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: lock/hide forms when version is not draft
Brad Barbindf2dd0ec56a5
diff --git a/apps/erp/app/integrations/onshape/lib/OnshapeSync.tsx b/apps/erp/app/integrations/onshape/lib/OnshapeSync.tsxindex 15ccd1dbcc..f0ba8d0666 100644--- a/apps/erp/app/integrations/onshape/lib/OnshapeSync.tsx+++ b/apps/erp/app/integrations/onshape/lib/OnshapeSync.tsx@@ -53,9 +53,11 @@ interface TreeData {export const OnshapeSync = ({itemId,makeMethodId,+ isDisabled,}: {itemId: string;makeMethodId: string;+ isDisabled: boolean;}) => {const [documentId, setDocumentId] = useState<string | null>(null);const [versionId, setVersionId] = useState<string | null>(null);@@ -91,7 +93,9 @@ export const OnshapeSync = ({>({});useMount(() => {- documentsFetcher.load(path.to.api.onShapeDocuments);+ if (!isDisabled) {+ documentsFetcher.load(path.to.api.onShapeDocuments);+ }});useEffect(() => {@@ -118,7 +122,7 @@ export const OnshapeSync = ({>({});useEffect(() => {- if (documentId) {+ if (documentId && !isDisabled) {versionsFetcher.load(path.to.api.onShapeVersions(documentId));}// eslint-disable-next-line react-hooks/exhaustive-deps@@ -142,7 +146,7 @@ export const OnshapeSync = ({>({});useEffect(() => {- if (documentId && versionId) {+ if (documentId && versionId && !isDisabled) {elementsFetcher.load(path.to.api.onShapeElements(documentId, versionId));}// eslint-disable-next-line react-hooks/exhaustive-deps@@ -251,6 +255,7 @@ export const OnshapeSync = ({<ComboboxisLoading={documentsFetcher.state === "loading"}options={documentOptions}+ disabled={isDisabled}onChange={(value) => {setVersionId(null);setElementId(null);@@ -268,6 +273,7 @@ export const OnshapeSync = ({<div className="w-[180px]"><ComboboxisLoading={versionsFetcher.state === "loading"}+ disabled={isDisabled}options={versionOptions}onChange={(value) => {setVersionId(value);@@ -286,6 +292,7 @@ export const OnshapeSync = ({<ComboboxisLoading={elementsFetcher.state === "loading"}options={elementOptions}+ disabled={isDisabled}onChange={(value) => {setElementId(value);}}@@ -343,7 +350,9 @@ export const OnshapeSync = ({<Buttonvariant={bomRows.length > 0 ? "secondary" : "primary"}isLoading={bomFetcher.state !== "idle"}- isDisabled={!isReadyForSync || bomFetcher.state !== "idle"}+ isDisabled={+ isDisabled || !isReadyForSync || bomFetcher.state !== "idle"+ }size="sm"onClick={loadBom}>@@ -362,7 +371,7 @@ export const OnshapeSync = ({size="sm"onClick={saveBom}isLoading={upsertBomFetcher.state !== "idle"}- isDisabled={upsertBomFetcher.state !== "idle"}+ isDisabled={isDisabled || upsertBomFetcher.state !== "idle"}>Save</Button>diff --git a/apps/erp/app/modules/items/ui/Item/BillOfProcess.tsx b/apps/erp/app/modules/items/ui/Item/BillOfProcess.tsxindex 3f8e97c818..7edbd019df 100644--- a/apps/erp/app/modules/items/ui/Item/BillOfProcess.tsx+++ b/apps/erp/app/modules/items/ui/Item/BillOfProcess.tsx@@ -60,7 +60,12 @@ import {LuX,} from "react-icons/lu";import { z } from "zod";-import { DirectionAwareTabs, EmployeeAvatar, TimeTypeIcon } from "~/components";+import {+ DirectionAwareTabs,+ EmployeeAvatar,+ Empty,+ TimeTypeIcon,+} from "~/components";import {Hidden,InputControlled,@@ -1735,125 +1740,127 @@ function AttributesForm({isLoading={fetcher.state !== "idle"}// this is a hack to re-render the editor component when the form is submitted with the default values>- <div className="p-6 border rounded-lg mb-6">- <ValidatedForm- action={path.to.newMethodOperationAttribute}- method="post"- validator={operationAttributeValidator}- fetcher={fetcher}- resetAfterSubmit- defaultValues={{- id: undefined,- name: "",- description: {},- type: "Task",- unitOfMeasureCode: "",- minValue: 0,- maxValue: 0,- listValues: [],- sortOrder:- attributes.reduce(- (acc, a) => Math.max(acc, a.sortOrder ?? 0),- 0- ) + 1,- operationId,- }}- onSubmit={() => {- setType("Task");- setDescription({});- }}- className="w-full"- >- <Hidden name="operationId" />- <Hidden name="sortOrder" />- <Hidden name="description" value={JSON.stringify(description)} />- <VStack spacing={4}>- <div className="w-full grid grid-cols-1 lg:grid-cols-2 gap-4 items-start">- <SelectControlled- name="type"- label="Type"- options={typeOptions}- value={type}- onChange={(option) => {- if (option) {- setType(option.value as OperationAttribute["type"]);- }- }}- />- <Input name="name" label="Name" />- </div>-- <VStack spacing={2} className="w-full col-span-2">- <Label>Description</Label>- <Editor- initialValue={description}- onUpload={onUploadImage}- onChange={(value) => {- setDescription(value);- }}- className="[&_.is-empty]:text-muted-foreground min-h-[120px] p-4 rounded-lg border w-full"- />- </VStack>-- {type === "Measurement" && (+ {!isDisabled && (+ <div className="p-6 border rounded-lg mb-6">+ <ValidatedForm+ action={path.to.newMethodOperationAttribute}+ method="post"+ validator={operationAttributeValidator}+ fetcher={fetcher}+ resetAfterSubmit+ defaultValues={{+ id: undefined,+ name: "",+ description: {},+ type: "Task",+ unitOfMeasureCode: "",+ minValue: 0,+ maxValue: 0,+ listValues: [],+ sortOrder:+ attributes.reduce(+ (acc, a) => Math.max(acc, a.sortOrder ?? 0),+ 0+ ) + 1,+ operationId,+ }}+ onSubmit={() => {+ setType("Task");+ setDescription({});+ }}+ className="w-full"+ >+ <Hidden name="operationId" />+ <Hidden name="sortOrder" />+ <Hidden name="description" value={JSON.stringify(description)} />+ <VStack spacing={4}><div className="w-full grid grid-cols-1 lg:grid-cols-2 gap-4 items-start">- <UnitOfMeasure- name="unitOfMeasureCode"- label="Unit of Measure"+ <SelectControlled+ name="type"+ label="Type"+ options={typeOptions}+ value={type}+ onChange={(option) => {+ if (option) {+ setType(option.value as OperationAttribute["type"]);+ }+ }}/>+ <Input name="name" label="Name" />+ </div>- <ToggleGroup- type="multiple"- value={numericControls}- onValueChange={setNumericControls}- className="justify-start items-start mt-6"- >- <ToggleGroupItem size="sm" value="min">- <LuMinimize2 className="mr-2" />- Minimum- </ToggleGroupItem>- <ToggleGroupItem size="sm" value="max">- <LuMaximize2 className="mr-2" />- Maximum- </ToggleGroupItem>- </ToggleGroup>+ <VStack spacing={2} className="w-full col-span-2">+ <Label>Description</Label>+ <Editor+ initialValue={description}+ onUpload={onUploadImage}+ onChange={(value) => {+ setDescription(value);+ }}+ className="[&_.is-empty]:text-muted-foreground min-h-[120px] p-4 rounded-lg border w-full"+ />+ </VStack>- {numericControls.includes("min") && (- <Number- name="minValue"- label="Minimum"- formatOptions={{- minimumFractionDigits: 0,- maximumFractionDigits: 10,- }}- />- )}- {numericControls.includes("max") && (- <Number- name="maxValue"- label="Maximum"- formatOptions={{- minimumFractionDigits: 0,- maximumFractionDigits: 10,- }}+ {type === "Measurement" && (+ <div className="w-full grid grid-cols-1 lg:grid-cols-2 gap-4 items-start">+ <UnitOfMeasure+ name="unitOfMeasureCode"+ label="Unit of Measure"/>- )}- </div>- )}- {type === "List" && (- <ArrayInput name="listValues" label="List Options" />- )}- <Submit- leftIcon={<LuCirclePlus />}- isDisabled={isDisabled || fetcher.state !== "idle"}- isLoading={fetcher.state !== "idle"}- >- Add Step- </Submit>- </VStack>- </ValidatedForm>- </div>+ <ToggleGroup+ type="multiple"+ value={numericControls}+ onValueChange={setNumericControls}+ className="justify-start items-start mt-6"+ >+ <ToggleGroupItem size="sm" value="min">+ <LuMinimize2 className="mr-2" />+ Minimum+ </ToggleGroupItem>+ <ToggleGroupItem size="sm" value="max">+ <LuMaximize2 className="mr-2" />+ Maximum+ </ToggleGroupItem>+ </ToggleGroup>++ {numericControls.includes("min") && (+ <Number+ name="minValue"+ label="Minimum"+ formatOptions={{+ minimumFractionDigits: 0,+ maximumFractionDigits: 10,+ }}+ />+ )}+ {numericControls.includes("max") && (+ <Number+ name="maxValue"+ label="Maximum"+ formatOptions={{+ minimumFractionDigits: 0,+ maximumFractionDigits: 10,+ }}+ />+ )}+ </div>+ )}+ {type === "List" && (+ <ArrayInput name="listValues" label="List Options" />+ )}++ <Submit+ leftIcon={<LuCirclePlus />}+ isDisabled={isDisabled || fetcher.state !== "idle"}+ isLoading={fetcher.state !== "idle"}+ >+ Add Step+ </Submit>+ </VStack>+ </ValidatedForm>+ </div>+ )}{attributes.length > 0 && (<div className="border rounded-lg">@@ -1873,6 +1880,11 @@ function AttributesForm({))}</div>)}+ {attributes.length === 0 && isDisabled && (+ <div className="flex flex-1 py-24 justify-between items-center w-full">+ <Empty />+ </div>+ )}</Loading>);}@@ -2304,41 +2316,43 @@ function ParametersForm({return (<div className="flex flex-col gap-6">- <div className="p-6 border rounded-lg">- <ValidatedForm- action={path.to.newMethodOperationParameter}- method="post"- validator={operationParameterValidator}- fetcher={fetcher}- resetAfterSubmit- defaultValues={{- id: undefined,- key: "",- value: "",- operationId,- }}- className="w-full"- >- <Hidden name="operationId" />- <VStack spacing={4}>- <div className="w-full grid grid-cols-1 lg:grid-cols-2 gap-4 items-start">- <Input- name="key"- label="Key"- autoFocus={parameters.length === 0}- />- <Input name="value" label="Value" />- </div>- <Submit- leftIcon={<LuCirclePlus />}- isDisabled={isDisabled || fetcher.state !== "idle"}- isLoading={fetcher.state !== "idle"}- >- Add Parameter- </Submit>- </VStack>- </ValidatedForm>- </div>+ {!isDisabled && (+ <div className="p-6 border rounded-lg">+ <ValidatedForm+ action={path.to.newMethodOperationParameter}+ method="post"+ validator={operationParameterValidator}+ fetcher={fetcher}+ resetAfterSubmit+ defaultValues={{+ id: undefined,+ key: "",+ value: "",+ operationId,+ }}+ className="w-full"+ >+ <Hidden name="operationId" />+ <VStack spacing={4}>+ <div className="w-full grid grid-cols-1 lg:grid-cols-2 gap-4 items-start">+ <Input+ name="key"+ label="Key"+ autoFocus={parameters.length === 0}+ />+ <Input name="value" label="Value" />+ </div>+ <Submit+ leftIcon={<LuCirclePlus />}+ isDisabled={isDisabled || fetcher.state !== "idle"}+ isLoading={fetcher.state !== "idle"}+ >+ Add Parameter+ </Submit>+ </VStack>+ </ValidatedForm>+ </div>+ )}{parameters.length > 0 && (<div className="border rounded-lg">@@ -2359,6 +2373,11 @@ function ParametersForm({))}</div>)}+ {parameters.length === 0 && isDisabled && (+ <div className="flex flex-1 py-24 justify-between items-center w-full">+ <Empty />+ </div>+ )}</div>);}@@ -2575,38 +2594,44 @@ function ToolsForm({return (<div className="flex flex-col gap-6">- <div className="p-6 border rounded-lg">- <ValidatedForm- action={path.to.newMethodOperationTool}- method="post"- validator={operationToolValidator}- fetcher={fetcher}- resetAfterSubmit- defaultValues={{- id: undefined,- toolId: "",- quantity: 1,- operationId,- }}- className="w-full"- >- <Hidden name="operationId" />- <VStack spacing={4}>- <div className="w-full grid grid-cols-1 lg:grid-cols-2 gap-4 items-start">- <Tool name="toolId" label="Tool" autoFocus={tools.length === 0} />- <Number name="quantity" label="Quantity" />- </div>+ {!isDisabled && (+ <div className="p-6 border rounded-lg">+ <ValidatedForm+ action={path.to.newMethodOperationTool}+ method="post"+ validator={operationToolValidator}+ fetcher={fetcher}+ resetAfterSubmit+ defaultValues={{+ id: undefined,+ toolId: "",+ quantity: 1,+ operationId,+ }}+ className="w-full"+ >+ <Hidden name="operationId" />+ <VStack spacing={4}>+ <div className="w-full grid grid-cols-1 lg:grid-cols-2 gap-4 items-start">+ <Tool+ name="toolId"+ label="Tool"+ autoFocus={tools.length === 0}+ />+ <Number name="quantity" label="Quantity" />+ </div>- <Submit- leftIcon={<LuCirclePlus />}- isDisabled={isDisabled || fetcher.state !== "idle"}- isLoading={fetcher.state !== "idle"}- >- Add Tool- </Submit>- </VStack>- </ValidatedForm>- </div>+ <Submit+ leftIcon={<LuCirclePlus />}+ isDisabled={isDisabled || fetcher.state !== "idle"}+ isLoading={fetcher.state !== "idle"}+ >+ Add Tool+ </Submit>+ </VStack>+ </ValidatedForm>+ </div>+ )}{tools.length > 0 && (<div className="border rounded-lg">@@ -2624,6 +2649,11 @@ function ToolsForm({))}</div>)}+ {tools.length === 0 && isDisabled && (+ <div className="flex flex-1 py-24 justify-between items-center w-full">+ <Empty />+ </div>+ )}</div>);}diff --git a/apps/erp/app/modules/items/ui/Item/BoMExplorer.tsx b/apps/erp/app/modules/items/ui/Item/BoMExplorer.tsxindex 62c867b660..6e23f41d20 100644--- a/apps/erp/app/modules/items/ui/Item/BoMExplorer.tsx+++ b/apps/erp/app/modules/items/ui/Item/BoMExplorer.tsx@@ -36,16 +36,14 @@ import { getLinkToItemDetails } from "./ItemForm";type BoMExplorerProps = {itemType: MethodItemType;- makeMethodId: string;- makeMethodVersion: string;+ makeMethod: MakeMethod;methods: FlatTreeItem<Method>[];selectedId?: string;};const BoMExplorer = ({itemType,- makeMethodId,- makeMethodVersion,+ makeMethod,methods,selectedId,}: BoMExplorerProps) => {@@ -53,6 +51,13 @@ const BoMExplorer = ({const parentRef = useRef<HTMLDivElement>(null);const integrations = useIntegrations();const params = useParams();++ const {+ id: makeMethodId,+ version: makeMethodVersion,+ status: makeMethodStatus,+ } = makeMethod;+const {nodes,getTreeProps,@@ -126,7 +131,11 @@ const BoMExplorer = ({</InputGroup></HStack>{integrations.has("onshape") && (- <OnshapeSync makeMethodId={makeMethodId} itemId={itemId} />+ <OnshapeSync+ makeMethodId={makeMethodId}+ itemId={itemId}+ isDisabled={makeMethodStatus !== "Draft"}+ />)}<TreeViewparentRef={parentRef}diff --git a/apps/erp/app/routes/x+/part+/$itemId.manufacturing.$methodId.tsx b/apps/erp/app/routes/x+/part+/$itemId.manufacturing.$methodId.tsxindex 04fb4d30a5..137870b0fd 100644--- a/apps/erp/app/routes/x+/part+/$itemId.manufacturing.$methodId.tsx+++ b/apps/erp/app/routes/x+/part+/$itemId.manufacturing.$methodId.tsx@@ -157,8 +157,8 @@ export default function PartManufacturing() {<div className="grid h-full overflow-hidden p-2"><BoMExploreritemType="Part"- makeMethodId={makeMethod.id}- makeMethodVersion={makeMethod.version.toString()}+ makeMethod={makeMethod}+ makeMethodStatus={makeMethod.status}// @ts-ignoremethods={methods}/>diff --git a/apps/erp/app/routes/x+/tool+/$itemId.manufacturing.$methodId.tsx b/apps/erp/app/routes/x+/tool+/$itemId.manufacturing.$methodId.tsxindex eadc025b66..0a49cf3198 100644--- a/apps/erp/app/routes/x+/tool+/$itemId.manufacturing.$methodId.tsx+++ b/apps/erp/app/routes/x+/tool+/$itemId.manufacturing.$methodId.tsx@@ -146,8 +146,7 @@ export default function ToolManufacturing() {<div className="grid h-full overflow-hidden p-2"><BoMExploreritemType="Tool"- makeMethodId={makeMethod.id}- makeMethodVersion={makeMethod.version.toString()}+ makeMethod={makeMethod}// @ts-ignoremethods={methods}/>