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 crud for attributes in method bom

Brad Barbin0fd481870c66
diff --git a/apps/erp/app/modules/items/items.service.ts b/apps/erp/app/modules/items/items.service.ts
index 674d53b1e0..7d09a0cfd1 100644
--- a/apps/erp/app/modules/items/items.service.ts
+++ b/apps/erp/app/modules/items/items.service.ts
@@ -1911,7 +1911,7 @@ export async function upsertMethodOperationAttribute(
companyId: string;
createdBy: string;
})
- | (Omit<z.infer<typeof operationParameterValidator>, "id"> & {
+ | (Omit<z.infer<typeof operationAttributeValidator>, "id"> & {
id: string;
updatedBy: string;
updatedAt: string;
diff --git a/apps/erp/app/modules/items/ui/Item/BillOfProcess.tsx b/apps/erp/app/modules/items/ui/Item/BillOfProcess.tsx
index e422d77a34..f37b657705 100644
--- a/apps/erp/app/modules/items/ui/Item/BillOfProcess.tsx
+++ b/apps/erp/app/modules/items/ui/Item/BillOfProcess.tsx
@@ -1,6 +1,6 @@
"use client";
import { useCarbon } from "@carbon/auth";
-import { Input, ValidatedForm } from "@carbon/form";
+import { Array as ArrayInput, Input, ValidatedForm } from "@carbon/form";
import type { JSONContent } from "@carbon/react";
import {
Alert,
@@ -21,6 +21,11 @@ import {
HStack,
IconButton,
Label,
+ ToggleGroup,
+ ToggleGroupItem,
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger,
VStack,
cn,
useDebounce,
@@ -34,13 +39,15 @@ import { useFetcher, useFetchers, useParams } from "@remix-run/react";
import { AnimatePresence, LayoutGroup, motion } from "framer-motion";
import { nanoid } from "nanoid";
import type { Dispatch, SetStateAction } from "react";
-import { useEffect, useRef, useState } from "react";
+import { useEffect, useMemo, useRef, useState } from "react";
import {
LuActivity,
LuChevronDown,
LuCirclePlus,
LuEllipsisVertical,
LuHammer,
+ LuInfo,
+ LuList,
LuSettings2,
LuSquareFunction,
LuTriangleAlert,
@@ -62,6 +69,7 @@ import {
Tags,
Tool,
UnitHint,
+ UnitOfMeasure,
WorkCenter,
} from "~/components/Form";
@@ -83,13 +91,17 @@ import type {
} from "~/modules/shared";
import {
methodOperationOrders,
+ operationAttributeValidator,
operationParameterValidator,
operationToolValidator,
operationTypes,
+ procedureAttributeType,
standardFactorType,
} from "~/modules/shared";
-import type { action as editMethodOperationToolAction } from "~/routes/x+/items+/methods+/operation.tool.$id";
+
+import type { action as editMethodOperationAttributeAction } from "~/routes/x+/items+/methods+/operation.attribute.$id";
import type { action as editMethodOperationParameterAction } from "~/routes/x+/items+/methods+/operation.parameter.$id";
+import type { action as editMethodOperationToolAction } from "~/routes/x+/items+/methods+/operation.tool.$id";
import type { action as newMethodOperationToolAction } from "~/routes/x+/items+/methods+/operation.tool.new";
import type { action as newMethodOperationParameterAction } from "~/routes/x+/items+/methods+/operation.parameter.new";
@@ -97,6 +109,9 @@ import { useTools } from "~/stores";
import { getPrivateUrl, path } from "~/utils/path";
import { methodOperationValidator } from "../../items.models";
import type { ConfigurationParameter, ConfigurationRule } from "../../types";
+import { ProcedureAttributeTypeIcon } from "~/components/Icons";
+import type { ProcedureAttribute } from "~/modules/production";
+import { useUnitOfMeasure } from "~/components/Form/UnitOfMeasure";
type Operation = z.infer<typeof methodOperationValidator> & {
workInstruction: JSONContent | null;
@@ -469,18 +484,21 @@ const BillOfProcess = ({
id: 2,
label: (
<span className="flex items-center gap-2">
- <span>Tools</span>
- {tools.length > 0 && <Count count={tools.length} />}
+ <span>Parameters</span>
+ {parameters.length > 0 && <Count count={parameters.length} />}
</span>
),
content: (
<div className="flex w-full flex-col py-4">
- <ToolsForm
- tools={tools}
+ <ParametersForm
+ parameters={parameters}
operationId={item.id!}
isDisabled={
selectedItemId === null || isTemporaryId(selectedItemId!)
}
+ configurable={configurable}
+ rulesByField={rulesByField}
+ onConfigure={onConfigure}
/>
</div>
),
@@ -489,14 +507,14 @@ const BillOfProcess = ({
id: 3,
label: (
<span className="flex items-center gap-2">
- <span>Parameters</span>
- {parameters.length > 0 && <Count count={parameters.length} />}
+ <span>Attributes</span>
+ {attributes.length > 0 && <Count count={attributes.length} />}
</span>
),
content: (
<div className="flex w-full flex-col py-4">
- <ParametersForm
- parameters={parameters}
+ <AttributesForm
+ attributes={attributes}
operationId={item.id!}
isDisabled={
selectedItemId === null || isTemporaryId(selectedItemId!)
@@ -512,11 +530,21 @@ const BillOfProcess = ({
id: 4,
label: (
<span className="flex items-center gap-2">
- <span>Attributes</span>
- {attributes.length > 0 && <Count count={attributes.length} />}
+ <span>Tools</span>
+ {tools.length > 0 && <Count count={tools.length} />}
</span>
),
- content: <div>Attributes</div>,
+ content: (
+ <div className="flex w-full flex-col py-4">
+ <ToolsForm
+ tools={tools}
+ operationId={item.id!}
+ isDisabled={
+ selectedItemId === null || isTemporaryId(selectedItemId!)
+ }
+ />
+ </div>
+ ),
},
];
@@ -1402,6 +1430,461 @@ function OperationForm({
);
}
+function AttributesForm({
+ operationId,
+ configurable,
+ isDisabled,
+ attributes,
+ rulesByField,
+ onConfigure,
+}: {
+ operationId: string;
+ configurable: boolean;
+ isDisabled: boolean;
+ attributes: OperationAttribute[];
+ rulesByField: Map<string, ConfigurationRule>;
+ onConfigure?: (c: Configuration) => void;
+}) {
+ const fetcher = useFetcher<typeof newMethodOperationParameterAction>();
+ const [type, setType] = useState<OperationAttribute["type"]>("Value");
+ const [numericControls, setNumericControls] = useState<string[]>([]);
+ const typeOptions = useMemo(
+ () =>
+ procedureAttributeType.map((type) => ({
+ label: (
+ <HStack>
+ <ProcedureAttributeTypeIcon type={type} className="mr-2" />
+ {type}
+ </HStack>
+ ),
+ value: type,
+ })),
+ []
+ );
+
+ if (isDisabled && isTemporaryId(operationId)) {
+ return (
+ <Alert className="max-w-[420px] mx-auto my-8">
+ <LuTriangleAlert />
+ <AlertTitle>Cannot add attributes to unsaved operation</AlertTitle>
+ <AlertDescription>
+ Please save the operation before adding attributes.
+ </AlertDescription>
+ </Alert>
+ );
+ }
+
+ return (
+ <div className="flex flex-col gap-6">
+ <div className="p-6 border rounded-lg">
+ <ValidatedForm
+ action={path.to.newMethodOperationAttribute}
+ method="post"
+ validator={operationAttributeValidator}
+ fetcher={fetcher}
+ resetAfterSubmit
+ defaultValues={{
+ id: undefined,
+ name: "",
+ description: "",
+ type: "Value",
+ unitOfMeasureCode: "",
+ minValue: 0,
+ maxValue: 0,
+ listValues: [],
+ sortOrder:
+ attributes.reduce(
+ (acc, a) => Math.max(acc, a.sortOrder ?? 0),
+ 0
+ ) + 1,
+ operationId,
+ }}
+ onSubmit={() => {
+ setType("Value");
+ }}
+ className="w-full"
+ >
+ <Hidden name="operationId" />
+ <Hidden name="sortOrder" />
+ <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}
+ onChange={(option) => {
+ if (option) {
+ setType(option.value as ProcedureAttribute["type"]);
+ }
+ }}
+ />
+ <Input name="name" label="Name" />
+ </div>
+
+ {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"
+ />
+
+ <ToggleGroup
+ type="multiple"
+ value={numericControls}
+ onValueChange={setNumericControls}
+ className="justify-start items-start mt-6"
+ >
+ <ToggleGroupItem value="min">Minimum</ToggleGroupItem>
+ <ToggleGroupItem value="max">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 Attribute
+ </Submit>
+ </VStack>
+ </ValidatedForm>
+ </div>
+
+ {attributes.length > 0 && (
+ <div className="border rounded-lg">
+ {[...attributes]
+ .sort((a, b) => (a.sortOrder ?? 0) - (b.sortOrder ?? 0))
+ .map((a, index) => (
+ <AttributesListItem
+ key={a.id}
+ attribute={a}
+ operationId={operationId}
+ typeOptions={typeOptions}
+ className={index === attributes.length - 1 ? "border-none" : ""}
+ configurable={configurable}
+ rulesByField={rulesByField}
+ onConfigure={onConfigure}
+ />
+ ))}
+ </div>
+ )}
+ </div>
+ );
+}
+
+function AttributesListItem({
+ attribute,
+ operationId,
+ typeOptions,
+ className,
+ configurable,
+ rulesByField,
+ onConfigure,
+}: {
+ attribute: OperationAttribute;
+ operationId: string;
+ typeOptions: { label: JSX.Element; value: string }[];
+ className?: string;
+ configurable: boolean;
+ rulesByField: Map<string, ConfigurationRule>;
+ onConfigure?: (c: Configuration) => void;
+}) {
+ const {
+ name,
+ unitOfMeasureCode,
+ minValue,
+ maxValue,
+ id,
+ updatedBy,
+ updatedAt,
+ createdBy,
+ createdAt,
+ } = attribute;
+
+ const disclosure = useDisclosure();
+ const deleteModalDisclosure = useDisclosure();
+ const submitted = useRef(false);
+ const fetcher = useFetcher<typeof editMethodOperationAttributeAction>();
+
+ useEffect(() => {
+ if (submitted.current && fetcher.state === "idle") {
+ disclosure.onClose();
+ submitted.current = false;
+ }
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [fetcher.state]);
+
+ const [type, setType] = useState<OperationAttribute["type"]>(attribute.type);
+ const [numericControls, setNumericControls] = useState<string[]>(() => {
+ const controls = [];
+ if (type === "Measurement") {
+ if (minValue !== null) {
+ controls.push("min");
+ }
+ if (maxValue !== null) {
+ controls.push("max");
+ }
+ }
+ return controls;
+ });
+
+ const isUpdated = updatedBy !== null;
+ const person = isUpdated ? updatedBy : createdBy;
+ const date = updatedAt ?? createdAt;
+
+ const unitOfMeasures = useUnitOfMeasure();
+
+ if (!id) return null;
+
+ const isConfigured =
+ configurable &&
+ attribute.type === "Measurement" &&
+ (rulesByField.has(getFieldKey(`attribute:${id}:minValue`, operationId)) ||
+ rulesByField.has(getFieldKey(`attribute:${id}:maxValue`, operationId)));
+
+ return (
+ <div className={cn("border-b p-6", className)}>
+ {disclosure.isOpen ? (
+ <ValidatedForm
+ action={path.to.methodOperationAttribute(id)}
+ method="post"
+ validator={operationAttributeValidator}
+ fetcher={fetcher}
+ resetAfterSubmit
+ onSubmit={() => {
+ disclosure.onClose();
+ }}
+ defaultValues={{
+ ...attribute,
+ 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">
+ <SelectControlled
+ name="type"
+ label="Type"
+ options={typeOptions}
+ onChange={(option) => {
+ if (option) {
+ setType(option.value as ProcedureAttribute["type"]);
+ }
+ }}
+ />
+ <Input name="name" label="Name" />
+ </div>
+ <Input name="description" label="Description" />
+ {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"
+ />
+
+ <ToggleGroup
+ type="multiple"
+ value={numericControls}
+ onValueChange={setNumericControls}
+ className="justify-start items-start mt-6"
+ >
+ <ToggleGroupItem value="min">Minimum</ToggleGroupItem>
+ <ToggleGroupItem value="max">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" />
+ )}
+ <HStack className="w-full justify-end" spacing={2}>
+ <Button variant="secondary" onClick={disclosure.onClose}>
+ Cancel
+ </Button>
+ <Submit
+ isDisabled={fetcher.state !== "idle"}
+ isLoading={fetcher.state !== "idle"}
+ >
+ Save
+ </Submit>
+ </HStack>
+ </VStack>
+ </ValidatedForm>
+ ) : (
+ <div className="flex flex-1 justify-between items-center w-full">
+ <HStack spacing={4} className="w-1/2">
+ <HStack spacing={4} className="flex-1">
+ <div className="bg-muted border rounded-full flex items-center justify-center p-2">
+ <ProcedureAttributeTypeIcon type={type} />
+ </div>
+ <VStack spacing={0}>
+ <HStack>
+ <p className="text-foreground text-sm font-medium">
+ {attribute.name}
+ </p>
+ {attribute.description && (
+ <Tooltip>
+ <TooltipTrigger>
+ <LuInfo className="text-muted-foreground size-3" />
+ </TooltipTrigger>
+ <TooltipContent side="right">
+ <p className="text-foreground text-sm">
+ {attribute.description}
+ </p>
+ </TooltipContent>
+ </Tooltip>
+ )}
+ </HStack>
+ {attribute.type === "Measurement" && (
+ <span className="text-xs text-muted-foreground text-right">
+ {attribute.minValue !== null && attribute.maxValue !== null
+ ? `Must be between ${attribute.minValue} and ${
+ attribute.maxValue
+ } ${
+ unitOfMeasures.find(
+ (u) => u.value === unitOfMeasureCode
+ )?.label
+ }`
+ : attribute.minValue !== null
+ ? `Must be > ${attribute.minValue} ${
+ unitOfMeasures.find(
+ (u) => u.value === unitOfMeasureCode
+ )?.label
+ }`
+ : `Must be < ${attribute.maxValue} ${
+ unitOfMeasures.find(
+ (u) => u.value === unitOfMeasureCode
+ )?.label
+ }`}
+ </span>
+ )}
+ </VStack>
+ {isConfigured && (
+ <Tooltip>
+ <TooltipTrigger>
+ <LuSquareFunction
+ aria-label="Configured"
+ className="size-4 text-emerald-500"
+ />
+ </TooltipTrigger>
+ <TooltipContent>
+ <p className="text-foreground text-sm">
+ This attribute is configured for this operation.
+ </p>
+ </TooltipContent>
+ </Tooltip>
+ )}
+ {attribute.type === "List" &&
+ Array.isArray(attribute.listValues) && (
+ <Tooltip>
+ <TooltipTrigger>
+ <LuList className="size-4 text-muted-foreground" />
+ </TooltipTrigger>
+ <TooltipContent>
+ {attribute.listValues.map((value) => (
+ <p key={value} className="text-foreground text-sm">
+ {value}
+ </p>
+ ))}
+ </TooltipContent>
+ </Tooltip>
+ )}
+ </HStack>
+ </HStack>
+ <div className="flex items-center justify-end gap-2">
+ <HStack spacing={2}>
+ <span className="text-xs text-muted-foreground">
+ {isUpdated ? "Updated" : "Created"} {formatRelativeTime(date)}
+ </span>
+ <EmployeeAvatar employeeId={person} withName={false} />
+ </HStack>
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <IconButton
+ aria-label="Open menu"
+ icon={<LuEllipsisVertical />}
+ variant="ghost"
+ />
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="end">
+ <DropdownMenuItem onClick={disclosure.onOpen}>
+ Edit
+ </DropdownMenuItem>
+ <DropdownMenuItem
+ destructive
+ onClick={deleteModalDisclosure.onOpen}
+ >
+ Delete
+ </DropdownMenuItem>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ </div>
+ </div>
+ )}
+ {deleteModalDisclosure.isOpen && (
+ <ConfirmDelete
+ action={path.to.deleteMethodOperationAttribute(id)}
+ isOpen={deleteModalDisclosure.isOpen}
+ name={name}
+ text={`Are you sure you want to delete the ${name} attribute from this operation? This cannot be undone.`}
+ onCancel={() => {
+ deleteModalDisclosure.onClose();
+ }}
+ onSubmit={() => {
+ deleteModalDisclosure.onClose();
+ }}
+ />
+ )}
+ </div>
+ );
+}
+
function ParametersForm({
operationId,
configurable,
@@ -1526,6 +2009,10 @@ function ParametersListItem({
if (!id) return null;
+ const isConfigured = rulesByField.has(
+ getFieldKey(`parameter:${id}:value`, operationId)
+ );
+
return (
<div className={cn("border-b p-6", className)}>
{disclosure.isOpen ? (
@@ -1553,9 +2040,7 @@ function ParametersListItem({
<Input
name="value"
label="Value"
- isConfigured={rulesByField.has(
- getFieldKey(`parameter:${id}:value`, operationId)
- )}
+ isConfigured={isConfigured}
onConfigure={
configurable && typeof onConfigure === "function"
? () => {
@@ -1597,20 +2082,31 @@ function ParametersListItem({
<HStack spacing={4} className="flex-1">
<div className="bg-muted border rounded-full flex items-center justify-center p-2">
<LuActivity
- className={cn(
- "size-4",
- rulesByField.has(
- getFieldKey(`parameter:${id}:value`, operationId)
- ) && "text-emerald-500"
- )}
+ className={cn("size-4", isConfigured && "text-emerald-500")}
/>
</div>
<VStack spacing={0}>
<span className="text-sm font-medium">{key}</span>
</VStack>
- <span className="text-base text-muted-foreground text-right">
- {value}
- </span>
+ {isConfigured ? (
+ <Tooltip>
+ <TooltipTrigger>
+ <LuSquareFunction
+ aria-label="Configured"
+ className="size-4 text-emerald-500"
+ />
+ </TooltipTrigger>
+ <TooltipContent>
+ <p className="text-foreground text-sm">
+ This value is configured for this operation.
+ </p>
+ </TooltipContent>
+ </Tooltip>
+ ) : (
+ <span className="text-base text-muted-foreground text-right">
+ {value}
+ </span>
+ )}
</HStack>
</HStack>
<div className="flex items-center justify-end gap-2">
diff --git a/apps/erp/app/modules/production/ui/Jobs/JobBillOfProcess.tsx b/apps/erp/app/modules/production/ui/Jobs/JobBillOfProcess.tsx
index e261049044..1ec9cabe8c 100644
--- a/apps/erp/app/modules/production/ui/Jobs/JobBillOfProcess.tsx
+++ b/apps/erp/app/modules/production/ui/Jobs/JobBillOfProcess.tsx
@@ -681,14 +681,14 @@ const JobBillOfProcess = ({
id: 2,
label: (
<span className="flex items-center gap-2">
- <span>Tools</span>
- {tools.length > 0 && <Count count={tools.length} />}
+ <span>Parameters</span>
+ {parameters.length > 0 && <Count count={parameters.length} />}
</span>
),
content: (
<div className="flex w-full flex-col py-4">
- <ToolsForm
- tools={tools}
+ <ParametersForm
+ parameters={parameters}
operationId={item.id!}
isDisabled={
selectedItemId === null || isTemporaryId(selectedItemId!)
@@ -698,17 +698,17 @@ const JobBillOfProcess = ({
),
},
{
- id: 3,
+ id: 4,
label: (
<span className="flex items-center gap-2">
- <span>Parameters</span>
- {parameters.length > 0 && <Count count={parameters.length} />}
+ <span>Tools</span>
+ {tools.length > 0 && <Count count={tools.length} />}
</span>
),
content: (
<div className="flex w-full flex-col py-4">
- <ParametersForm
- parameters={parameters}
+ <ToolsForm
+ tools={tools}
operationId={item.id!}
isDisabled={
selectedItemId === null || isTemporaryId(selectedItemId!)
@@ -718,7 +718,7 @@ const JobBillOfProcess = ({
),
},
{
- id: 4,
+ id: 5,
label: "Events",
content: (
<div className="flex w-full flex-col pr-2 py-6 min-h-[300px]">
@@ -743,7 +743,7 @@ const JobBillOfProcess = ({
),
},
{
- id: 5,
+ id: 6,
label: "Chat",
content: <OperationChat jobOperationId={item.id} />,
},
diff --git a/apps/erp/app/modules/production/ui/Procedures/ProcedureAttributesExplorer.tsx b/apps/erp/app/modules/production/ui/Procedures/ProcedureAttributesExplorer.tsx
index cd8c9d2493..efbaa8c322 100644
--- a/apps/erp/app/modules/production/ui/Procedures/ProcedureAttributesExplorer.tsx
+++ b/apps/erp/app/modules/production/ui/Procedures/ProcedureAttributesExplorer.tsx
@@ -547,7 +547,7 @@ function ProcedureAttributeForm({
</>
)}
{type === "List" && (
- <ArrayInput name="listOptions" label="List Options" />
+ <ArrayInput name="listValues" label="List Options" />
)}
</VStack>
</DrawerBody>
diff --git a/apps/erp/app/modules/sales/ui/Quotes/QuoteBillOfProcess.tsx b/apps/erp/app/modules/sales/ui/Quotes/QuoteBillOfProcess.tsx
index 808a697bea..bc22c081e2 100644
--- a/apps/erp/app/modules/sales/ui/Quotes/QuoteBillOfProcess.tsx
+++ b/apps/erp/app/modules/sales/ui/Quotes/QuoteBillOfProcess.tsx
@@ -45,7 +45,7 @@ import {
LuTriangleAlert,
LuX,
} from "react-icons/lu";
-import { z } from "zod";
+import type { z } from "zod";
import { DirectionAwareTabs, EmployeeAvatar, TimeTypeIcon } from "~/components";
import {
Hidden,
@@ -527,14 +527,14 @@ const QuoteBillOfProcess = ({
id: 2,
label: (
<span className="flex items-center gap-2">
- <span>Tools</span>
- {tools.length > 0 && <Count count={tools.length} />}
+ <span>Parameters</span>
+ {parameters.length > 0 && <Count count={parameters.length} />}
</span>
),
content: (
<div className="flex w-full flex-col py-4">
- <ToolsForm
- tools={tools}
+ <ParametersForm
+ parameters={parameters}
operationId={item.id!}
isDisabled={
selectedItemId === null || isTemporaryId(selectedItemId!)
@@ -544,17 +544,17 @@ const QuoteBillOfProcess = ({
),
},
{
- id: 3,
+ id: 4,
label: (
<span className="flex items-center gap-2">
- <span>Parameters</span>
- {parameters.length > 0 && <Count count={parameters.length} />}
+ <span>Tools</span>
+ {tools.length > 0 && <Count count={tools.length} />}
</span>
),
content: (
<div className="flex w-full flex-col py-4">
- <ParametersForm
- parameters={parameters}
+ <ToolsForm
+ tools={tools}
operationId={item.id!}
isDisabled={
selectedItemId === null || isTemporaryId(selectedItemId!)
diff --git a/apps/erp/app/modules/shared/shared.models.ts b/apps/erp/app/modules/shared/shared.models.ts
index eda0df560d..0a46356aee 100644
--- a/apps/erp/app/modules/shared/shared.models.ts
+++ b/apps/erp/app/modules/shared/shared.models.ts
@@ -122,8 +122,9 @@ export const operationAttributeValidator = z
.refine(
(data) => {
if (data.type === "List") {
+ console.log(data.listValues);
return (
- !!data.listValues &&
+ Array.isArray(data.listValues) &&
data.listValues.length > 0 &&
data.listValues.every((option) => option.trim() !== "")
);
diff --git a/apps/erp/app/routes/x+/items+/methods+/operation.attribute.$id.tsx b/apps/erp/app/routes/x+/items+/methods+/operation.attribute.$id.tsx
new file mode 100644
index 0000000000..aed8a1179e
--- /dev/null
+++ b/apps/erp/app/routes/x+/items+/methods+/operation.attribute.$id.tsx
@@ -0,0 +1,66 @@
+import { assertIsPost, error, success } from "@carbon/auth";
+import { requirePermissions } from "@carbon/auth/auth.server";
+import { flash } from "@carbon/auth/session.server";
+import { validator } from "@carbon/form";
+import { json, type ActionFunctionArgs } from "@vercel/remix";
+import { upsertMethodOperationAttribute } from "~/modules/items";
+import { operationAttributeValidator } from "~/modules/shared";
+
+export async function action({ request, params }: ActionFunctionArgs) {
+ assertIsPost(request);
+ const { client, userId } = await requirePermissions(request, {
+ update: "parts",
+ });
+
+ const { id } = params;
+ if (!id) {
+ return json({ success: false, message: "Invalid operation attribute id" });
+ }
+
+ const formData = await request.formData();
+ const validation = await validator(operationAttributeValidator).validate(
+ formData
+ );
+
+ if (validation.error) {
+ return json({ success: false, message: "Invalid form data" });
+ }
+
+ const { id: _id, ...data } = validation.data;
+
+ const update = await upsertMethodOperationAttribute(client, {
+ id,
+ ...data,
+ updatedBy: userId,
+ updatedAt: new Date().toISOString(),
+ });
+ if (update.error) {
+ return json(
+ {
+ id: null,
+ },
+ await flash(
+ request,
+ error(update.error, "Failed to update method operation attribute")
+ )
+ );
+ }
+
+ const methodOperationAttributeId = update.data?.id;
+ if (!methodOperationAttributeId) {
+ return json(
+ {
+ id: null,
+ },
+ await flash(
+ request,
+ error(update.error, "Failed to update method operation attribute")
+ )
+ );
+ }
+
+ return json(
+ { id: methodOperationAttributeId },
+ await flash(request, success("Method operation attribute updated"))
+ );
+}
diff --git a/apps/erp/app/routes/x+/items+/methods+/operation.attribute.delete.$id.tsx b/apps/erp/app/routes/x+/items+/methods+/operation.attribute.delete.$id.tsx
new file mode 100644
index 0000000000..7e15f778ab
--- /dev/null
+++ b/apps/erp/app/routes/x+/items+/methods+/operation.attribute.delete.$id.tsx
@@ -0,0 +1,38 @@
+import { assertIsPost, error } from "@carbon/auth";
+import { requirePermissions } from "@carbon/auth/auth.server";
+import { flash } from "@carbon/auth/session.server";
+import { json, type ActionFunctionArgs } from "@vercel/remix";
+import { deleteMethodOperationAttribute } from "~/modules/items";
+
+export async function action({ request, params }: ActionFunctionArgs) {
+ assertIsPost(request);
+ const { client } = await requirePermissions(request, {
+ delete: "parts",
+ });
+
+ const { id } = params;
+ if (!id) {
+ throw new Error("id not found");
+ }
+
+ const deleteOperationAttribute = await deleteMethodOperationAttribute(
+ client,
+ id
+ );
+ if (deleteOperationAttribute.error) {
+ return json(
+ {
+ id: null,
+ },
+ await flash(
+ request,
+ error(
+ deleteOperationAttribute.error,
+ "Failed to delete method operation attribute"
+ )
+ )
+ );
+ }
+
+ return json({});
+}
diff --git a/apps/erp/app/routes/x+/items+/methods+/operation.attribute.new.tsx b/apps/erp/app/routes/x+/items+/methods+/operation.attribute.new.tsx
new file mode 100644
index 0000000000..2a9ccc2515
--- /dev/null
+++ b/apps/erp/app/routes/x+/items+/methods+/operation.attribute.new.tsx
@@ -0,0 +1,55 @@
+import { assertIsPost, error } from "@carbon/auth";
+import { requirePermissions } from "@carbon/auth/auth.server";
+import { flash } from "@carbon/auth/session.server";
+import { validationError, validator } from "@carbon/form";
+import { json, type ActionFunctionArgs } from "@vercel/remix";
+import { upsertMethodOperationAttribute } from "~/modules/items";
+import { operationAttributeValidator } from "~/modules/shared";
+
+export async function action({ request }: ActionFunctionArgs) {
+ assertIsPost(request);
+ const { client, companyId, userId } = await requirePermissions(request, {
+ create: "parts",
+ });
+
+ const formData = await request.formData();
+ const validation = await validator(operationAttributeValidator).validate(
+ formData
+ );
+
+ if (validation.error) {
+ return validationError(validation.error);
+ }
+
+ const insert = await upsertMethodOperationAttribute(client, {
+ ...validation.data,
+ companyId,
+ createdBy: userId,
+ });
+ if (insert.error) {
+ return json(
+ {
+ id: null,
+ },
+ await flash(
+ request,
+ error(insert.error, "Failed to insert method operation attribute")
+ )
+ );
+ }
+
+ const methodOperationAttributeId = insert.data?.id;
+ if (!methodOperationAttributeId) {
+ return json(
+ {
+ id: null,
+ },
+ await flash(
+ request,
+ error(insert.error, "Failed to insert method operation attribute")
+ )
+ );
+ }
+
+ return json({ id: methodOperationAttributeId });
+}
diff --git a/apps/erp/app/routes/x+/items+/methods+/operation.parameter.new.tsx b/apps/erp/app/routes/x+/items+/methods+/operation.parameter.new.tsx
index 7eeaf4a7e5..31969f1ced 100644
--- a/apps/erp/app/routes/x+/items+/methods+/operation.parameter.new.tsx
+++ b/apps/erp/app/routes/x+/items+/methods+/operation.parameter.new.tsx
@@ -46,7 +46,7 @@ export async function action({ request }: ActionFunctionArgs) {
},
await flash(
request,
- error(insert.error, "Failed to insert method operation tool")
+ error(insert.error, "Failed to insert method operation parameter")
)
);
}
diff --git a/apps/erp/app/routes/x+/part+/$itemId.manufacturing.tsx b/apps/erp/app/routes/x+/part+/$itemId.manufacturing.tsx
index 182ca817d8..9bfc65757f 100644
--- a/apps/erp/app/routes/x+/part+/$itemId.manufacturing.tsx
+++ b/apps/erp/app/routes/x+/part+/$itemId.manufacturing.tsx
@@ -5,7 +5,7 @@ import {
ResizablePanelGroup,
ScrollArea,
} from "@carbon/react";
-import type { ShouldRevalidateFunctionArgs } from "@remix-run/react";
+
import {
Outlet,
json,
@@ -34,17 +34,6 @@ import { BoMExplorer } from "~/modules/items/ui/Item";
import type { MethodItemType, MethodType } from "~/modules/shared";
import { path } from "~/utils/path";
-export const shouldRevalidate = ({
- formAction,
- defaultShouldRevalidate,
-}: ShouldRevalidateFunctionArgs) => {
- // Replace '/specific/path' with the path you want to exclude
- if (formAction && formAction.includes("tool")) {
- return false;
- }
- return defaultShouldRevalidate;
-};
-
export async function loader({ request, params }: LoaderFunctionArgs) {
const { client, companyId } = await requirePermissions(request, {
view: "parts",
diff --git a/apps/erp/app/utils/path.ts b/apps/erp/app/utils/path.ts
index 9d6c0a59bc..302bbe13b1 100644
--- a/apps/erp/app/utils/path.ts
+++ b/apps/erp/app/utils/path.ts
@@ -313,6 +313,8 @@ export const path = {
deleteJob: (id: string) => generatePath(`${x}/job/${id}/delete`),
deleteJobMaterial: (jobId: string, id: string) =>
generatePath(`${x}/job/methods/${jobId}/material/delete/${id}`),
+ deleteJobOperationAttribute: (id: string) =>
+ generatePath(`${x}/job/methods/operation/attribute/delete/${id}`),
deleteJobOperationParameter: (id: string) =>
generatePath(`${x}/job/methods/operation/parameter/delete/${id}`),
deleteJobOperationTool: (id: string) =>
@@ -323,6 +325,8 @@ export const path = {
generatePath(`${x}/items/substances/delete/${id}`),
deleteMethodMaterial: (id: string) =>
generatePath(`${x}/items/methods/material/delete/${id}`),
+ deleteMethodOperationAttribute: (id: string) =>
+ generatePath(`${x}/items/methods/operation/attribute/delete/${id}`),
deleteMethodOperationParameter: (id: string) =>
generatePath(`${x}/items/methods/operation/parameter/delete/${id}`),
deleteMethodOperationTool: (id: string) =>
@@ -361,6 +365,8 @@ export const path = {
generatePath(
`${x}/quote/methods/${quoteId}/${lineId}/material/delete/${id}`
),
+ deleteQuoteOperationAttribute: (id: string) =>
+ generatePath(`${x}/quote/methods/operation/attribute/delete/${id}`),
deleteQuoteOperationParameter: (id: string) =>
generatePath(`${x}/quote/methods/operation/parameter/delete/${id}`),
deleteQuoteOperationTool: (id: string) =>
@@ -475,6 +481,8 @@ export const path = {
jobOperations: (id: string) => generatePath(`${x}/job/${id}/operations`),
jobOperationsOrder: `${x}/job/methods/operation/order`,
jobOperationsDelete: `${x}/job/methods/operation/delete`,
+ jobOperationAttribute: (id: string) =>
+ generatePath(`${x}/job/methods/operation/attribute/${id}`),
jobOperationParameter: (id: string) =>
generatePath(`${x}/job/methods/operation/parameter/${id}`),
jobOperationTool: (id: string) =>
@@ -531,6 +539,8 @@ export const path = {
methodOperations: `${x}/items/methods/operations`,
methodOperationsOrder: `${x}/items/methods/operation/order`,
methodOperationsDelete: `${x}/items/methods/operation/delete`,
+ methodOperationAttribute: (id: string) =>
+ generatePath(`${x}/items/methods/operation/attribute/${id}`),
methodOperationParameter: (id: string) =>
generatePath(`${x}/items/methods/operation/parameter/${id}`),
methodOperationTool: (id: string) =>
@@ -580,12 +590,14 @@ export const path = {
generatePath(`${x}/job/methods/${jobId}/material/new`),
newJobOperation: (jobId: string) =>
generatePath(`${x}/job/methods/${jobId}/operation/new`),
+ newJobOperationAttribute: `${x}/job/methods/operation/attribute/new`,
newJobOperationParameter: `${x}/job/methods/operation/parameter/new`,
newJobOperationTool: `${x}/job/methods/operation/tool/new`,
newLocation: `${x}/resources/locations/new`,
newMaterial: `${x}/material/new`,
newMethodMaterial: `${x}/items/methods/material/new`,
newMethodOperation: `${x}/items/methods/operation/new`,
+ newMethodOperationAttribute: `${x}/items/methods/operation/attribute/new`,
newMethodOperationTool: `${x}/items/methods/operation/tool/new`,
newMethodOperationParameter: `${x}/items/methods/operation/parameter/new`,
newNote: `${x}/shared/notes/new`,
@@ -616,6 +628,7 @@ export const path = {
generatePath(`${x}/quote/${id}/${lineId}/cost/new`),
newQuoteOperation: (quoteId: string, lineId: string) =>
generatePath(`${x}/quote/methods/${quoteId}/${lineId}/operation/new`),
+ newQuoteOperationAttribute: `${x}/quote/methods/operation/attribute/new`,
newQuoteOperationParameter: `${x}/quote/methods/operation/parameter/new`,
newQuoteOperationTool: `${x}/quote/methods/operation/tool/new`,
newQuoteMaterial: (quoteId: string, lineId: string) =>
@@ -801,6 +814,8 @@ export const path = {
generatePath(`${x}/quote/methods/${quoteId}/${lineId}/operation/${id}`),
quoteOperationsOrder: `${x}/quote/methods/operation/order`,
quoteOperationsDelete: `${x}/quote/methods/operation/delete`,
+ quoteOperationAttribute: (id: string) =>
+ generatePath(`${x}/quote/methods/operation/attribute/${id}`),
quoteOperationParameter: (id: string) =>
generatePath(`${x}/quote/methods/operation/parameter/${id}`),
quoteOperationTool: (id: string) =>