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.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
feat: custom fields for work cell and work cell type forms
Brad Barbin5817966bf918
diff --git a/apps/carbon/app/modules/resources/resources.service.ts b/apps/carbon/app/modules/resources/resources.service.tsindex 51a7faab13..08e85fee5d 100644--- a/apps/carbon/app/modules/resources/resources.service.ts+++ b/apps/carbon/app/modules/resources/resources.service.ts@@ -17,6 +17,7 @@ import type {partnerValidator,shiftValidator,workCellTypeValidator,+ workCellValidator,} from "./resources.models";export async function deleteAbility(@@ -1191,31 +1192,23 @@ export async function upsertShift(export async function upsertWorkCell(client: SupabaseClient<Database>,workCell:- | {- name: string;- description: string;- workCellTypeId: string;- locationId: string;- departmentId: string;- activeDate?: string;+ | (Omit<z.infer<typeof workCellValidator>, "id"> & {createdBy: string;- }- | {+ customFields?: Json;+ })+ | (Omit<z.infer<typeof workCellValidator>, "id"> & {id: string;- name: string;- description: string;- workCellTypeId: string;- locationId: string;- departmentId: string;- activeDate?: string;updatedBy: string;- }+ customFields?: Json;+ })) {- if ("id" in workCell) {- const { id, ...update } = workCell;- return client.from("workCell").update(sanitize(update)).eq("id", id);+ if ("createdBy" in workCell) {+ return client.from("workCell").insert([workCell]).select("*").single();}- return client.from("workCell").insert([workCell]).select("*").single();+ return client+ .from("workCell")+ .update(sanitize(workCell))+ .eq("id", workCell.id);}export async function upsertWorkCellType(@@ -1223,19 +1216,23 @@ export async function upsertWorkCellType(workCellType:| (Omit<z.infer<typeof workCellTypeValidator>, "id"> & {createdBy: string;+ customFields?: Json;})| (Omit<z.infer<typeof workCellTypeValidator>, "id"> & {id: string;updatedBy: string;+ customFields?: Json;})) {- if ("id" in workCellType) {- const { id, ...update } = workCellType;- return client.from("workCellType").update(sanitize(update)).eq("id", id);+ if ("createdBy" in workCellType) {+ return client+ .from("workCellType")+ .insert([workCellType])+ .select("id")+ .single();}return client.from("workCellType")- .insert([workCellType])- .select("id")- .single();+ .update(sanitize(workCellType))+ .eq("id", workCellType.id);}diff --git a/apps/carbon/app/modules/resources/ui/Equipment/EquipmentTypesTable.tsx b/apps/carbon/app/modules/resources/ui/Equipment/EquipmentTypesTable.tsxindex 448fd28dc0..d34eb9f1b5 100644--- a/apps/carbon/app/modules/resources/ui/Equipment/EquipmentTypesTable.tsx+++ b/apps/carbon/app/modules/resources/ui/Equipment/EquipmentTypesTable.tsx@@ -1,7 +1,7 @@import {Button,+ Enumerable,HStack,- Hyperlink,MenuIcon,MenuItem,useDisclosure,@@ -50,9 +50,11 @@ const EquipmentTypesTable = memo(header: "Equipment Type",cell: ({ row }) => (<HStack>- <Hyperlink onClick={() => navigate(row.original.id)}>- {row.original.name}- </Hyperlink>+ <Enumerable+ value={row.original.name}+ onClick={() => navigate(row.original.id)}+ className="cursor-pointer"+ />{row.original.requiredAbility && (<BsFillCheckCircleFillclassName="text-green-500"diff --git a/apps/carbon/app/modules/resources/ui/WorkCells/WorkCellTypesTable.tsx b/apps/carbon/app/modules/resources/ui/WorkCells/WorkCellTypesTable.tsxindex 54bbec56b0..5894133568 100644--- a/apps/carbon/app/modules/resources/ui/WorkCells/WorkCellTypesTable.tsx+++ b/apps/carbon/app/modules/resources/ui/WorkCells/WorkCellTypesTable.tsx@@ -1,7 +1,7 @@import {Button,+ Enumerable,HStack,- Hyperlink,MenuIcon,MenuItem,useDisclosure,@@ -47,9 +47,12 @@ const WorkCellTypesTable = memo(({ data, count }: WorkCellTypesTableProps) => {header: "Work Cell Type",cell: ({ row }) => (<HStack>- <Hyperlink onClick={() => navigate(row.original.id)}>- {row.original.name}- </Hyperlink>+ <Enumerable+ value={row.original.name}+ onClick={() => navigate(row.original.id)}+ className="cursor-pointer"+ />+{row.original.requiredAbility && (<BsFillCheckCircleFillclassName="text-green-500"diff --git a/apps/carbon/app/routes/x+/person+/$personId.job.tsx b/apps/carbon/app/routes/x+/person+/$personId.job.tsxindex 483e7f9d2f..0ba911a141 100644--- a/apps/carbon/app/routes/x+/person+/$personId.job.tsx+++ b/apps/carbon/app/routes/x+/person+/$personId.job.tsx@@ -83,6 +83,5 @@ export default function PersonJobRoute() {...getCustomFields(job.customFields),};- console.log({ initialValues });return <PersonJob key={personId} initialValues={initialValues} />;}diff --git a/apps/carbon/app/routes/x+/resources+/work-cells.$typeId.tsx b/apps/carbon/app/routes/x+/resources+/work-cells.$typeId.tsxindex e9e4edd742..93e64ace10 100644--- a/apps/carbon/app/routes/x+/resources+/work-cells.$typeId.tsx+++ b/apps/carbon/app/routes/x+/resources+/work-cells.$typeId.tsx@@ -10,6 +10,7 @@ import {} from "~/modules/resources";import { requirePermissions } from "~/services/auth";import { flash } from "~/services/session.server";+import { getCustomFields, setCustomFields } from "~/utils/form";import { assertIsPost, notFound } from "~/utils/http";import { path } from "~/utils/path";import { error, success } from "~/utils/result";@@ -43,9 +44,8 @@ export async function action({ request }: ActionFunctionArgs) {update: "resources",});- const validation = await validator(workCellTypeValidator).validate(- await request.formData()- );+ const formData = await request.formData();+ const validation = await validator(workCellTypeValidator).validate(formData);if (validation.error) {return validationError(validation.error);@@ -58,6 +58,7 @@ export async function action({ request }: ActionFunctionArgs) {id,...data,updatedBy: userId,+ customFields: setCustomFields(formData),});if (updateCategory.error) {return redirect(@@ -89,6 +90,7 @@ export default function EditAttributeCategoryRoute() {laborRate: workCellType?.laborRate ?? 0,overheadRate: workCellType?.overheadRate ?? 0,defaultStandardFactor: workCellType?.defaultStandardFactor ?? "Total Hours",+ ...getCustomFields(workCellType?.customFields),};return (diff --git a/apps/carbon/app/routes/x+/resources+/work-cells.cell.$workCellId.tsx b/apps/carbon/app/routes/x+/resources+/work-cells.cell.$workCellId.tsxindex c6129122af..b46cf8cc46 100644--- a/apps/carbon/app/routes/x+/resources+/work-cells.cell.$workCellId.tsx+++ b/apps/carbon/app/routes/x+/resources+/work-cells.cell.$workCellId.tsx@@ -4,6 +4,7 @@ import { redirect } from "@remix-run/node";import { upsertWorkCell, workCellValidator } from "~/modules/resources";import { requirePermissions } from "~/services/auth";import { flash } from "~/services/session.server";+import { setCustomFields } from "~/utils/form";import { assertIsPost } from "~/utils/http";import { path } from "~/utils/path";import { error, success } from "~/utils/result";@@ -14,9 +15,8 @@ export async function action({ request, params }: ActionFunctionArgs) {update: "resources",});- const validation = await validator(workCellValidator).validate(- await request.formData()- );+ const formData = await request.formData();+ const validation = await validator(workCellValidator).validate(formData);if (validation.error) {return validationError(validation.error);@@ -33,10 +33,13 @@ export async function action({ request, params }: ActionFunctionArgs) {);}+ const { id, ...data } = validation.data;+const updateWorkCell = await upsertWorkCell(client, {id: workCellId,- ...validation.data,+ ...data,updatedBy: userId,+ customFields: setCustomFields(formData),});if (updateWorkCell.error)redirect(diff --git a/apps/carbon/app/routes/x+/resources+/work-cells.cell.new.tsx b/apps/carbon/app/routes/x+/resources+/work-cells.cell.new.tsxindex a65b1cfdf4..380d43649d 100644--- a/apps/carbon/app/routes/x+/resources+/work-cells.cell.new.tsx+++ b/apps/carbon/app/routes/x+/resources+/work-cells.cell.new.tsx@@ -4,6 +4,7 @@ import { json, redirect } from "@remix-run/node";import { upsertWorkCell, workCellValidator } from "~/modules/resources";import { requirePermissions } from "~/services/auth";import { flash } from "~/services/session.server";+import { setCustomFields } from "~/utils/form";import { assertIsPost } from "~/utils/http";import { path } from "~/utils/path";import { error } from "~/utils/result";@@ -14,31 +15,19 @@ export async function action({ request }: ActionFunctionArgs) {create: "resources",});- const validation = await validator(workCellValidator).validate(- await request.formData()- );+ const formData = await request.formData();+ const validation = await validator(workCellValidator).validate(formData);if (validation.error) {return validationError(validation.error);}- const {- name,- description,- workCellTypeId,- locationId,- departmentId,- activeDate,- } = validation.data;+ const { id, ...data } = validation.data;const insertWorkCell = await upsertWorkCell(client, {- name,- description,- workCellTypeId,- locationId,- departmentId,- activeDate,+ ...data,createdBy: userId,+ customFields: setCustomFields(formData),});if (insertWorkCell.error) {return json(diff --git a/apps/carbon/app/routes/x+/resources+/work-cells.list.$typeId.$workCellId.tsx b/apps/carbon/app/routes/x+/resources+/work-cells.list.$typeId.$workCellId.tsxindex 267e5753f7..b863280af0 100644--- a/apps/carbon/app/routes/x+/resources+/work-cells.list.$typeId.$workCellId.tsx+++ b/apps/carbon/app/routes/x+/resources+/work-cells.list.$typeId.$workCellId.tsx@@ -6,6 +6,7 @@ import type { WorkCellType } from "~/modules/resources";import { WorkCellForm, getWorkCell } from "~/modules/resources";import { requirePermissions } from "~/services/auth";import { flash } from "~/services/session.server";+import { getCustomFields } from "~/utils/form";import { notFound } from "~/utils/http";import { path } from "~/utils/path";import { error } from "~/utils/result";@@ -65,6 +66,7 @@ export default function EditWorkCellRoute() {locationId: workCell?.location?.id ?? "",departmentId: workCell?.department?.id ?? "",activeDate: workCell?.activeDate ?? "",+ ...getCustomFields(workCell?.customFields),}}workCellTypes={workCellRouteData?.workCellTypes ?? []}onClose={onClose}diff --git a/apps/carbon/app/routes/x+/resources+/work-cells.new.tsx b/apps/carbon/app/routes/x+/resources+/work-cells.new.tsxindex 25e625816d..68e3d5c768 100644--- a/apps/carbon/app/routes/x+/resources+/work-cells.new.tsx+++ b/apps/carbon/app/routes/x+/resources+/work-cells.new.tsx@@ -9,6 +9,7 @@ import {} from "~/modules/resources";import { requirePermissions } from "~/services/auth";import { flash } from "~/services/session.server";+import { setCustomFields } from "~/utils/form";import { assertIsPost } from "~/utils/http";import { path } from "~/utils/path";import { error } from "~/utils/result";@@ -33,6 +34,7 @@ export async function action({ request }: ActionFunctionArgs) {const createWorkCellType = await upsertWorkCellType(client, {...data,createdBy: userId,+ customFields: setCustomFields(formData),});if (createWorkCellType.error) {return modal