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: parallelizable operations
Brad Barbin792ef017dfb8
diff --git a/apps/carbon/app/components/SortableList.tsx b/apps/carbon/app/components/SortableList.tsxindex a19dc655dc..c1cd598442 100644--- a/apps/carbon/app/components/SortableList.tsx+++ b/apps/carbon/app/components/SortableList.tsx@@ -7,33 +7,39 @@ import {motion,useDragControls,} from "framer-motion";-import type { Dispatch, ReactNode, SetStateAction } from "react";+import type { Dispatch, SetStateAction } from "react";import { useState } from "react";import useMeasure from "react-use-measure";import { Checkbox, cn } from "@carbon/react";import { LuTrash } from "react-icons/lu";-export type Item = {+interface Item {+ id: string;text: string;checked: boolean;- id: string;- description: string;-};+ order?: "With Previous" | "After Previous";+}-interface SortableListItemProps {- item: Item;+interface SortableItem<T> extends Item {+ data: T;+}++interface SortableListItemProps<T> {+ item: SortableItem<T>;+ items: SortableItem<T>[];order: number;onCompleteItem: (id: string) => void;onRemoveItem: (id: string) => void;- renderExtra?: (item: Item) => React.ReactNode;+ renderExtra?: (item: SortableItem<T>) => React.ReactNode;isExpanded?: boolean;className?: string;handleDrag: () => void;}-function SortableListItem({+function SortableListItem<T>({item,+ items,order,onCompleteItem,onRemoveItem,@@ -41,7 +47,7 @@ function SortableListItem({handleDrag,isExpanded,className,-}: SortableListItemProps) {+}: SortableListItemProps<T>) {let [ref, bounds] = useMeasure();const [isDragging, setIsDragging] = useState(false);const [isDraggable] = useState(true);@@ -134,7 +140,7 @@ function SortableListItem({/>{/* List Order */}<p className="font-mono text-xs pl-1 text-foreground/50 flex flex-shrink-0">- {order + 1}+ {getParallelizedOrder(order, item, items)}</p>{/* List Title */}@@ -247,38 +253,47 @@ function SortableListItem({SortableListItem.displayName = "SortableListItem";-interface SortableListProps {- items: Item[];- setItems: Dispatch<SetStateAction<Item[]>>;+export type SortableItemRenderProps<T extends Item> = {+ item: T;+ items: T[];+ order: number;+ onCompleteItem: (id: string) => void;+ onRemoveItem: (id: string) => void;+};++interface SortableListProps<T extends Item> {+ items: T[];onCompleteItem: (id: string) => void;- renderItem: (- item: Item,- order: number,- onCompleteItem: (id: string) => void,- onRemoveItem: (id: string) => void- ) => ReactNode;+ onRemoveItem: (id: string) => void;+ onReorder: Dispatch<SetStateAction<Item[]>>;+ renderItem: (props: SortableItemRenderProps<T>) => React.ReactNode;}-function SortableList({+function SortableList<T extends Item>({items,- setItems,+ onRemoveItem,onCompleteItem,+ onReorder,renderItem,-}: SortableListProps) {+}: SortableListProps<T>) {if (items) {return (<LayoutGroup><Reorder.Groupaxis="y"values={items}- onReorder={setItems}+ onReorder={onReorder}className="flex flex-col"><AnimatePresence>{items?.map((item, index) =>- renderItem(item, index, onCompleteItem, (id: string) =>- setItems((items) => items.filter((item) => item.id !== id))- )+ renderItem({+ item,+ items,+ order: index,+ onCompleteItem,+ onRemoveItem,+ }))}</AnimatePresence></Reorder.Group>@@ -291,3 +306,15 @@ function SortableList({SortableList.displayName = "SortableList";export { SortableList, SortableListItem };++function getParallelizedOrder(index: number, item: Item, items: Item[]) {+ if (item?.order !== "With Previous") return index + 1;+ // traverse backwards through the list of items to find the first item that is not "With Previous" and return its index + 1+ for (let i = index - 1; i >= 0; i--) {+ if (items[i].order !== "With Previous") {+ return i + 1;+ }+ }++ return 1;+}diff --git a/apps/carbon/app/modules/items/items.service.ts b/apps/carbon/app/modules/items/items.service.tsindex 7280ffc651..b8402af929 100644--- a/apps/carbon/app/modules/items/items.service.ts+++ b/apps/carbon/app/modules/items/items.service.ts@@ -288,6 +288,34 @@ export async function getItemReplenishment(.single();}+export async function getItemQuantities(+ client: SupabaseClient<Database>,+ itemId: string,+ companyId: string,+ locationId: string+) {+ return client+ .from("itemQuantities")+ .select("*")+ .eq("itemId", itemId)+ .eq("companyId", companyId)+ .eq("locationId", locationId)+ .maybeSingle();+}++export async function getItemUnitSalePrice(+ client: SupabaseClient<Database>,+ id: string,+ companyId: string+) {+ return client+ .from("itemUnitSalePrice")+ .select("*")+ .eq("itemId", id)+ .eq("companyId", companyId)+ .single();+}+export async function getMaterial(client: SupabaseClient<Database>,itemId: string,@@ -432,32 +460,24 @@ export async function getMaterialSubstancesList(.order("name");}-export async function getItemQuantities(+export async function getMethodMaterials(client: SupabaseClient<Database>,- itemId: string,- companyId: string,- locationId: string+ makeMethodId: string) {return client- .from("itemQuantities")+ .from("methodMaterial").select("*")- .eq("itemId", itemId)- .eq("companyId", companyId)- .eq("locationId", locationId)- .maybeSingle();+ .eq("makeMethodId", makeMethodId);}-export async function getItemUnitSalePrice(+export async function getMethodOperations(client: SupabaseClient<Database>,- id: string,- companyId: string+ makeMethodId: string) {return client- .from("itemUnitSalePrice")+ .from("methodOperation").select("*")- .eq("itemId", id)- .eq("companyId", companyId)- .single();+ .eq("makeMethodId", makeMethodId);}export async function getPart(diff --git a/apps/carbon/app/modules/items/types.ts b/apps/carbon/app/modules/items/types.tsindex 1d17515133..9a4d7ee5ee 100644--- a/apps/carbon/app/modules/items/types.ts+++ b/apps/carbon/app/modules/items/types.ts@@ -10,6 +10,8 @@ import type {getMaterialForms,getMaterialSubstances,getMaterials,+ getMethodMaterials,+ getMethodOperations,getPart,getParts,getPickMethods,@@ -68,8 +70,13 @@ export type Material = NonNullable<Awaited<ReturnType<typeof getMaterials>>["data"]>[number];-export type PartManufacturingPolicy =- Database["public"]["Enums"]["partManufacturingPolicy"];+export type MethodMaterial = NonNullable<+ Awaited<ReturnType<typeof getMethodMaterials>>["data"]+>[number];++export type MethodOperation = NonNullable<+ Awaited<ReturnType<typeof getMethodOperations>>["data"]+>[number];export type Part = NonNullable<Awaited<ReturnType<typeof getParts>>["data"]diff --git a/apps/carbon/app/modules/items/ui/Item/BillOfProcess.tsx b/apps/carbon/app/modules/items/ui/Item/BillOfProcess.tsxindex 05a60d753c..05d66c750a 100644--- a/apps/carbon/app/modules/items/ui/Item/BillOfProcess.tsx+++ b/apps/carbon/app/modules/items/ui/Item/BillOfProcess.tsx@@ -25,17 +25,9 @@ import {StandardFactor,WorkCellType,} from "~/components/Form";-import type { Item } from "~/components/SortableList";+import type { Item, SortableItemRenderProps } from "~/components/SortableList";import { SortableList, SortableListItem } from "~/components/SortableList";-// type Process = {-// workCenterTypeId: string;-// equipmentTypeId?: string;-// setupHours: number;-// standardFactor: StandardFactor;-// productionStandard: number;-// };-export const workInstructions = {type: "doc",content: [@@ -172,35 +164,37 @@ export const workInstructions = {],};+type ItemWithData = Item & {};+const initialState = [{id: "1",text: "Plasma Cut",checked: false,- description: "",+ order: "After Previous",},{id: "2",text: "Deburring",checked: false,- description: "",+ order: "With Previous",},{id: "3",text: "Brake Press",checked: false,- description: "",+ order: "After Previous",},{id: "5",text: "Paint",checked: false,- description: "",+ order: "After Previous",},];const BillOfProcess = () => {- const [items, setItems] = useState<Item[]>(initialState);+ const [items, setItems] = useState<ItemWithData[]>(initialState);const [openItemId, setOpenItemId] = useState<string | null>(null);const [tabChangeRerender, setTabChangeRerender] = useState<number>(1);@@ -219,7 +213,6 @@ const BillOfProcess = () => {text: `Item ${prevItems.length + 1}`,checked: false,id: Math.random().toString(16).slice(2),- description: "",},]);};@@ -237,12 +230,13 @@ const BillOfProcess = () => {});}, []);- const renderListItem = (- item: Item,- order: number,- onCompleteItem: (id: string) => void,- onRemoveItem: (id: string) => void- ) => {+ const renderListItem = ({+ item,+ items,+ order,+ onCompleteItem,+ onRemoveItem,+ }: SortableItemRenderProps<ItemWithData>) => {const isOpen = item.id === openItemId;const tabs = [@@ -341,8 +335,9 @@ const BillOfProcess = () => {];return (- <SortableListItem+ <SortableListItem<ItemWithData>item={item}+ items={items}order={order}key={item.id}isExpanded={isOpen}@@ -470,15 +465,18 @@ const BillOfProcess = () => {<CardAction><Button variant="secondary" onClick={onAddItem}>- Add Process+ Add Operation</Button></CardAction></HStack><CardContent><SortableListitems={items}- setItems={setItems}+ onReorder={setItems}onCompleteItem={onCompleteItem}+ onRemoveItem={(id) =>+ setItems((prevItems) => prevItems.filter((item) => item.id !== id))+ }renderItem={renderListItem}/></CardContent>diff --git a/apps/carbon/app/modules/items/ui/MaterialForms/MaterialShapesTable.tsx b/apps/carbon/app/modules/items/ui/MaterialForms/MaterialShapesTable.tsxindex 3f65904eaa..5025407168 100644--- a/apps/carbon/app/modules/items/ui/MaterialForms/MaterialShapesTable.tsx+++ b/apps/carbon/app/modules/items/ui/MaterialForms/MaterialShapesTable.tsx@@ -28,15 +28,18 @@ const MaterialShapesTable = memo({accessorKey: "name",header: "Name",- cell: ({ row }) => (- <Hyperlink- to={`${path.to.materialForm(- row.original.id- )}?${params.toString()}`}- >- {row.original.name}- </Hyperlink>- ),+ cell: ({ row }) =>+ row.original.companyId === null ? (+ row.original.name+ ) : (+ <Hyperlink+ to={`${path.to.materialForm(+ row.original.id+ )}?${params.toString()}`}+ >+ {row.original.name}+ </Hyperlink>+ ),},{header: "Type",diff --git a/apps/carbon/app/modules/items/ui/MaterialSubstances/MaterialSubstanceTable.tsx b/apps/carbon/app/modules/items/ui/MaterialSubstances/MaterialSubstanceTable.tsxindex 0bcc0dd451..bfb93dfbad 100644--- a/apps/carbon/app/modules/items/ui/MaterialSubstances/MaterialSubstanceTable.tsx+++ b/apps/carbon/app/modules/items/ui/MaterialSubstances/MaterialSubstanceTable.tsx@@ -28,15 +28,18 @@ const MaterialSubstancesTable = memo({accessorKey: "name",header: "Name",- cell: ({ row }) => (- <Hyperlink- to={`${path.to.materialSubstance(- row.original.id- )}?${params.toString()}`}- >- {row.original.name}- </Hyperlink>- ),+ cell: ({ row }) =>+ row.original.companyId === null ? (+ row.original.name+ ) : (+ <Hyperlink+ to={`${path.to.materialSubstance(+ row.original.id+ )}?${params.toString()}`}+ >+ {row.original.name}+ </Hyperlink>+ ),},{header: "Type",diff --git a/apps/carbon/app/routes/x+/items+/forms.$formId.tsx b/apps/carbon/app/routes/x+/items+/forms.$formId.tsxindex 62c2ca34e6..f58dad662b 100644--- a/apps/carbon/app/routes/x+/items+/forms.$formId.tsx+++ b/apps/carbon/app/routes/x+/items+/forms.$formId.tsx@@ -26,6 +26,16 @@ export async function loader({ request, params }: LoaderFunctionArgs) {const materialForm = await getMaterialForm(client, formId);+ if (materialForm.data?.companyId === null) {+ throw redirect(+ path.to.materialForms,+ await flash(+ request,+ error(new Error("Access Denied"), "Cannot edit global material shape")+ )+ );+ }+return json({materialForm: materialForm?.data ?? null,});diff --git a/apps/carbon/app/routes/x+/items+/substances.$substanceId.tsx b/apps/carbon/app/routes/x+/items+/substances.$substanceId.tsxindex 3621672957..236c9ded91 100644--- a/apps/carbon/app/routes/x+/items+/substances.$substanceId.tsx+++ b/apps/carbon/app/routes/x+/items+/substances.$substanceId.tsx@@ -26,6 +26,19 @@ export async function loader({ request, params }: LoaderFunctionArgs) {const materialSubstance = await getMaterialSubstance(client, substanceId);+ if (materialSubstance.data?.companyId === null) {+ throw redirect(+ path.to.materialSubstances,+ await flash(+ request,+ error(+ new Error("Access denied"),+ "Cannot edit global material substance"+ )+ )+ );+ }+return json({materialSubstance: materialSubstance?.data ?? null,});