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: add create from dropdown for parts
Brad Barbin69b63c034b3c
diff --git a/apps/carbon/app/components/Form/Part.tsx b/apps/carbon/app/components/Form/Part.tsxindex 41e0f442e5..4a675815ee 100644--- a/apps/carbon/app/components/Form/Part.tsx+++ b/apps/carbon/app/components/Form/Part.tsx@@ -1,8 +1,9 @@-import { useMemo } from "react";-import type { PartReplenishmentSystem } from "~/modules/parts";+import { useDisclosure } from "@carbon/react";+import { useMemo, useState } from "react";+import { PartForm, type PartReplenishmentSystem } from "~/modules/parts";import { useParts } from "~/stores";import type { ComboboxProps } from "./Combobox";-import Combobox from "./Combobox";+import CreatableCombobox from "./CreatableCombobox";type PartSelectProps = Omit<ComboboxProps, "options"> & {partReplenishmentSystem?: PartReplenishmentSystem;@@ -10,15 +11,17 @@ type PartSelectProps = Omit<ComboboxProps, "options"> & {const Part = ({ partReplenishmentSystem, ...props }: PartSelectProps) => {const [parts] = useParts();+ const newPartsModal = useDisclosure();+ const [createdPart, setCreatedPart] = useState<string>("");const options = useMemo(() =>parts.filter((part) => {if (partReplenishmentSystem === "Buy") {- return ["Buy", "Buy and Make"].includes(partReplenishmentSystem);+ return ["Buy", "Buy and Make"].includes(part.replenishmentSystem);} else if (partReplenishmentSystem === "Make") {- return ["Make", "Buy and Make"].includes(partReplenishmentSystem);+ return ["Make", "Buy and Make"].includes(part.replenishmentSystem);} else {return true;}@@ -31,7 +34,36 @@ const Part = ({ partReplenishmentSystem, ...props }: PartSelectProps) => {);return (- <Combobox options={options} {...props} label={props?.label ?? "Part"} />+ <>+ <CreatableCombobox+ options={options}+ {...props}+ label={props?.label ?? "Part"}+ onCreateOption={(option) => {+ newPartsModal.onOpen();+ setCreatedPart(option);+ }}+ />+ {newPartsModal.isOpen && (+ <PartForm+ type="modal"+ onClose={() => {+ setCreatedPart("");+ newPartsModal.onClose();+ }}+ initialValues={{+ id: "",+ name: createdPart,+ description: "",+ partType: "Inventory" as "Inventory",+ replenishmentSystem: "Buy" as "Buy",+ unitOfMeasureCode: "EA",+ blocked: false,+ active: false,+ }}+ />+ )}+ </>);};diff --git a/apps/carbon/app/modules/parts/ui/Part/PartForm.tsx b/apps/carbon/app/modules/parts/ui/Part/PartForm.tsxindex 11ebab8149..1cfaa0cfde 100644--- a/apps/carbon/app/modules/parts/ui/Part/PartForm.tsx+++ b/apps/carbon/app/modules/parts/ui/Part/PartForm.tsx@@ -1,10 +1,12 @@import {- Card,- CardContent,- CardDescription,- CardFooter,- CardHeader,- CardTitle,+ ModalCard,+ ModalCardBody,+ ModalCardContent,+ ModalCardDescription,+ ModalCardFooter,+ ModalCardHeader,+ ModalCardProvider,+ ModalCardTitle,VStack,cn,} from "@carbon/react";@@ -32,6 +34,8 @@ import { path } from "~/utils/path";type PartFormProps = {initialValues: TypeOfValidator<typeof partValidator>;+ type?: "card" | "modal";+ onClose?: () => void;};const useNextPartIdShortcut = () => {@@ -79,7 +83,7 @@ const useNextPartIdShortcut = () => {return { partId, onPartIdChange, loading };};-const PartForm = ({ initialValues }: PartFormProps) => {+const PartForm = ({ initialValues, type = "card", onClose }: PartFormProps) => {const sharedPartsData = useRouteData<{partGroups: PartGroupListItem[];unitOfMeasures: UnitOfMeasureListItem[];@@ -114,86 +118,94 @@ const PartForm = ({ initialValues }: PartFormProps) => {})) ?? [];return (- <ValidatedForm- method="post"- validator={partValidator}- defaultValues={initialValues}- >- <Card>- <CardHeader>- <CardTitle>{isEditing ? "Part Details" : "New Part"}</CardTitle>- {!isEditing && (- <CardDescription>- A part contains the information about a specific item that can be- purchased or manufactured.- </CardDescription>- )}- </CardHeader>- <CardContent>- <div- className={cn(- "grid w-full gap-x-8 gap-y-2",- isEditing ? "grid-cols-1 md:grid-cols-3" : "grid-cols-1"- )}+ <ModalCardProvider type={type}>+ <ModalCard onClose={onClose}>+ <ModalCardContent>+ <ValidatedForm+ action={isEditing ? undefined : path.to.newPart}+ method="post"+ validator={partValidator}+ defaultValues={initialValues}+ onSubmit={onClose}>- <VStack>- {isEditing ? (- <Input name="id" label="Part ID" isReadOnly />- ) : (- <InputControlled- name="id"- label="Part ID"- helperText="Use ... to get the next part ID"- value={partId}- onChange={onPartIdChange}- isDisabled={loading}- />+ <ModalCardHeader>+ <ModalCardTitle>+ {isEditing ? "Part Details" : "New Part"}+ </ModalCardTitle>+ {!isEditing && (+ <ModalCardDescription>+ A part contains the information about a specific item that can+ be purchased or manufactured.+ </ModalCardDescription>)}+ </ModalCardHeader>+ <ModalCardBody>+ <div+ className={cn(+ "grid w-full gap-x-8 gap-y-2",+ isEditing ? "grid-cols-1 md:grid-cols-3" : "grid-cols-1"+ )}+ >+ <VStack>+ {isEditing ? (+ <Input name="id" label="Part ID" isReadOnly />+ ) : (+ <InputControlled+ name="id"+ label="Part ID"+ helperText="Use ... to get the next part ID"+ value={partId}+ onChange={onPartIdChange}+ isDisabled={loading}+ />+ )}- <Input name="name" label="Name" />- <TextArea name="description" label="Description" />- </VStack>- <VStack>- <Select- name="replenishmentSystem"- label="Replenishment System"- options={partReplenishmentSystemOptions}- />- <Select- name="partType"- label="Part Type"- options={partTypeOptions}- />- <Combobox- name="unitOfMeasureCode"- label="Unit of Measure"- options={unitOfMeasureOptions}- />- </VStack>- <VStack>- <Combobox- name="partGroupId"- label="Part Group"- options={partGroupOptions}- />- <Boolean name="blocked" label="Blocked" />- {isEditing && <Boolean name="active" label="Active" />}- </VStack>- </div>- </CardContent>- <CardFooter>- <Submit- isDisabled={- isEditing- ? !permissions.can("update", "parts")- : !permissions.can("create", "parts")- }- >- Save- </Submit>- </CardFooter>- </Card>- </ValidatedForm>+ <Input name="name" label="Name" />+ <TextArea name="description" label="Description" />+ </VStack>+ <VStack>+ <Select+ name="replenishmentSystem"+ label="Replenishment System"+ options={partReplenishmentSystemOptions}+ />+ <Select+ name="partType"+ label="Part Type"+ options={partTypeOptions}+ />+ <Combobox+ name="unitOfMeasureCode"+ label="Unit of Measure"+ options={unitOfMeasureOptions}+ />+ </VStack>+ <VStack>+ <Combobox+ name="partGroupId"+ label="Part Group"+ options={partGroupOptions}+ />+ <Boolean name="blocked" label="Blocked" />+ {isEditing && <Boolean name="active" label="Active" />}+ </VStack>+ </div>+ </ModalCardBody>+ <ModalCardFooter>+ <Submit+ isDisabled={+ isEditing+ ? !permissions.can("update", "parts")+ : !permissions.can("create", "parts")+ }+ >+ Save+ </Submit>+ </ModalCardFooter>+ </ValidatedForm>+ </ModalCardContent>+ </ModalCard>+ </ModalCardProvider>);};diff --git a/apps/carbon/app/modules/sales/sales.models.ts b/apps/carbon/app/modules/sales/sales.models.tsindex a41c4dd6a8..dbde21873b 100644--- a/apps/carbon/app/modules/sales/sales.models.ts+++ b/apps/carbon/app/modules/sales/sales.models.ts@@ -60,6 +60,12 @@ export const customerTypeValidator = withZod(}));+export const quoteLineStatusType = [+ "Draft",+ "In Progress",+ "Complete",+] as const;+export const quoteStatusType = ["Draft","Open",@@ -103,7 +109,7 @@ export const quotationAssemblyValidator = withZod(export const quotationOperationValidator = withZod(z.object({id: zfd.text(z.string().optional()),- quoteAssemblyId: z.string().min(20, { message: "Assembly is required" }),+ quoteAssemblyId: zfd.text(z.string().optional()),workCellTypeId: z.string().min(20, { message: "Work cell is required" }),equipmentTypeId: zfd.text(z.string().optional()),description: zfd.text(z.string().optional()),diff --git a/packages/database/src/types.ts b/packages/database/src/types.tsindex 9171447e4d..7cf0f2c337 100644--- a/packages/database/src/types.ts+++ b/packages/database/src/types.ts@@ -7039,6 +7039,7 @@ export interface Database {quoteId: string;quoteRevisionId: number;replenishmentSystem: string | null;+ status: Database["public"]["Enums"]["quoteLineStatus"];unitOfMeasureCode: string | null;updatedAt: string | null;updatedBy: string | null;@@ -7053,6 +7054,7 @@ export interface Database {quoteId: string;quoteRevisionId?: number;replenishmentSystem?: string | null;+ status?: Database["public"]["Enums"]["quoteLineStatus"];unitOfMeasureCode?: string | null;updatedAt?: string | null;updatedBy?: string | null;@@ -7067,6 +7069,7 @@ export interface Database {quoteId?: string;quoteRevisionId?: number;replenishmentSystem?: string | null;+ status?: Database["public"]["Enums"]["quoteLineStatus"];unitOfMeasureCode?: string | null;updatedAt?: string | null;updatedBy?: string | null;@@ -7389,7 +7392,7 @@ export interface Database {laborRate: number;overheadRate: number;productionStandard: number;- quoteAssemblyId: string;+ quoteAssemblyId: string | null;quoteId: string;quoteLineId: string;quotingRate: number;@@ -7408,7 +7411,7 @@ export interface Database {laborRate?: number;overheadRate?: number;productionStandard?: number;- quoteAssemblyId: string;+ quoteAssemblyId?: string | null;quoteId: string;quoteLineId: string;quotingRate?: number;@@ -7427,7 +7430,7 @@ export interface Database {laborRate?: number;overheadRate?: number;productionStandard?: number;- quoteAssemblyId?: string;+ quoteAssemblyId?: string | null;quoteId?: string;quoteLineId?: string;quotingRate?: number;@@ -11999,6 +12002,7 @@ export interface Database {| "Reject"| "Request Approval";purchaseOrderType: "Purchase" | "Return";+ quoteLineStatus: "Draft" | "In Progress" | "Complete";quoteStatus:| "Draft"| "Open"diff --git a/packages/database/supabase/migrations/20240206224405_quotes.sql b/packages/database/supabase/migrations/20240206224405_quotes.sqlindex 9965fdb02c..7bc4458558 100644--- a/packages/database/supabase/migrations/20240206224405_quotes.sql+++ b/packages/database/supabase/migrations/20240206224405_quotes.sql@@ -42,10 +42,22 @@ CREATE TABLE "quote" (CONSTRAINT "quote_updatedBy_fkey" FOREIGN KEY ("updatedBy") REFERENCES "user" ("id") ON DELETE RESTRICT ON UPDATE CASCADE);+CREATE INDEX "quote_quoteId_idx" ON "quote" ("quoteId");+CREATE INDEX "quote_ownerId_idx" ON "quote" ("ownerId");+CREATE INDEX "quote_customerId_idx" ON "quote" ("customerId");+CREATE INDEX "quote_locationId_idx" ON "quote" ("locationId");++CREATE TYPE "quoteLineStatus" AS ENUM (+ 'Draft',+ 'In Progress',+ 'Complete'+);+CREATE TABLE "quoteLine" ("id" TEXT NOT NULL DEFAULT xid(),"quoteId" TEXT NOT NULL,"quoteRevisionId" INTEGER NOT NULL DEFAULT 0,+ "status" "quoteLineStatus" NOT NULL DEFAULT 'Draft',"partId" TEXT NOT NULL,"description" TEXT NOT NULL,"customerPartId" TEXT,@@ -126,7 +138,7 @@ CREATE TABLE "quoteOperation" ("id" TEXT NOT NULL DEFAULT xid(),"quoteId" TEXT NOT NULL,"quoteLineId" TEXT NOT NULL,- "quoteAssemblyId" TEXT NOT NULL,+ "quoteAssemblyId" TEXT,"workCellTypeId" TEXT NOT NULL,"equipmentTypeId" TEXT,"description" TEXT,diff --git a/packages/react/src/ModalCard.tsx b/packages/react/src/ModalCard.tsxnew file mode 100644index 0000000000..f9c6938f5f--- /dev/null+++ b/packages/react/src/ModalCard.tsx@@ -0,0 +1,175 @@+/*+ ModalCard components are an abstraction over Card and Modal components.+*/+import type {+ ComponentPropsWithoutRef,+ ElementRef,+ PropsWithChildren,+} from "react";+import { createContext, forwardRef, useContext } from "react";+import {+ Card,+ CardContent,+ CardDescription,+ CardFooter,+ CardHeader,+ CardTitle,+} from "./Card";++import {+ Modal,+ ModalBody,+ ModalContent,+ ModalDescription,+ ModalFooter,+ ModalHeader,+ ModalTitle,+} from "./Modal";++const ModalCardTypeContext = createContext<"card" | "modal">("card");+const ModalCardTypeProvider = ModalCardTypeContext.Provider;++const ModalCardProvider = ({+ type = "card",+ ...props+}: PropsWithChildren<{+ type?: "card" | "modal";+}>) => <ModalCardTypeProvider value={type} {...props} />;++const useModalCardType = () => {+ const type = useContext(ModalCardTypeContext);+ return type;+};++const ModalCard = forwardRef<+ ElementRef<typeof Modal> | ElementRef<typeof Card>,+ | (ComponentPropsWithoutRef<typeof Modal> & {+ onClose?: () => void;+ })+ | (ComponentPropsWithoutRef<typeof Card> & {+ onClose?: () => void;+ })+>(({ onClose, ...props }, ref) => {+ const type = useModalCardType();++ if (type === "card") {+ return <Card {...props} ref={ref} />;+ }++ return (+ <Modal+ {...props}+ onOpenChange={(open) => {+ if (!open) {+ onClose?.();+ }+ }}+ open+ />+ );+});+ModalCard.displayName = "ModalCard";++const ModalCardBody = forwardRef<+ ElementRef<typeof ModalBody> | ElementRef<typeof CardContent>,+ | ComponentPropsWithoutRef<typeof ModalBody>+ | ComponentPropsWithoutRef<typeof CardContent>+>((props, ref) => {+ const type = useModalCardType();++ if (type === "card") {+ return <CardContent {...props} ref={ref} />;+ }++ return <ModalBody {...props} />;+});+ModalCardBody.displayName = "ModalCardBody";++const ModalCardContent = forwardRef<+ ElementRef<typeof ModalContent> | ElementRef<"div">,+ | ComponentPropsWithoutRef<typeof ModalContent>+ | ComponentPropsWithoutRef<"div">+>((props, ref) => {+ const type = useModalCardType();++ if (type === "card") {+ return <div {...props} ref={ref} />;+ }++ return <ModalContent {...props} ref={ref} />;+});+ModalCardContent.displayName = "ModalCardContent";++const ModalCardDescription = forwardRef<+ ElementRef<typeof ModalDescription> | ElementRef<typeof CardDescription>,+ | ComponentPropsWithoutRef<typeof ModalDescription>+ | ComponentPropsWithoutRef<typeof CardDescription>+>((props, ref) => {+ const type = useModalCardType();++ if (type === "card") {+ return <CardDescription {...props} ref={ref} />;+ }++ return <ModalDescription {...props} ref={ref} />;+});+ModalCardDescription.displayName = "ModalCardDescription";++const ModalCardFooter = forwardRef<+ ElementRef<typeof ModalFooter> | ElementRef<typeof CardFooter>,+ | ComponentPropsWithoutRef<typeof ModalFooter>+ | ComponentPropsWithoutRef<typeof CardFooter>+>((props, ref) => {+ const type = useModalCardType();++ if (type === "card") {+ return <CardFooter {...props} ref={ref} />;+ }++ return <ModalFooter {...props} />;+});+ModalCardFooter.displayName = "ModalCardFooter";++const ModalCardHeader = forwardRef<+ ElementRef<typeof ModalHeader> | ElementRef<typeof CardHeader>,+ | ComponentPropsWithoutRef<typeof ModalHeader>+ | ComponentPropsWithoutRef<typeof CardHeader>+>((props, ref) => {+ const type = useModalCardType();++ if (type === "card") {+ return <CardHeader {...props} ref={ref} />;+ }++ return <ModalHeader {...props} />;+});+ModalCardHeader.displayName = "ModalCardHeader";++const ModalCardTitle = forwardRef<+ ElementRef<typeof ModalTitle> | ElementRef<typeof CardTitle>,+ | ComponentPropsWithoutRef<typeof ModalTitle>+ | ComponentPropsWithoutRef<typeof CardTitle>+>((props, ref) => {+ const type = useModalCardType();++ if (type === "card") {+ return <CardTitle {...props} ref={ref} />;+ }++ return <ModalTitle {...props} ref={ref} />;+});+ModalCardTitle.displayName = "ModalCardTitle";++export {+ ModalCard,+ ModalCardBody,+ ModalCardContent,+ ModalCardDescription,+ ModalCardFooter,+ ModalCardHeader,+ ModalCardProvider,+ ModalCardTitle,+ ModalCardTypeContext,+ ModalCardTypeProvider,+ useModalCardType,+};diff --git a/packages/react/src/index.tsx b/packages/react/src/index.tsxindex 0e850f36d4..2e92414da4 100644--- a/packages/react/src/index.tsx+++ b/packages/react/src/index.tsx@@ -145,6 +145,19 @@ import {ModalTitle,ModalTrigger,} from "./Modal";+import {+ ModalCard,+ ModalCardBody,+ ModalCardContent,+ ModalCardDescription,+ ModalCardFooter,+ ModalCardHeader,+ ModalCardProvider,+ ModalCardTitle,+ ModalCardTypeContext,+ ModalCardTypeProvider,+ useModalCardType,+} from "./ModalCard";import type { NumberFieldProps } from "./Number";import {NumberDecrementStepper,@@ -322,6 +335,16 @@ export {MenubarItem,Modal,ModalBody,+ ModalCard,+ ModalCardBody,+ ModalCardContent,+ ModalCardDescription,+ ModalCardFooter,+ ModalCardHeader,+ ModalCardProvider,+ ModalCardTitle,+ ModalCardTypeContext,+ ModalCardTypeProvider,ModalClose,ModalContent,ModalDescription,@@ -389,6 +412,7 @@ export {useHydrated,useInterval,useKeyboardShortcuts,+ useModalCardType,useMount,useOutsideClick,};diff --git a/packages/utils/src/themes.ts b/packages/utils/src/themes.tsindex a606683d4f..87f529726d 100644--- a/packages/utils/src/themes.ts+++ b/packages/utils/src/themes.ts@@ -5,51 +5,51 @@ export const themes = [name: "zinc",label: "Carbon",activeColor: {- light: "240 5.9% 10%",- dark: "240 5.2% 33.9%",+ light: "220 5.9% 10%",+ dark: "220 5.2% 33.9%",},cssVars: {light: {background: "0 0% 100%",- foreground: "240 10% 3.9%",+ foreground: "220 10% 3.9%",card: "0 0% 100%",- "card-foreground": "240 10% 3.9%",+ "card-foreground": "220 10% 3.9%",popover: "0 0% 100%",- "popover-foreground": "240 10% 3.9%",- primary: "240 5.9% 10%",+ "popover-foreground": "220 10% 3.9%",+ primary: "220 5.9% 10%","primary-foreground": "0 0% 98%",- secondary: "240 4.8% 95.9%",- "secondary-foreground": "240 5.9% 10%",- muted: "240 4.8% 95.9%",- "muted-foreground": "240 3.8% 46.1%",- accent: "240 4.8% 95.9%",- "accent-foreground": "240 5.9% 10%",+ secondary: "220 4.8% 95.9%",+ "secondary-foreground": "220 5.9% 10%",+ muted: "220 4.8% 95.9%",+ "muted-foreground": "220 3.8% 46.1%",+ accent: "220 4.8% 95.9%",+ "accent-foreground": "220 5.9% 10%",destructive: "0 84.2% 60.2%","destructive-foreground": "0 0% 98%",- border: "240 5.9% 90%",- input: "240 5.9% 90%",- ring: "240 5.9% 10%",+ border: "220 5.9% 90%",+ input: "220 5.9% 90%",+ ring: "220 5.9% 10%",},dark: {background: "220 10% 6.9%",foreground: "0 0% 98%",- card: "240 10% 8.9%",+ card: "220 10% 8.9%","card-foreground": "0 0% 98%",- popover: "240 10% 8.9%",+ popover: "220 10% 8.9%","popover-foreground": "0 0% 98%",primary: "0 0% 98%",- "primary-foreground": "240 5.9% 10%",- secondary: "240 3.7% 15.9%",+ "primary-foreground": "220 5.9% 10%",+ secondary: "220 3.7% 15.9%","secondary-foreground": "0 0% 98%",- muted: "240 3.7% 15.9%",- "muted-foreground": "240 5% 64.9%",- accent: "240 3.7% 15.9%",+ muted: "220 3.7% 15.9%",+ "muted-foreground": "220 5% 64.9%",+ accent: "220 3.7% 15.9%","accent-foreground": "0 0% 98%",destructive: "0 62.8% 30.6%","destructive-foreground": "0 0% 98%",- border: "240 3.7% 15.9%",- input: "240 3.7% 15.9%",- ring: "240 4.9% 83.9%",+ border: "220 3.7% 15.9%",+ input: "220 3.7% 15.9%",+ ring: "220 4.9% 83.9%",},},},