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: allow substance and shape to be inline editable in material properties sidebar
Brad Barbin43a326217c50
diff --git a/apps/erp/app/components/Form/Shape.tsx b/apps/erp/app/components/Form/Shape.tsxindex 4f02243e94..9f67ec22b8 100644--- a/apps/erp/app/components/Form/Shape.tsx+++ b/apps/erp/app/components/Form/Shape.tsx@@ -6,10 +6,21 @@ import { useMemo, useRef, useState } from "react";import { usePermissions } from "~/hooks";import type { getMaterialFormsList } from "~/modules/items";import { MaterialShapeForm } from "~/modules/items/ui/MaterialForms";-+import { Enumerable } from "../Enumerable";import { path } from "~/utils/path";-type ShapeSelectProps = Omit<ComboboxProps, "options">;+type ShapeSelectProps = Omit<ComboboxProps, "options" | "inline"> & {+ inline?: boolean;+};++const ShapePreview = (+ value: string,+ options: { value: string; label: string | JSX.Element }[]+) => {+ const shape = options.find((o) => o.value === value);+ // @ts-ignore+ return <Enumerable value={shape?.label ?? null} />;+};const Shape = (props: ShapeSelectProps) => {const options = useShape();@@ -25,6 +36,7 @@ const Shape = (props: ShapeSelectProps) => {ref={triggerRef}options={options}{...props}+ inline={props.inline ? ShapePreview : undefined}label={props?.label ?? "Shape"}onCreateOption={(option) => {newShapeModal.onOpen();@@ -46,7 +58,12 @@ const Shape = (props: ShapeSelectProps) => {)}</>) : (- <Combobox options={options} {...props} label={props?.label ?? "Form"} />+ <Combobox+ options={options}+ {...props}+ inline={props.inline ? ShapePreview : undefined}+ label={props?.label ?? "Form"}+ />);};diff --git a/apps/erp/app/components/Form/Substance.tsx b/apps/erp/app/components/Form/Substance.tsxindex 9dba369994..84c94307f2 100644--- a/apps/erp/app/components/Form/Substance.tsx+++ b/apps/erp/app/components/Form/Substance.tsx@@ -6,10 +6,21 @@ import { useMemo, useRef, useState } from "react";import { usePermissions } from "~/hooks";import type { getMaterialSubstancesList } from "~/modules/items";import { MaterialSubstanceForm } from "~/modules/items/ui/MaterialSubstances";-+import { Enumerable } from "../Enumerable";import { path } from "~/utils/path";-type SubstanceSelectProps = Omit<ComboboxProps, "options">;+type SubstanceSelectProps = Omit<ComboboxProps, "options" | "inline"> & {+ inline?: boolean;+};++const SubstancePreview = (+ value: string,+ options: { value: string; label: string | JSX.Element }[]+) => {+ const substance = options.find((o) => o.value === value);+ // @ts-ignore+ return <Enumerable value={substance?.label ?? null} />;+};const Substance = (props: SubstanceSelectProps) => {const options = useSubstance();@@ -25,6 +36,7 @@ const Substance = (props: SubstanceSelectProps) => {ref={triggerRef}options={options}{...props}+ inline={props.inline ? SubstancePreview : undefined}label={props?.label ?? "Substance"}onCreateOption={(option) => {newSubstanceModal.onOpen();@@ -49,6 +61,7 @@ const Substance = (props: SubstanceSelectProps) => {<Comboboxoptions={options}{...props}+ inline={props.inline ? SubstancePreview : undefined}label={props?.label ?? "Substance"}/>);diff --git a/apps/erp/app/modules/items/ui/Materials/MaterialProperties.tsx b/apps/erp/app/modules/items/ui/Materials/MaterialProperties.tsxindex a42a79dc80..de415815c3 100644--- a/apps/erp/app/modules/items/ui/Materials/MaterialProperties.tsx+++ b/apps/erp/app/modules/items/ui/Materials/MaterialProperties.tsx@@ -22,7 +22,6 @@ import { LuCopy, LuKeySquare, LuLink } from "react-icons/lu";import { z } from "zod";import { zfd } from "zod-form-data";import { MethodBadge, MethodIcon, TrackingTypeIcon } from "~/components";-import { Enumerable } from "~/components/Enumerable";import { Boolean, Tags, UnitOfMeasure } from "~/components/Form";import CustomFormInlineFields from "~/components/Form/CustomFormInlineFields";import { ItemThumbnailUpload } from "~/components/ItemThumnailUpload";@@ -36,6 +35,8 @@ import { copyToClipboard } from "~/utils/string";import { itemTrackingTypes } from "../../items.models";import type { ItemFile, Material, PickMethod, SupplierPart } from "../../types";import { FileBadge } from "../Item";+import Substance from "~/components/Form/Substance";+import Shape from "~/components/Form/Shape";const MaterialProperties = () => {const { itemId } = useParams();@@ -80,7 +81,9 @@ const MaterialProperties = () => {| "defaultMethodType"| "itemTrackingType"| "active"- | "unitOfMeasureCode",+ | "unitOfMeasureCode"+ | "materialFormId"+ | "materialSubstanceId",value: string | null) => {const formData = new FormData();@@ -311,17 +314,45 @@ const MaterialProperties = () => {</DropdownMenu></VStack>- <VStack spacing={2}>- <h3 className="text-xs text-muted-foreground">Shape</h3>- <Enumerable value={routeData?.materialSummary?.materialForm ?? null} />- </VStack>+ <ValidatedForm+ defaultValues={{+ materialFormId:+ routeData?.materialSummary?.materialFormId ?? undefined,+ }}+ validator={z.object({+ materialFormId: z.string().nullable(),+ })}+ className="w-full"+ >+ <Shape+ label="Shape"+ name="materialFormId"+ inline+ onChange={(value) => {+ onUpdate("materialFormId", value?.value ?? null);+ }}+ />+ </ValidatedForm>- <VStack spacing={2}>- <h3 className="text-xs text-muted-foreground">Substance</h3>- <Enumerable- value={routeData?.materialSummary?.materialSubstance ?? null}+ <ValidatedForm+ defaultValues={{+ materialSubstanceId:+ routeData?.materialSummary?.materialSubstanceId ?? undefined,+ }}+ validator={z.object({+ materialSubstanceId: z.string().nullable(),+ })}+ className="w-full"+ >+ <Substance+ label="Substance"+ name="materialSubstanceId"+ inline+ onChange={(value) => {+ onUpdate("materialSubstanceId", value?.value ?? null);+ }}/>- </VStack>+ </ValidatedForm><ValidatedFormdefaultValues={{diff --git a/apps/erp/app/routes/x+/items+/update.tsx b/apps/erp/app/routes/x+/items+/update.tsxindex fdd2436f3c..bf44237c02 100644--- a/apps/erp/app/routes/x+/items+/update.tsx+++ b/apps/erp/app/routes/x+/items+/update.tsx@@ -34,11 +34,14 @@ export async function action({ request }: ActionFunctionArgs) {case "materialFormId":case "materialSubstanceId":return json(- await client.from("material").update({- [field]: value,- updatedBy: userId,- updatedAt: new Date().toISOString(),- })+ await client+ .from("material")+ .update({+ [field]: value,+ updatedBy: userId,+ updatedAt: new Date().toISOString(),+ })+ .in("itemId", items as string[]));case "active":return json(