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: add filtering to work center and process tables

Brad Barbin95d15589cbed
diff --git a/apps/erp/app/modules/resources/ui/Processes/ProcessesTable.tsx b/apps/erp/app/modules/resources/ui/Processes/ProcessesTable.tsx
index f50083f084..f900cba49a 100644
--- a/apps/erp/app/modules/resources/ui/Processes/ProcessesTable.tsx
+++ b/apps/erp/app/modules/resources/ui/Processes/ProcessesTable.tsx
@@ -24,12 +24,12 @@ import {
} from "react-icons/lu";
import { EmployeeAvatar, Hyperlink, New, Table } from "~/components";
import { Enumerable } from "~/components/Enumerable";
+import { useWorkCenters } from "~/components/Form/WorkCenter";
import { usePermissions, useUrlParams } from "~/hooks";
import { useCustomColumns } from "~/hooks/useCustomColumns";
import { type Process } from "~/modules/resources";
import { standardFactorType } from "~/modules/shared";
import { usePeople } from "~/stores";
-import type { ListItem } from "~/types";
import { path } from "~/utils/path";
type ProcessesTableProps = {
@@ -49,6 +49,7 @@ const ProcessesTable = memo(({ data, count }: ProcessesTableProps) => {
const permissions = usePermissions();
const [params] = useUrlParams();
const [people] = usePeople();
+ const { options: workCenters } = useWorkCenters({});
const customColumns = useCustomColumns<Process>("process");
const columns = useMemo<ColumnDef<Process>[]>(() => {
@@ -95,19 +96,31 @@ const ProcessesTable = memo(({ data, count }: ProcessesTableProps) => {
header: "Work Centers",
cell: ({ row }) => (
<span className="flex gap-2 items-center flex-wrap py-2">
- {((row.original.workCenters ?? []) as Array<ListItem>).map((wc) => (
- <Enumerable
- key={wc.name}
- onClick={() => navigate(path.to.workCenter(wc.id))}
- variant="secondary"
- className="cursor-pointer"
- value={wc.name}
- />
- ))}
+ {((row.original.workCenters ?? []) as Array<string>).map((wc) => {
+ const workCenter = workCenters.find((w) => w.value === wc);
+ return (
+ <Enumerable
+ key={workCenter?.label}
+ onClick={() =>
+ navigate(path.to.workCenter(workCenter?.value!))
+ }
+ className="cursor-pointer"
+ value={workCenter?.label ?? null}
+ />
+ );
+ })}
</span>
),
meta: {
icon: <LuBuilding2 />,
+ filter: {
+ type: "static",
+ options: workCenters.map((w) => ({
+ value: w.value,
+ label: <Enumerable value={w.label} />,
+ })),
+ isArray: true,
+ },
},
},
{
@@ -180,7 +193,7 @@ const ProcessesTable = memo(({ data, count }: ProcessesTableProps) => {
},
];
return [...defaultColumns, ...customColumns];
- }, [people, customColumns, navigate]);
+ }, [workCenters, people, customColumns, navigate]);
const renderContextMenu = useCallback(
(row: (typeof data)[number]) => {
diff --git a/apps/erp/app/modules/resources/ui/WorkCenters/WorkCentersTable.tsx b/apps/erp/app/modules/resources/ui/WorkCenters/WorkCentersTable.tsx
index f4b9fc855e..b6184877cd 100644
--- a/apps/erp/app/modules/resources/ui/WorkCenters/WorkCentersTable.tsx
+++ b/apps/erp/app/modules/resources/ui/WorkCenters/WorkCentersTable.tsx
@@ -36,6 +36,7 @@ import {
} from "react-icons/lu";
import { EmployeeAvatar, Hyperlink, New, Table } from "~/components";
import { Enumerable } from "~/components/Enumerable";
+import { useProcesses } from "~/components/Form/Process";
import { Confirm } from "~/components/Modals";
import {
useCurrencyFormatter,
@@ -76,6 +77,7 @@ const WorkCentersTable = memo(
useState<WorkCenter | null>(null);
const formatter = useCurrencyFormatter();
+ const processes = useProcesses();
const onActivate = (data: WorkCenter) => {
setSelectedWorkCenter(data);
@@ -127,20 +129,29 @@ const WorkCentersTable = memo(
header: "Processes",
cell: ({ row }) => (
<span className="flex gap-2 items-center flex-wrap py-2">
- {((row.original.processes ?? []) as Array<ListItem>).map(
- (process) => (
+ {((row.original.processes ?? []) as Array<string>).map((p) => {
+ const process = processes.find((proc) => proc.value === p);
+ return (
<Enumerable
- key={process.name}
- value={process.name}
- onClick={() => navigate(path.to.process(process.id))}
+ key={process?.label}
+ value={process?.label ?? null}
+ onClick={() => navigate(path.to.process(process?.value!))}
className="cursor-pointer"
/>
- )
- )}
+ );
+ })}
</span>
),
meta: {
icon: <LuCog />,
+ filter: {
+ type: "static",
+ options: processes.map((process) => ({
+ value: process.value,
+ label: <Enumerable value={process.label} />,
+ })),
+ isArray: true,
+ },
},
},
{
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index 7dfc561c17..2456ee4bf8 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -39541,14 +39541,14 @@ export type Database = {
},
{
foreignKeyName: "partner_id_fkey"
- columns: ["id"]
+ columns: ["supplierLocationId"]
isOneToOne: false
referencedRelation: "supplierLocation"
referencedColumns: ["id"]
},
{
foreignKeyName: "partner_id_fkey"
- columns: ["supplierLocationId"]
+ columns: ["id"]
isOneToOne: false
referencedRelation: "supplierLocation"
referencedColumns: ["id"]
@@ -39869,9 +39869,10 @@ export type Database = {
name: string | null
processType: Database["public"]["Enums"]["processType"] | null
suppliers: Json | null
+ tags: string[] | null
updatedAt: string | null
updatedBy: string | null
- workCenters: Json | null
+ workCenters: string[] | null
}
Relationships: [
{
@@ -43915,14 +43916,14 @@ export type Database = {
Relationships: [
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["paymentCountryCode"]
+ columns: ["customerCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
},
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["customerCountryCode"]
+ columns: ["paymentCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
@@ -46028,8 +46029,9 @@ export type Database = {
machineRate: number | null
name: string | null
overheadRate: number | null
- processes: Json | null
+ processes: string[] | null
requiredAbilityId: string | null
+ tags: string[] | null
updatedAt: string | null
updatedBy: string | null
}
diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.ts
index 7dfc561c17..2456ee4bf8 100644
--- a/packages/database/supabase/functions/lib/types.ts
+++ b/packages/database/supabase/functions/lib/types.ts
@@ -39541,14 +39541,14 @@ export type Database = {
},
{
foreignKeyName: "partner_id_fkey"
- columns: ["id"]
+ columns: ["supplierLocationId"]
isOneToOne: false
referencedRelation: "supplierLocation"
referencedColumns: ["id"]
},
{
foreignKeyName: "partner_id_fkey"
- columns: ["supplierLocationId"]
+ columns: ["id"]
isOneToOne: false
referencedRelation: "supplierLocation"
referencedColumns: ["id"]
@@ -39869,9 +39869,10 @@ export type Database = {
name: string | null
processType: Database["public"]["Enums"]["processType"] | null
suppliers: Json | null
+ tags: string[] | null
updatedAt: string | null
updatedBy: string | null
- workCenters: Json | null
+ workCenters: string[] | null
}
Relationships: [
{
@@ -43915,14 +43916,14 @@ export type Database = {
Relationships: [
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["paymentCountryCode"]
+ columns: ["customerCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
},
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["customerCountryCode"]
+ columns: ["paymentCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
@@ -46028,8 +46029,9 @@ export type Database = {
machineRate: number | null
name: string | null
overheadRate: number | null
- processes: Json | null
+ processes: string[] | null
requiredAbilityId: string | null
+ tags: string[] | null
updatedAt: string | null
updatedBy: string | null
}
diff --git a/packages/database/supabase/migrations/20250808230310_processes-and-workcenters-view.sql b/packages/database/supabase/migrations/20250808230310_processes-and-workcenters-view.sql
new file mode 100644
index 0000000000..077738b241
--- /dev/null
+++ b/packages/database/supabase/migrations/20250808230310_processes-and-workcenters-view.sql
@@ -0,0 +1,41 @@
+DROP VIEW IF EXISTS "workCenters";
+CREATE OR REPLACE VIEW "workCenters" WITH(SECURITY_INVOKER=true) AS
+ SELECT
+ wc.*,
+ l.name as "locationName",
+ wcp.processes
+ FROM "workCenter" wc
+ LEFT JOIN location l
+ ON wc."locationId" = l.id
+ LEFT JOIN (
+ SELECT
+ "workCenterId",
+ array_agg("processId"::text) as processes
+ FROM "workCenterProcess" wcp
+ INNER JOIN "process" p ON wcp."processId" = p.id
+ GROUP BY "workCenterId"
+ ) wcp ON wc.id = wcp."workCenterId";
+
+DROP VIEW IF EXISTS "processes";
+CREATE OR REPLACE VIEW "processes" WITH(SECURITY_INVOKER=true) AS
+ SELECT
+ p.*,
+ wcp."workCenters",
+ sp."suppliers"
+ FROM "process" p
+ LEFT JOIN (
+ SELECT
+ "processId",
+ array_agg("workCenterId"::text) as "workCenters"
+ FROM "workCenterProcess" wcp
+ INNER JOIN "workCenter" wc ON wcp."workCenterId" = wc.id
+ GROUP BY "processId"
+ ) wcp ON p.id = wcp."processId"
+ LEFT JOIN (
+ SELECT
+ "processId",
+ jsonb_agg(jsonb_build_object('id', sp."id", 'name', s.name)) as "suppliers"
+ FROM "supplierProcess" sp
+ INNER JOIN "supplier" s ON sp."supplierId" = s.id
+ GROUP BY "processId"
+ ) sp ON p.id = sp."processId";
\ No newline at end of file