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.

feat(quality): expand inspection plan rows on click, add item group and tags columns (#2082)

Brad Barbinc22f6b2ac5a9
diff --git a/.claude/rules/inspection-system.md b/.claude/rules/inspection-system.md
index ebc8b79dd3..b0776b8381 100644
--- a/.claude/rules/inspection-system.md
+++ b/.claude/rules/inspection-system.md
@@ -196,10 +196,14 @@ ON DELETE SET NULL) and no PDF; each feature names its PMI item
document's sampling default.
- The Inspection Plans list (`/x/quality/inspection-plans`) is one row per part,
read from the `inspectionPlanParts` view (`getInspectionPlanParts`,
- `20261028161842_inspection-plan-parts-view.sql`): the part, its plan count and
- a `plans` jsonb rollup the expanded row lists, as the Change Notices list
- lists a notice's affected items. A search expands every row and marks the
- matches (`expandRowsFor` on the Table, `Highlight` / `searchMatches`).
+ `20261028161842_inspection-plan-parts-view.sql`, recreated by
+ `20261028222414_inspection-plan-parts-group-tags.sql`): the part, its plan
+ count, its item group (`itemCost.itemPostingGroupId`) and tags (`part.tags`),
+ and a `plans` jsonb rollup the expanded row lists, as the Change Notices list
+ lists a notice's affected items. Clicking a row expands it; the part is not a
+ link. Item Group and Tags are filterable columns, hidden by default. A search
+ expands every row and marks the matches (`expandRowsFor` on the Table,
+ `Highlight` / `searchMatches`).
- PMI ids are per-kind counters in file order, stable for one file. An extractor
change that reorders items would point an old plan's features at other items.
diff --git a/apps/erp/app/modules/quality/ui/InspectionDocument/InspectionDocumentTable.tsx b/apps/erp/app/modules/quality/ui/InspectionDocument/InspectionDocumentTable.tsx
index cfa555904f..f732923615 100644
--- a/apps/erp/app/modules/quality/ui/InspectionDocument/InspectionDocumentTable.tsx
+++ b/apps/erp/app/modules/quality/ui/InspectionDocument/InspectionDocumentTable.tsx
@@ -2,6 +2,7 @@
// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,
// including ports, remain AGPLv3; serving them over a network requires releasing their source.
+import { Badge, HStack } from "@carbon/react";
import { useLingui } from "@lingui/react/macro";
import type { ColumnDef } from "@tanstack/react-table";
import { memo, useCallback, useMemo } from "react";
@@ -10,6 +11,8 @@ import {
LuBox,
LuCalendar,
LuFileText,
+ LuGroup,
+ LuTag,
LuTarget
} from "react-icons/lu";
import {
@@ -22,6 +25,8 @@ import {
searchMatches,
Table
} from "~/components";
+import { Enumerable } from "~/components/Enumerable";
+import { useItemPostingGroups } from "~/components/Form/ItemPostingGroup";
import type { InfiniteOptions } from "~/components/Table";
import { usePermissions, useUrlParams } from "~/hooks";
import { useItems } from "~/stores/items";
@@ -32,20 +37,24 @@ type InspectionDocumentTableProps = {
data: InspectionPlanPart[];
count: number;
infinite: InfiniteOptions;
+ tags: { name: string }[];
};
const defaultColumnVisibility = {
- createdAt: false
+ createdAt: false,
+ itemPostingGroupId: false,
+ tags: false
};
/** One row per part; its inspection plans are the expanded row, open while a
* search is, with the matches marked. */
const InspectionDocumentTable = memo(
- ({ data, count, infinite }: InspectionDocumentTableProps) => {
+ ({ data, count, infinite, tags }: InspectionDocumentTableProps) => {
const [params] = useUrlParams();
const { t } = useLingui();
const permissions = usePermissions();
const [items] = useItems();
+ const itemPostingGroups = useItemPostingGroups();
const search = params.get("search");
const columns = useMemo<ColumnDef<InspectionPlanPart>[]>(
@@ -53,23 +62,22 @@ const InspectionDocumentTable = memo(
{
accessorKey: "partReadableId",
header: t`Part`,
+ // Clicking the row expands its plans.
cell: ({ row }) => (
- <Hyperlink to={path.to.part(row.original.id!)}>
- <div className="flex flex-col gap-0">
- <span className="text-sm font-medium">
- <Highlight
- text={row.original.partReadableId}
- ranges={searchMatches(row.original.partReadableId, search)}
- />
- </span>
- <span className="text-xs text-muted-foreground">
- <Highlight
- text={row.original.partName}
- ranges={searchMatches(row.original.partName, search)}
- />
- </span>
- </div>
- </Hyperlink>
+ <div className="flex flex-col gap-0">
+ <span className="text-sm font-medium">
+ <Highlight
+ text={row.original.partReadableId}
+ ranges={searchMatches(row.original.partReadableId, search)}
+ />
+ </span>
+ <span className="text-xs text-muted-foreground">
+ <Highlight
+ text={row.original.partName}
+ ranges={searchMatches(row.original.partName, search)}
+ />
+ </span>
+ </div>
),
meta: {
mobile: "P1",
@@ -91,6 +99,57 @@ const InspectionDocumentTable = memo(
),
meta: { mobile: "P2", icon: <LuTarget /> }
},
+ {
+ accessorKey: "itemPostingGroupId",
+ header: t`Item Group`,
+ cell: (item) => {
+ const itemPostingGroupId = item.getValue<string>();
+ const itemPostingGroup = itemPostingGroups.find(
+ (group) => group.value === itemPostingGroupId
+ );
+ return <Enumerable value={itemPostingGroup?.label ?? null} />;
+ },
+ meta: {
+ filter: {
+ type: "static" as const,
+ options: itemPostingGroups.map((group) => ({
+ value: group.value,
+ label: <Enumerable value={group.label} />
+ }))
+ },
+ icon: <LuGroup />,
+ exportValue: (row) =>
+ itemPostingGroups.find(
+ (group) => group.value === row.itemPostingGroupId
+ )?.label ?? null
+ }
+ },
+ {
+ accessorKey: "tags",
+ header: t`Tags`,
+ cell: ({ row }) => (
+ <HStack spacing={0} className="gap-1">
+ {row.original.tags?.map((tag) => (
+ <Badge key={tag} variant="secondary">
+ {tag}
+ </Badge>
+ ))}
+ </HStack>
+ ),
+ meta: {
+ filter: {
+ type: "static" as const,
+ options: tags?.map((tag) => ({
+ value: tag.name,
+ label: <Badge variant="secondary">{tag.name}</Badge>
+ })),
+ isArray: true
+ },
+ icon: <LuTag />,
+ exportValue: (row) =>
+ row.tags?.length ? row.tags.join(", ") : null
+ }
+ },
{
accessorKey: "updatedAt",
header: t`Updated At`,
@@ -114,7 +173,7 @@ const InspectionDocumentTable = memo(
value: (row) => row.plans.map((plan) => plan.name).join(", ")
})
],
- [items, search, t]
+ [items, itemPostingGroups, search, tags, t]
);
const renderExpandedRow = useCallback(
diff --git a/apps/erp/app/routes/x+/quality+/inspection-plans.tsx b/apps/erp/app/routes/x+/quality+/inspection-plans.tsx
index 6e6a3d813d..b8f3e7c00f 100644
--- a/apps/erp/app/routes/x+/quality+/inspection-plans.tsx
+++ b/apps/erp/app/routes/x+/quality+/inspection-plans.tsx
@@ -7,6 +7,7 @@ import { msg } from "@lingui/core/macro";
import type { LoaderFunctionArgs } from "react-router";
import { useLoaderData } from "react-router";
import { InspectionDocumentTable } from "~/modules/quality/ui/InspectionDocument";
+import { getTagsList } from "~/modules/shared/shared.service";
import type { Handle } from "~/utils/handle";
import { loadListPage } from "~/utils/list-registry/load.server";
import { inspectionPlansList } from "~/utils/list-registry/quality.server";
@@ -18,15 +19,26 @@ export const handle: Handle = {
};
export async function loader({ request }: LoaderFunctionArgs) {
- return loadListPage(request, inspectionPlansList, { dataKey: "parts" });
+ return loadListPage(request, inspectionPlansList, {
+ dataKey: "parts",
+ // Inspection plans are only made for parts.
+ firstPage: async ({ client, companyId }) => ({
+ tags: (await getTagsList(client, companyId, "part")).data ?? []
+ })
+ });
}
export default function InspectionDocumentsRoute() {
- const { parts, count, infinite } = useLoaderData<typeof loader>();
+ const { parts, count, infinite, tags } = useLoaderData<typeof loader>();
return (
<VStack spacing={0} className="h-full">
- <InspectionDocumentTable data={parts} count={count} infinite={infinite} />
+ <InspectionDocumentTable
+ data={parts}
+ count={count}
+ infinite={infinite}
+ tags={tags}
+ />
<RecordOutlet />
</VStack>
);
diff --git a/packages/database/src/swagger-docs-schema.ts b/packages/database/src/swagger-docs-schema.ts
index 5216777f95..9ccfd94839 100644
--- a/packages/database/src/swagger-docs-schema.ts
+++ b/packages/database/src/swagger-docs-schema.ts
@@ -57510,6 +57510,12 @@ export default {
{
$ref: "#/parameters/rowFilter.inspectionPlanParts.updatedAt"
},
+ {
+ $ref: "#/parameters/rowFilter.inspectionPlanParts.itemPostingGroupId"
+ },
+ {
+ $ref: "#/parameters/rowFilter.inspectionPlanParts.tags"
+ },
{
$ref: "#/parameters/select"
},
@@ -146678,6 +146684,19 @@ export default {
updatedAt: {
format: "timestamp with time zone",
type: "string"
+ },
+ itemPostingGroupId: {
+ description:
+ "Note:\nThis is a Foreign Key to `itemPostingGroup.id`.<fk table='itemPostingGroup' column='id'/>",
+ format: "text",
+ type: "string"
+ },
+ tags: {
+ format: "text[]",
+ items: {
+ type: "string"
+ },
+ type: "array"
}
},
type: "object"
@@ -200264,6 +200283,18 @@ export default {
in: "query",
type: "string"
},
+ "rowFilter.inspectionPlanParts.itemPostingGroupId": {
+ name: "itemPostingGroupId",
+ required: false,
+ in: "query",
+ type: "string"
+ },
+ "rowFilter.inspectionPlanParts.tags": {
+ name: "tags",
+ required: false,
+ in: "query",
+ type: "string"
+ },
"body.purchaseReturnOrderLineTrackedEntity": {
name: "purchaseReturnOrderLineTrackedEntity",
description: "purchaseReturnOrderLineTrackedEntity",
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index 99f71c4f81..dd75fed51d 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -77601,11 +77601,13 @@ export type Database = {
companyId: string | null
createdAt: string | null
id: string | null
+ itemPostingGroupId: string | null
partName: string | null
partReadableId: string | null
planCount: number | null
planNames: string | null
plans: Json | null
+ tags: string[] | null
updatedAt: string | null
}
Relationships: [
@@ -77678,6 +77680,13 @@ export type Database = {
isOneToOne: false
referencedRelation: "tools"
referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "itemCost_itemPostingGroupId_fkey"
+ columns: ["itemPostingGroupId"]
+ isOneToOne: false
+ referencedRelation: "itemPostingGroup"
+ referencedColumns: ["id"]
}
]
}
diff --git a/packages/database/supabase/migrations/20261028222414_inspection-plan-parts-group-tags.sql b/packages/database/supabase/migrations/20261028222414_inspection-plan-parts-group-tags.sql
new file mode 100644
index 0000000000..61a5bbfb30
--- /dev/null
+++ b/packages/database/supabase/migrations/20261028222414_inspection-plan-parts-group-tags.sql
@@ -0,0 +1,37 @@
+-- The Inspection Plans list filters by the part's item group and tags.
+
+DROP VIEW IF EXISTS "inspectionPlanParts";
+CREATE VIEW "inspectionPlanParts" WITH (SECURITY_INVOKER=true) AS
+ SELECT
+ d."partId" AS "id",
+ d."companyId",
+ i."readableIdWithRevision" AS "partReadableId",
+ i."name" AS "partName",
+ COUNT(*)::INTEGER AS "planCount",
+ -- The search reads the plans' names too.
+ string_agg(COALESCE(d."drawingNumber", d."fileName"), ' ') AS "planNames",
+ jsonb_agg(
+ jsonb_build_object(
+ 'id', d."id",
+ 'name', COALESCE(d."drawingNumber", d."fileName"),
+ 'modelUploadId', d."modelUploadId",
+ 'createdBy', d."createdBy",
+ 'createdAt', d."createdAt"
+ )
+ ORDER BY COALESCE(d."drawingNumber", d."fileName"), d."id"
+ ) AS "plans",
+ MIN(d."createdAt") AS "createdAt",
+ MAX(COALESCE(d."updatedAt", d."createdAt")) AS "updatedAt",
+ ic."itemPostingGroupId",
+ p."tags"
+ FROM "inspectionDocument" d
+ JOIN "item" i ON i."id" = d."partId"
+ LEFT JOIN "itemCost" ic ON ic."itemId" = i."id"
+ LEFT JOIN "part" p ON p."id" = i."readableId" AND p."companyId" = i."companyId"
+ GROUP BY
+ d."partId",
+ d."companyId",
+ i."readableIdWithRevision",
+ i."name",
+ ic."itemPostingGroupId",
+ p."tags";