Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

fix: don't include inactive by default in inventory table

Brad Barbin310fa5ebbf76
diff --git a/apps/carbon/app/modules/inventory/inventory.service.ts b/apps/carbon/app/modules/inventory/inventory.service.ts
index ca47d40b43..32850ec6cf 100644
--- a/apps/carbon/app/modules/inventory/inventory.service.ts
+++ b/apps/carbon/app/modules/inventory/inventory.service.ts
@@ -141,11 +141,62 @@ export async function getInventoryItems(
);
}
+ const includeInactive = args?.filters?.some(
+ (filter) =>
+ (filter.column === "active" && filter.value === "false") ||
+ (filter.column === "active" && filter.operator === "in")
+ );
+ if (!includeInactive) {
+ query = query.eq("active", true);
+ }
+
query = setGenericQueryFilters(query, args);
return query;
}
+export async function getInventoryItemsCount(
+ client: SupabaseClient<Database>,
+ companyId: string,
+ args: GenericQueryFilters & {
+ search: string | null;
+ }
+) {
+ let query = client
+ .from("item")
+ .select("id, readableId", { count: "exact" })
+ .eq("companyId", companyId)
+ .eq("itemTrackingType", "Inventory");
+
+ if (args?.search) {
+ query = query.or(
+ `name.ilike.%${args.search}%,readableId.ilike.%${args.search}%`
+ );
+ }
+
+ const includeInactive = args?.filters?.some(
+ (filter) =>
+ (filter.column === "active" && filter.value === "false") ||
+ (filter.column === "active" && filter.operator === "in")
+ );
+ if (!includeInactive) {
+ query = query.eq("active", true);
+ }
+
+ const filteredArgs = {
+ ...args,
+ filters: args.filters?.filter(
+ (filter) =>
+ filter.column !== "materialFormId" &&
+ filter.column !== "materialSubstanceId"
+ ),
+ };
+
+ query = setGenericQueryFilters(query, filteredArgs);
+
+ return query;
+}
+
export async function getReceipts(
client: SupabaseClient<Database>,
companyId: string,
diff --git a/apps/carbon/app/modules/inventory/ui/Inventory/InventoryItemHeader.tsx b/apps/carbon/app/modules/inventory/ui/Inventory/InventoryItemHeader.tsx
index edb0a81b19..88a4bf6370 100644
--- a/apps/carbon/app/modules/inventory/ui/Inventory/InventoryItemHeader.tsx
+++ b/apps/carbon/app/modules/inventory/ui/Inventory/InventoryItemHeader.tsx
@@ -1,17 +1,23 @@
import { Button, VStack } from "@carbon/react";
-import { useNavigate, useParams } from "@remix-run/react";
-import { LuX } from "react-icons/lu";
+import { Link, useNavigate, useParams } from "@remix-run/react";
+import { LuExternalLink, LuX } from "react-icons/lu";
import { DetailsTopbar } from "~/components/Layout";
import { useUrlParams } from "~/hooks";
+import { getLinkToItemDetails } from "~/modules/items/ui/Item/ItemForm";
+import type { MethodItemType } from "~/modules/shared";
import { path } from "~/utils/path";
import { useInventoryNavigation } from "./useInventoryNavigation";
type InventoryItemHeaderProps = {
itemReadableId: string;
+ itemType: MethodItemType;
};
-const InventoryItemHeader = ({ itemReadableId }: InventoryItemHeaderProps) => {
+const InventoryItemHeader = ({
+ itemReadableId,
+ itemType,
+}: InventoryItemHeaderProps) => {
const links = useInventoryNavigation();
const { itemId } = useParams();
if (!itemId) throw new Error("itemId not found");
@@ -32,7 +38,12 @@ const InventoryItemHeader = ({ itemReadableId }: InventoryItemHeaderProps) => {
>
<LuX className="w-4 h-4" />
</Button>
- <span className="font-semibold text-center">{itemReadableId}</span>
+ <span className="flex items-center font-semibold text-center">
+ {itemReadableId}{" "}
+ <Link to={getLinkToItemDetails(itemType, itemId)} className="ml-2">
+ <LuExternalLink />
+ </Link>
+ </span>
<DetailsTopbar links={links} preserveParams />
</div>
</VStack>
diff --git a/apps/carbon/app/modules/inventory/ui/Inventory/InventoryTable.tsx b/apps/carbon/app/modules/inventory/ui/Inventory/InventoryTable.tsx
index ceec9b71fa..5eed16df3b 100644
--- a/apps/carbon/app/modules/inventory/ui/Inventory/InventoryTable.tsx
+++ b/apps/carbon/app/modules/inventory/ui/Inventory/InventoryTable.tsx
@@ -1,4 +1,4 @@
-import { Combobox, HStack, Heading, VStack } from "@carbon/react";
+import { Checkbox, Combobox, HStack, Heading, VStack } from "@carbon/react";
import type { ColumnDef } from "@tanstack/react-table";
import { memo, useMemo } from "react";
import {
@@ -173,6 +173,21 @@ const InventoryTable = memo(
},
},
},
+ {
+ accessorKey: "active",
+ header: "Active",
+ cell: (item) => <Checkbox isChecked={item.getValue<boolean>()} />,
+ meta: {
+ filter: {
+ type: "static",
+ options: [
+ { value: "true", label: "Active" },
+ { value: "false", label: "Inactive" },
+ ],
+ },
+ pluralHeader: "Active Statuses",
+ },
+ },
];
}, [forms, params, substances, unitOfMeasures]);
@@ -181,6 +196,7 @@ const InventoryTable = memo(
}, []);
const defaultColumnVisibility = {
+ active: false,
type: false,
};
diff --git a/apps/carbon/app/modules/items/ui/Item/ItemForm.tsx b/apps/carbon/app/modules/items/ui/Item/ItemForm.tsx
index 4b074d31dd..eed9100ec5 100644
--- a/apps/carbon/app/modules/items/ui/Item/ItemForm.tsx
+++ b/apps/carbon/app/modules/items/ui/Item/ItemForm.tsx
@@ -84,7 +84,7 @@ const ItemForm = ({ initialValues, type }: ItemFormProps) => {
</CardHeader>
<CardAction>
<Button isIcon asChild variant="ghost" size="lg">
- <Link to={getLink(type, initialValues.id)}>
+ <Link to={getLinkToItemDetails(type, initialValues.id)}>
<LuExternalLink />
</Link>
</Button>
@@ -146,7 +146,7 @@ const ItemForm = ({ initialValues, type }: ItemFormProps) => {
export default ItemForm;
-function getLink(type: MethodItemType, id: string) {
+export function getLinkToItemDetails(type: MethodItemType, id: string) {
switch (type) {
case "Part":
return path.to.partDetails(id);
diff --git a/apps/carbon/app/routes/x+/inventory+/quantities+/$itemId.tsx b/apps/carbon/app/routes/x+/inventory+/quantities+/$itemId.tsx
index e3def6a2ad..4d86d9a76e 100644
--- a/apps/carbon/app/routes/x+/inventory+/quantities+/$itemId.tsx
+++ b/apps/carbon/app/routes/x+/inventory+/quantities+/$itemId.tsx
@@ -120,7 +120,10 @@ export default function ItemInventoryRoute() {
className="bg-muted"
>
<ScrollArea className="h-[calc(100vh-49px)]">
- <InventoryItemHeader itemReadableId={item.readableId} />
+ <InventoryItemHeader
+ itemReadableId={item.readableId}
+ itemType={item.type}
+ />
<VStack className="p-2">
<Outlet />
</VStack>
diff --git a/apps/carbon/app/routes/x+/inventory+/quantities.tsx b/apps/carbon/app/routes/x+/inventory+/quantities.tsx
index 9ae7bb524e..055d1913c1 100644
--- a/apps/carbon/app/routes/x+/inventory+/quantities.tsx
+++ b/apps/carbon/app/routes/x+/inventory+/quantities.tsx
@@ -9,7 +9,7 @@ import type { LoaderFunctionArgs } from "@vercel/remix";
import { json, redirect } from "@vercel/remix";
import { useRouteData } from "~/hooks";
import type { InventoryItem } from "~/modules/inventory";
-import { getInventoryItems } from "~/modules/inventory";
+import { getInventoryItems, getInventoryItemsCount } from "~/modules/inventory";
import InventoryTable from "~/modules/inventory/ui/Inventory/InventoryTable";
import {
getMaterialFormsList,
@@ -76,10 +76,13 @@ export async function loader({ request }: LoaderFunctionArgs) {
sorts,
filters,
}),
- client
- .from("item")
- .select("id", { count: "exact" })
- .eq("itemTrackingType", "Inventory"),
+ getInventoryItemsCount(client, companyId, {
+ search,
+ limit,
+ offset,
+ sorts,
+ filters,
+ }),
getMaterialFormsList(client, companyId),
getMaterialSubstancesList(client, companyId),
]);