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.

fix(items): show the List options error on steps and drop empty option rows

Raul8db14c5c34de
diff --git a/apps/erp/app/modules/items/ui/Item/BillOfProcess.tsx b/apps/erp/app/modules/items/ui/Item/BillOfProcess.tsx
index 8ca101883a..1377326de8 100644
--- a/apps/erp/app/modules/items/ui/Item/BillOfProcess.tsx
+++ b/apps/erp/app/modules/items/ui/Item/BillOfProcess.tsx
@@ -2346,7 +2346,11 @@ function AttributesForm({
</div>
)}
{type === "List" && (
- <ArrayInput name="listValues" label={t`List Options`} />
+ <ArrayInput
+ name="listValues"
+ label={t`List Options`}
+ isRequired
+ />
)}
<SlidesEditor
@@ -2759,7 +2763,11 @@ function AttributesListItem({
</div>
)}
{type === "List" && (
- <ArrayInput name="listValues" label={t`List Options`} />
+ <ArrayInput
+ name="listValues"
+ label={t`List Options`}
+ isRequired
+ />
)}
<StepSlides step={attribute} isDisabled={isDisabled} />
<StepParts
diff --git a/apps/erp/app/modules/production/production.models.ts b/apps/erp/app/modules/production/production.models.ts
index d748a41120..b1dc32f05b 100644
--- a/apps/erp/app/modules/production/production.models.ts
+++ b/apps/erp/app/modules/production/production.models.ts
@@ -14,6 +14,7 @@ import {
operationTypes,
procedureStepType,
standardFactorType,
+ stepListValues,
toTiptapDoc
} from "../shared/shared.models";
import type {
@@ -987,7 +988,7 @@ export const procedureStepValidator = z
unitOfMeasureCode: zfd.text(z.string().optional()),
minValue: zfd.numeric(z.number().min(0).optional()),
maxValue: zfd.numeric(z.number().min(0).optional()),
- listValues: z.array(z.string()).optional(),
+ listValues: stepListValues,
sortOrder: zfd.numeric(z.number().min(0).optional())
})
.refine(
@@ -1005,17 +1006,13 @@ export const procedureStepValidator = z
.refine(
(data) => {
if (data.type === "List") {
- return (
- !!data.listValues &&
- data.listValues.length > 0 &&
- data.listValues.every((option) => option.trim() !== "")
- );
+ return !!data.listValues && data.listValues.length > 0;
}
return true;
},
{
message: "List options are required",
- path: ["listOptions"]
+ path: ["listValues"]
}
)
.refine(
diff --git a/apps/erp/app/modules/production/ui/Jobs/JobBillOfProcess.tsx b/apps/erp/app/modules/production/ui/Jobs/JobBillOfProcess.tsx
index 6678bb71f7..d12e77b397 100644
--- a/apps/erp/app/modules/production/ui/Jobs/JobBillOfProcess.tsx
+++ b/apps/erp/app/modules/production/ui/Jobs/JobBillOfProcess.tsx
@@ -1609,7 +1609,11 @@ function StepsForm({
</div>
)}
{type === "List" && (
- <ArrayInput name="listValues" label={t`List Options`} />
+ <ArrayInput
+ name="listValues"
+ label={t`List Options`}
+ isRequired
+ />
)}
<SlidesEditor
@@ -2262,7 +2266,11 @@ function StepsListItem({
</div>
)}
{type === "List" && (
- <ArrayInput name="listValues" label={t`List Options`} />
+ <ArrayInput
+ name="listValues"
+ label={t`List Options`}
+ isRequired
+ />
)}
<JobStepSlides step={attribute} isDisabled={isDisabled} />
<JobStepParts
diff --git a/apps/erp/app/modules/production/ui/Procedures/ProcedureExplorer.tsx b/apps/erp/app/modules/production/ui/Procedures/ProcedureExplorer.tsx
index d57c2d5227..a5234e4866 100644
--- a/apps/erp/app/modules/production/ui/Procedures/ProcedureExplorer.tsx
+++ b/apps/erp/app/modules/production/ui/Procedures/ProcedureExplorer.tsx
@@ -874,7 +874,11 @@ function ProcedureStepForm({
</>
)}
{type === "List" && (
- <ArrayInput name="listValues" label={t`List Options`} />
+ <ArrayInput
+ name="listValues"
+ label={t`List Options`}
+ isRequired
+ />
)}
</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 e1dbf1bc92..50671de7c1 100644
--- a/apps/erp/app/modules/sales/ui/Quotes/QuoteBillOfProcess.tsx
+++ b/apps/erp/app/modules/sales/ui/Quotes/QuoteBillOfProcess.tsx
@@ -1032,7 +1032,11 @@ function AttributesForm({
</div>
)}
{type === "List" && (
- <ArrayInput name="listValues" label={t`List Options`} />
+ <ArrayInput
+ name="listValues"
+ label={t`List Options`}
+ isRequired
+ />
)}
<Submit
@@ -1281,7 +1285,11 @@ function AttributesListItem({
</div>
)}
{type === "List" && (
- <ArrayInput name="listValues" label={t`List Options`} />
+ <ArrayInput
+ name="listValues"
+ label={t`List Options`}
+ isRequired
+ />
)}
<HStack className="w-full justify-end" spacing={2}>
<Button variant="secondary" onClick={disclosure.onClose}>
diff --git a/apps/erp/app/modules/shared/shared.models.test.ts b/apps/erp/app/modules/shared/shared.models.test.ts
index 4411d954c8..d603add29f 100644
--- a/apps/erp/app/modules/shared/shared.models.test.ts
+++ b/apps/erp/app/modules/shared/shared.models.test.ts
@@ -5,6 +5,7 @@
import { describe, expect, it } from "vitest";
import {
normalizeOperationSourceIds,
+ operationStepValidator,
optionalTiptapDoc,
toTiptapDoc
} from "./shared.models";
@@ -122,3 +123,48 @@ describe("normalizeOperationSourceIds", () => {
).not.toHaveProperty("workCenterId");
});
});
+
+// A List step needs at least one option. The error must sit on `listValues`,
+// the field the step forms render: on any other path the form refused the save
+// with no message. Blank rows are dropped first, so the empty row "Add option"
+// leaves behind never blocks a save and is never stored.
+describe("operationStepValidator list options", () => {
+ const listStep = (listValues?: string[]) => ({
+ operationId: "op1",
+ name: "Pick a finish",
+ description: "Choose one",
+ type: "List" as const,
+ listValues
+ });
+
+ const listValuesError = (listValues?: string[]) => {
+ const result = operationStepValidator.safeParse(listStep(listValues));
+ if (result.success) return undefined;
+ return result.error.issues.find(
+ (issue) => issue.path.join(".") === "listValues"
+ )?.message;
+ };
+
+ it("puts the missing-options error on the listValues field", () => {
+ expect(listValuesError(undefined)).toBe("List options are required");
+ expect(listValuesError([])).toBe("List options are required");
+ });
+
+ it("treats a list of blank rows as no options", () => {
+ expect(listValuesError(["", " "])).toBe("List options are required");
+ });
+
+ it("drops a trailing empty row instead of refusing the save", () => {
+ const result = operationStepValidator.safeParse(
+ listStep(["Matte", "Gloss", ""])
+ );
+ expect(result.success).toBe(true);
+ expect(result.data?.listValues).toEqual(["Matte", "Gloss"]);
+ });
+
+ it("does not require options on other step types", () => {
+ expect(
+ operationStepValidator.safeParse({ ...listStep(), type: "Task" }).success
+ ).toBe(true);
+ });
+});
diff --git a/apps/erp/app/modules/shared/shared.models.ts b/apps/erp/app/modules/shared/shared.models.ts
index e6e295056c..42d336b407 100644
--- a/apps/erp/app/modules/shared/shared.models.ts
+++ b/apps/erp/app/modules/shared/shared.models.ts
@@ -277,6 +277,16 @@ export const optionalTiptapDoc = z
// omits `notes` stops compiling.
.optional();
+/**
+ * A List step's options. Blank rows (the empty row "Add option" leaves) are
+ * dropped before the step's refine runs, so a trailing empty row never blocks a
+ * save and is never stored.
+ */
+export const stepListValues = z
+ .array(z.string())
+ .transform((values) => values.filter((value) => value.trim() !== ""))
+ .optional();
+
export const operationStepValidator = z
.object({
id: zfd.text(z.string().optional()),
@@ -292,7 +302,7 @@ export const operationStepValidator = z
unitOfMeasureCode: zfd.text(z.string().optional()),
minValue: zfd.numeric(z.number().min(0).optional()),
maxValue: zfd.numeric(z.number().min(0).optional()),
- listValues: z.array(z.string()).optional(),
+ listValues: stepListValues,
sortOrder: zfd.numeric(z.number().min(0).optional())
})
.refine(
@@ -310,17 +320,13 @@ export const operationStepValidator = z
.refine(
(data) => {
if (data.type === "List") {
- return (
- Array.isArray(data.listValues) &&
- data.listValues.length > 0 &&
- data.listValues.every((option) => option.trim() !== "")
- );
+ return Array.isArray(data.listValues) && data.listValues.length > 0;
}
return true;
},
{
message: "List options are required",
- path: ["listOptions"]
+ path: ["listValues"]
}
)
.refine(