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(table): allow underscores in custom-field column keys

Sidwebworks0e60572899ba
diff --git a/apps/erp/app/components/Table/utils.test.ts b/apps/erp/app/components/Table/utils.test.ts
index 54559bacb6..1bd662b810 100644
--- a/apps/erp/app/components/Table/utils.test.ts
+++ b/apps/erp/app/components/Table/utils.test.ts
@@ -34,6 +34,14 @@ describe("buildColumnMaps", () => {
).toThrow(/Cannot contain '_'/);
});
+ it("allows an underscore in a custom-field accessor (generated id)", () => {
+ const { accessors } = buildColumnMaps(
+ cols({ accessorKey: "customFields->>qzAx_-vk3", header: "Color" }),
+ upper
+ );
+ expect(accessors).toEqual({ "customFields->>qzAx_-vk3": "COLOR" });
+ });
+
it("includes a display column (id, no accessor) that has exportValue", () => {
const exportValue = (row: Row) => row.tags.join(", ");
const { accessors, exportValues, sortKeyToLabel } = buildColumnMaps(
diff --git a/apps/erp/app/components/Table/utils.ts b/apps/erp/app/components/Table/utils.ts
index 4ecce9d7dd..5a244d1a75 100644
--- a/apps/erp/app/components/Table/utils.ts
+++ b/apps/erp/app/components/Table/utils.ts
@@ -33,7 +33,13 @@ export function buildColumnMaps<T>(
for (const column of columns) {
const accessorKey = getAccessorKey(column);
- if (accessorKey?.includes("_")) {
+ // '_' is the nested-path separator for editable cells (updateNestedProperty).
+ // Custom-field columns are read-only and keyed by a generated id that may
+ // contain '_', so they are exempt.
+ if (
+ accessorKey?.includes("_") &&
+ !accessorKey.startsWith("customFields->>")
+ ) {
throw new Error(`Invalid accessorKey ${accessorKey}. Cannot contain '_'`);
}