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
fix(grid): an inline number edit was dropped once the value formatted
sidgaikwad8feb5dadb202
diff --git a/apps/erp/app/components/Editable/EditableNumber.tsx b/apps/erp/app/components/Editable/EditableNumber.tsxindex f603fc11e9..0f57c88372 100644--- a/apps/erp/app/components/Editable/EditableNumber.tsx+++ b/apps/erp/app/components/Editable/EditableNumber.tsx@@ -1,24 +1,19 @@import type { NumberFieldProps } from "@carbon/react";import { NumberField, NumberInput } from "@carbon/react";import type { PostgrestSingleResponse } from "@supabase/supabase-js";+import { useRef } from "react";import type { EditableTableCellComponentProps } from "~/components/Editable";-const EditableNumber =- <T extends object>(- mutation: (- accessorKey: string,- newValue: string,- row: T- ) => Promise<PostgrestSingleResponse<unknown>>,- // Static props, or a function of the row for per-row limits (e.g. a serial- // line's `maxValue: 1`).- numberFieldProps?: NumberFieldProps | ((row: T) => NumberFieldProps),- // `clearable` lets an empty input persist as a cleared value (sent as "") so- // a nullable column can be reset. Off by default so non-nullable columns keep- // ignoring empty input.- options?: { clearable?: boolean }- ) =>- ({+const EditableNumber = <T extends object>(+ mutation: (+ accessorKey: string,+ newValue: string,+ row: T+ ) => Promise<PostgrestSingleResponse<unknown>>,+ numberFieldProps?: NumberFieldProps | ((row: T) => NumberFieldProps),+ options?: { clearable?: boolean }+) => {+ const EditableNumberEditor = ({value,row,accessorKey,@@ -30,13 +25,13 @@ const EditableNumber =? numberFieldProps(row): numberFieldProps;- // Postgres NUMERIC columns arrive as strings over the wire — coerce for the- // NumberField's initial (uncontrolled) value.const numericValue =value === null || value === undefined || value === ""? undefined: Number(value);+ const latestValue = useRef<number | undefined>(numericValue);+const clamp = (n: number) => {const { minValue, maxValue } = resolvedProps ?? {};let v = n;@@ -45,11 +40,9 @@ const EditableNumber =return v;};- // Push an edit into the table's state model + persist it.const commit = (raw: number | undefined) => {const isEmpty = raw === undefined || !Number.isFinite(raw);const next = isEmpty ? null : clamp(raw as number);- // Nothing changed (or an ignorable empty on a non-clearable/empty cell).if (next === (numericValue ?? null)) return;if (isEmpty &&@@ -59,7 +52,7 @@ const EditableNumber =onUpdate({ [accessorKey]: next });- // @ts-ignore - mutation receives the raw cell value ("" clears)+ // @ts-ignoremutation(accessorKey, isEmpty ? "" : next, row).then(({ error }) => {if (error) {@@ -74,28 +67,26 @@ const EditableNumber =};return (- // UNCONTROLLED (`defaultValue`, not `value`): the editing input only mounts- // for the selected cell and the surrounding page re-renders often, which- // would reset a controlled value mid-edit. react-aria's `onChange` commits- // on blur/Enter — but moving to another cell UNMOUNTS this input, and the- // unmount races that commit so it never fires. The DOM `onBlur` on the raw- // input fires synchronously before the unmount, so it is the reliable path- // that syncs the edit into the table's state model.- <NumberField {...resolvedProps} defaultValue={numericValue}>+ <NumberField+ {...resolvedProps}+ defaultValue={numericValue}+ onChange={(next) => {+ latestValue.current = Number.isNaN(next) ? undefined : next;+ resolvedProps?.onChange?.(next);+ }}+ ><NumberInputsize="sm"className="w-full rounded-none outline-none border-none shadow-none focus-visible:ring-0"autoFocusonFocus={(e) => e.currentTarget.select()}- onBlur={(e) => {- const text = (e.currentTarget.value ?? "").trim();- // Empty or unparseable → no value (commit guards against a stray 0).- const parsed = text === "" ? Number.NaN : Number(text);- commit(Number.isNaN(parsed) ? undefined : parsed);- }}+ onBlur={() => commit(latestValue.current)}/></NumberField>);};+ return EditableNumberEditor;+};+export default EditableNumber;diff --git a/apps/erp/app/modules/quality/ui/Inspections/InspectionMeasurementGrid.tsx b/apps/erp/app/modules/quality/ui/Inspections/InspectionMeasurementGrid.tsxindex f7c33430d0..aa2e89b51f 100644--- a/apps/erp/app/modules/quality/ui/Inspections/InspectionMeasurementGrid.tsx+++ b/apps/erp/app/modules/quality/ui/Inspections/InspectionMeasurementGrid.tsx@@ -596,11 +596,8 @@ const InspectionMeasurementGrid = ({> = {};for (let i = 0; i < columnCount; i++) {const key = sampleKey(i);- const numberEditor = EditableNumber<FeatureGridRow>(+ const NumberEditor = EditableNumber<FeatureGridRow>(onCellEdit,- // react-aria NumberField defaults to 3 fraction digits, which rounds- // fine measurements (e.g. thousandths/ten-thousandths of an inch) on- // blur. Allow up to 6 so precision readings persist intact.{ formatOptions: { maximumFractionDigits: 6 } },{clearable: true@@ -608,10 +605,9 @@ const InspectionMeasurementGrid = ({);components[key] = (props) => {if (!props.row.isNumeric) {- // Attribute feature: keep the Pass/Fail toggle visible when focused.return renderPassFail(props.row, i);}- return numberEditor(props);+ return <NumberEditor {...props} />;};}return components;