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: non-conformance properties
Brad Barbin3819519fc328
diff --git a/apps/erp/app/modules/quality/ui/NonConformance/NonConformanceForm.tsx b/apps/erp/app/modules/quality/ui/NonConformance/NonConformanceForm.tsxindex 19e1869ccc..8d4c11ee9a 100644--- a/apps/erp/app/modules/quality/ui/NonConformance/NonConformanceForm.tsx+++ b/apps/erp/app/modules/quality/ui/NonConformance/NonConformanceForm.tsx@@ -26,6 +26,7 @@ import {Submit,} from "~/components/Form";import { usePermissions } from "~/hooks";+import type { MethodItemType } from "~/modules/shared";import type { ListItem } from "~/types";import {nonConformanceApprovalRequirement,@@ -68,6 +69,8 @@ const NonConformanceForm = ({approvalRequirements: initialValues.approvalRequirements ?? [],});+ const [itemType, setItemType] = useState<string>("Item");+const onWorkflowChange = (value: { value: string } | null) => {if (value) {const selectedWorkflow = nonConformanceWorkflows.find(@@ -121,7 +124,14 @@ const NonConformanceForm = ({<VStack spacing={4}><div className="grid w-full gap-4 grid-cols-1 md:grid-cols-2"><Input name="name" label="Name" />- <Item name="itemId" label="Item" type="Item" />+ <Item+ name="itemId"+ label="Item"+ type={itemType as MethodItemType}+ onTypeChange={(value) => {+ setItemType(value as string);+ }}+ /></div><TextArea name="description" label="Description" /><div className="grid w-full gap-4 grid-cols-1 md:grid-cols-2">diff --git a/apps/erp/app/modules/quality/ui/NonConformance/NonConformanceProperties.tsx b/apps/erp/app/modules/quality/ui/NonConformance/NonConformanceProperties.tsxindex b988cbddfb..34dafef55d 100644--- a/apps/erp/app/modules/quality/ui/NonConformance/NonConformanceProperties.tsx+++ b/apps/erp/app/modules/quality/ui/NonConformance/NonConformanceProperties.tsx@@ -1,5 +1,11 @@import type { Json } from "@carbon/database";-import { DatePicker, InputControlled, ValidatedForm } from "@carbon/form";+import {+ DatePicker,+ InputControlled,+ MultiSelect,+ Select,+ ValidatedForm,+} from "@carbon/form";import {Button,HStack,@@ -14,14 +20,22 @@ import { useCallback, useEffect } from "react";import { LuCopy, LuKeySquare, LuLink } from "react-icons/lu";import { z } from "zod";import { Assignee, useOptimisticAssignment } from "~/components";+import { Enumerable } from "~/components/Enumerable";import { Tags } from "~/components/Form";import CustomFormInlineFields from "~/components/Form/CustomFormInlineFields";import { usePermissions, useRouteData } from "~/hooks";import type { action } from "~/routes/x+/items+/update";-import type { StorageItem } from "~/types";+import type { ListItem, StorageItem } from "~/types";import { path } from "~/utils/path";import { copyToClipboard } from "~/utils/string";+import {+ nonConformanceApprovalRequirement,+ nonConformanceInvestigationType,+ nonConformanceRequiredAction,+ nonConformanceSource,+} from "../../quality.models";import type { NonConformance } from "../../types";+import { getSourceIcon } from "./NonConformanceIcons";const NonConformanceProperties = () => {const { id } = useParams();@@ -31,6 +45,7 @@ const NonConformanceProperties = () => {const routeData = useRouteData<{nonConformance: NonConformance;+ nonConformanceTypes: ListItem[];files: Promise<StorageItem[]>;tags: { name: string }[];}>(path.to.nonConformance(id));@@ -122,6 +137,8 @@ const NonConformanceProperties = () => {[id]);+ const disableStructureUpdate = !permissions.can("delete", "quality");+return (<VStackspacing={4}@@ -210,8 +227,8 @@ const NonConformanceProperties = () => {<InputControlledlabel=""name="name"- inlinesize="sm"+ inlinevalue={routeData?.nonConformance?.name ?? ""}onBlur={(e) => {onUpdate("name", e.target.value ?? null);@@ -234,6 +251,157 @@ const NonConformanceProperties = () => {/></VStack>+ <ValidatedForm+ defaultValues={{+ nonConformanceTypeId:+ routeData?.nonConformance?.nonConformanceTypeId ?? "",+ }}+ validator={z.object({+ nonConformanceTypeId: z.string().optional(),+ })}+ className="w-full"+ >+ <Select+ options={(routeData?.nonConformanceTypes ?? []).map((type) => ({+ value: type.id,+ label: <Enumerable value={type.name} />,+ }))}+ isReadOnly={disableStructureUpdate}+ label="Non-conformance Type"+ name="nonConformanceTypeId"+ inline={(value, options) => {+ return (+ <Enumerable+ value={+ routeData?.nonConformanceTypes.find((t) => t.id === value)+ ?.name ?? null+ }+ />+ );+ }}+ onChange={(value) => {+ if (value) {+ onUpdate("source", value.value);+ }+ }}+ />+ </ValidatedForm>++ <ValidatedForm+ defaultValues={{+ source: routeData?.nonConformance?.source ?? "",+ }}+ validator={z.object({+ source: z.string().optional(),+ })}+ className="w-full"+ >+ <Select+ options={nonConformanceSource.map((source) => ({+ value: source,+ label: (+ <div className="flex gap-2 items-center">+ {getSourceIcon(source, false)}+ <span>{source}</span>+ </div>+ ),+ }))}+ isReadOnly={disableStructureUpdate}+ label="Source"+ name="source"+ inline={(value, options) => {+ return (+ <div className="flex gap-2 items-center">+ {getSourceIcon(value as "External" | "Internal", false)}+ <span>{value}</span>+ </div>+ );+ }}+ onChange={(value) => {+ if (value) {+ onUpdate("source", value.value);+ }+ }}+ />+ </ValidatedForm>++ <ValidatedForm+ defaultValues={{+ investigationTypes:+ routeData?.nonConformance?.investigationTypes ?? [],+ }}+ validator={z.object({+ investigationTypes: z.array(z.string()).optional(),+ })}+ className="w-full"+ >+ <MultiSelect+ options={nonConformanceInvestigationType.map((type) => ({+ value: type,+ label: type,+ }))}+ isReadOnly={disableStructureUpdate}+ label="Investigation Types"+ name="investigationTypes"+ inline+ onChange={(value) => {+ onUpdate("investigationTypes", value.map((v) => v.value).join(","));+ }}+ />+ </ValidatedForm>++ <ValidatedForm+ defaultValues={{+ requiredActions: routeData?.nonConformance?.requiredActions ?? [],+ }}+ validator={z.object({+ requiredActions: z.array(z.string()).optional(),+ })}+ className="w-full"+ >+ <MultiSelect+ options={nonConformanceRequiredAction.map((type) => ({+ value: type,+ label: type,+ }))}+ isReadOnly={disableStructureUpdate}+ label="Required Actions"+ name="requiredActions"+ inline+ onChange={(value) => {+ onUpdate("requiredActions", value.map((v) => v.value).join(","));+ }}+ />+ </ValidatedForm>++ <ValidatedForm+ defaultValues={{+ approvalRequirements:+ routeData?.nonConformance?.approvalRequirements ?? [],+ }}+ validator={z.object({+ approvalRequirements: z.array(z.string()).optional(),+ })}+ className="w-full"+ >+ <MultiSelect+ options={nonConformanceApprovalRequirement.map((type) => ({+ value: type,+ label: type,+ }))}+ isReadOnly={disableStructureUpdate}+ label="Approval Requirements"+ name="approvalRequirements"+ inline+ onChange={(value) => {+ onUpdate(+ "approvalRequirements",+ value.map((v) => v.value).join(",")+ );+ }}+ />+ </ValidatedForm>+<ValidatedFormdefaultValues={{openDate: routeData?.nonConformance?.openDate ?? "",diff --git a/apps/erp/app/routes/x+/non-conformance+/$id.tsx b/apps/erp/app/routes/x+/non-conformance+/$id.tsxindex c242c662d1..d6c0ad7c8d 100644--- a/apps/erp/app/routes/x+/non-conformance+/$id.tsx+++ b/apps/erp/app/routes/x+/non-conformance+/$id.tsx@@ -5,7 +5,10 @@ import { Outlet } from "@remix-run/react";import type { LoaderFunctionArgs } from "@vercel/remix";import { defer, redirect } from "@vercel/remix";import { getItemFiles } from "~/modules/items";-import { getNonConformance } from "~/modules/quality";+import {+ getNonConformance,+ getNonConformanceTypesList,+} from "~/modules/quality";import NonConformanceHeader from "~/modules/quality/ui/NonConformance/NonConformanceHeader";import NonConformanceProperties from "~/modules/quality/ui/NonConformance/NonConformanceProperties";import { getTagsList } from "~/modules/shared";@@ -14,8 +17,8 @@ import { path } from "~/utils/path";export const handle: Handle = {breadcrumb: "Non-Conformances",- to: path.to.parts,- module: "items",+ to: path.to.nonConformances,+ module: "quality",};export async function loader({ request, params }: LoaderFunctionArgs) {@@ -27,8 +30,9 @@ export async function loader({ request, params }: LoaderFunctionArgs) {const { id } = params;if (!id) throw new Error("Could not find id");- const [nonConformance, tags] = await Promise.all([+ const [nonConformance, nonConformanceTypes, tags] = await Promise.all([getNonConformance(client, id),+ getNonConformanceTypesList(client, companyId),getTagsList(client, companyId, "nonConformance"),]);@@ -44,6 +48,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {return defer({nonConformance: nonConformance.data,+ nonConformanceTypes: nonConformanceTypes.data ?? [],files: getItemFiles(client, id, companyId),tags: tags.data ?? [],});diff --git a/apps/erp/app/routes/x+/non-conformance+/update.tsx b/apps/erp/app/routes/x+/non-conformance+/update.tsxindex 4ce998b240..8f2a5ca262 100644--- a/apps/erp/app/routes/x+/non-conformance+/update.tsx+++ b/apps/erp/app/routes/x+/non-conformance+/update.tsx@@ -27,16 +27,19 @@ export async function action({ request }: ActionFunctionArgs) {case "investigationTypes":case "requiredActions":case "approvalRequirements":+ console.log(value);+ const arrayValue = value ? value.split(",") : [];const update = await client.from("nonConformance").update({- [field]: value ? value : null,+ [field]: arrayValue,updatedBy: userId,updatedAt: new Date().toISOString(),}).in("id", ids as string[]);if (update.error) {+ console.error(update.error);return json({error: { message: "Failed to update non-conformance" },data: null,diff --git a/packages/form/src/components/MultiSelect.tsx b/packages/form/src/components/MultiSelect.tsxindex bbce939409..89cf5296c0 100644--- a/packages/form/src/components/MultiSelect.tsx+++ b/packages/form/src/components/MultiSelect.tsx@@ -1,5 +1,6 @@import type { MultiSelectProps as MultiSelectBaseProps } from "@carbon/react";import {+ Badge,FormControl,FormErrorMessage,FormHelperText,@@ -7,24 +8,57 @@ import {MultiSelect as MultiSelectBase,} from "@carbon/react";-import { useControlField, useField } from "../hooks";import { useEffect } from "react";+import { useControlField, useField } from "../hooks";export type MultiSelectProps = Omit<MultiSelectBaseProps,- "onChange" | "value"+ "onChange" | "value" | "inline"> & {name: string;label?: string;helperText?: string;value?: string[];onChange?: (newValue: { value: string; label: string }[]) => void;+ inline?: boolean;+ inlineIcon?: React.ReactElement;+ maxPreview?: number;+};++const MultiSelectPreview = (+ value: string[],+ options: { value: string; label: string; helper?: string }[],+ maxPreview?: number+) => {+ return (+ <div className="flex flex-wrap gap-1 items-start">+ {maxPreview && value.length > maxPreview ? (+ <Badge+ variant="secondary"+ className="border dark:border-none dark:shadow-button-base"+ >+ {value.length} selected+ </Badge>+ ) : (+ value.sort().map((label: string) => (+ <Badge+ className="max-w-[160px] truncate border dark:border-none dark:shadow-button-base"+ key={label}+ variant="secondary"+ >+ {label}+ </Badge>+ ))+ )}+ </div>+ );};const MultiSelect = ({name,label,helperText,+ maxPreview,...props}: MultiSelectProps) => {const { error } = useField(name);@@ -50,9 +84,11 @@ const MultiSelect = ({value={selection}/>))}+<MultiSelectBase{...props}value={value.filter(Boolean)}+ inline={props.inline ? MultiSelectPreview : undefined}onChange={(newValue) => {setValue(newValue ?? []);onChange(newValue ?? []);diff --git a/packages/form/src/components/Select.tsx b/packages/form/src/components/Select.tsxindex 0402f98eb9..65953871c4 100644--- a/packages/form/src/components/Select.tsx+++ b/packages/form/src/components/Select.tsx@@ -144,6 +144,12 @@ export const SelectBase = forwardRef<HTMLButtonElement, SelectBaseProps>() => {const isInlinePreview = !!inline;+ console.log({+ isInlinePreview,+ value,+ options,+ });+return (<HStack spacing={1}>{isInlinePreview && value && (diff --git a/packages/react/src/MultiSelect.tsx b/packages/react/src/MultiSelect.tsxindex 15096b52d1..d6b150e704 100644--- a/packages/react/src/MultiSelect.tsx+++ b/packages/react/src/MultiSelect.tsx@@ -2,6 +2,7 @@ import { useVirtualizer } from "@tanstack/react-virtual";import type { ComponentPropsWithoutRef } from "react";import { forwardRef, useId, useMemo, useRef, useState } from "react";import { FaRegSquare, FaSquareCheck } from "react-icons/fa6";+import { LuCirclePlus, LuSettings2, LuX } from "react-icons/lu";import { RxMagnifyingGlass } from "react-icons/rx";import { Badge, BadgeCloseButton } from "./Badge";import { Button } from "./Button";@@ -13,6 +14,8 @@ import {CommandItem,multiSelectTriggerVariants,} from "./Command";+import { HStack } from "./HStack";+import { IconButton } from "./IconButton";import { Popover, PopoverContent, PopoverTrigger } from "./Popover";import { cn } from "./utils/cn";import { reactNodeToString } from "./utils/react";@@ -26,11 +29,20 @@ export type MultiSelectProps = Omit<options: {label: string;value: string;+ helper?: string;}[];isReadOnly?: boolean;+ isClearable?: boolean;placeholder?: string;onChange: (selected: string[]) => void;itemHeight?: number;+ maxPreview?: number;+ inline?: (+ value: string[],+ options: { value: string; label: string; helper?: string }[],+ maxPreview?: number+ ) => React.ReactNode;+ inlineIcon?: React.ReactElement;};const MultiSelect = forwardRef<HTMLButtonElement, MultiSelectProps>(@@ -40,15 +52,20 @@ const MultiSelect = forwardRef<HTMLButtonElement, MultiSelectProps>(value,options,isReadOnly,+ isClearable,placeholder,onChange,className,itemHeight = 40,+ maxPreview,+ inline,+ inlineIcon,...props},ref) => {const [open, setOpen] = useState(false);+ const [search, setSearch] = useState("");const id = useId();@@ -57,70 +74,139 @@ const MultiSelect = forwardRef<HTMLButtonElement, MultiSelectProps>(};const hasSelections = value.length > 0;+ const isInlinePreview = !!inline;return (- <Popover open={open} onOpenChange={setOpen}>- <PopoverTrigger asChild>- <Button- aria-controls={id}- aria-expanded={open}- role="combobox"- tabIndex={0}- variant="secondary"+ <HStack+ className={cn(isInlinePreview ? "w-full" : "min-w-0 flex-grow")}+ spacing={1}+ >+ {isInlinePreview && Array.isArray(value) && value.length > 0 && (+ <spanclassName={cn(- multiSelectTriggerVariants({ size, hasSelections }),- "bg-transparent px-2",- className+ "flex-grow line-clamp-1 cursor-pointer",+ isReadOnly && "cursor-default opacity-50")}- onClick={() => setOpen(!open)}- onKeyDown={() => setOpen(!open)}- asChild+ onClick={isReadOnly ? undefined : () => setOpen(true)}>- <div>- {hasSelections ? (- <div className="flex gap-1 flex-wrap">- {value.map((item) => (- <Badge- key={item}- variant="secondary"- className="border border-card"- >- {options.find((option) => option.value === item)?.label}- <BadgeCloseButton- type="button"- tabIndex={-1}- onClick={(e) => {- e.preventDefault();- e.stopPropagation();- handleUnselect(item);- }}- />- </Badge>- ))}+ {inline(value, options, maxPreview)}+ </span>+ )}++ <Popover open={open} onOpenChange={setOpen}>+ <PopoverTrigger asChild>+ {inline ? (+ <IconButton+ size={size ?? "sm"}+ variant="secondary"+ aria-label={hasSelections ? "Edit" : "Add"}+ icon={+ inlineIcon ? (+ inlineIcon+ ) : hasSelections ? (+ <LuSettings2 />+ ) : (+ <LuCirclePlus />+ )+ }+ ref={ref}+ isDisabled={isReadOnly}+ onClick={() => setOpen(true)}+ />+ ) : (+ <Button+ aria-controls={id}+ aria-expanded={open}+ role="combobox"+ tabIndex={0}+ variant="secondary"+ className={cn(+ multiSelectTriggerVariants({ size, hasSelections }),+ "bg-transparent px-2",+ className+ )}+ isDisabled={isReadOnly}+ onClick={() => {+ if (!isReadOnly) setOpen(!open);+ }}+ onKeyDown={(e) => {+ if ((e.key === "Enter" || e.key === " ") && !isReadOnly) {+ setOpen(!open);+ }+ }}+ asChild+ >+ <div>+ {hasSelections ? (+ <div className="flex gap-1 flex-wrap">+ {value.map((item) => (+ <Badge+ key={item}+ variant="secondary"+ className="border border-card shadow-sm"+ >+ {+ options.find((option) => option.value === item)+ ?.label+ }+ <BadgeCloseButton+ disabled={isReadOnly}+ type="button"+ tabIndex={-1}+ onKeyDown={(e) => {+ if (e.key === "Enter" && !isReadOnly) {+ handleUnselect(item);+ }+ }}+ onMouseDown={(e) => {+ e.preventDefault();+ e.stopPropagation();+ }}+ onClick={(e) => {+ e.preventDefault();+ e.stopPropagation();+ if (!isReadOnly) handleUnselect(item);+ }}+ />+ </Badge>+ ))}+ </div>+ ) : (+ <span className="text-muted-foreground">+ {placeholder ?? "Select"}+ </span>+ )}++ <RxMagnifyingGlass className="h-4 w-4 shrink-0 opacity-50" /></div>- ) : (- <span className="text-muted-foreground">- {placeholder ?? "Select"}- </span>- )}-- <RxMagnifyingGlass className="h-4 w-4 shrink-0 opacity-50" />- </div>- </Button>- </PopoverTrigger>- <PopoverContent- align="start"- className="min-w-[260px] w-[--radix-popover-trigger-width] p-1"- >- <VirtualizedCommand- options={options}- value={value}- onChange={onChange}- itemHeight={itemHeight}- setOpen={setOpen}+ </Button>+ )}+ </PopoverTrigger>+ <PopoverContent+ align="end"+ className="min-w-[260px] w-[--radix-popover-trigger-width] p-1"+ >+ <VirtualizedCommand+ options={options}+ value={value}+ onChange={onChange}+ itemHeight={itemHeight}+ setOpen={setOpen}+ search={search}+ setSearch={setSearch}+ />+ </PopoverContent>+ </Popover>+ {isClearable && !isReadOnly && value.length > 0 && (+ <IconButton+ variant={isInlinePreview ? "secondary" : "ghost"}+ aria-label="Clear"+ icon={<LuX />}+ onClick={() => onChange([])}+ size={isInlinePreview ? "sm" : size}/>- </PopoverContent>- </Popover>+ )}+ </HStack>);});@@ -134,6 +220,8 @@ type VirtualizedCommandProps = {onChange: (selected: string[]) => void;itemHeight: number;setOpen: (open: boolean) => void;+ search: string;+ setSearch: (search: string) => void;};function VirtualizedCommand({@@ -142,8 +230,9 @@ function VirtualizedCommand({onChange,itemHeight,setOpen,+ search,+ setSearch,}: VirtualizedCommandProps) {- const [search, setSearch] = useState("");const parentRef = useRef<HTMLDivElement>(null);const filteredOptions = useMemo(() => {@@ -151,10 +240,10 @@ function VirtualizedCommand({? options.filter((option) => {const value =typeof option.label === "string"- ? option.label.toLowerCase()+ ? `${option.label} ${option.helper ?? ""}`: reactNodeToString(option.label);- return value.includes(search.toLowerCase());+ return value.toLowerCase().includes(search.toLowerCase());}): options;}, [options, search]);@@ -185,7 +274,6 @@ function VirtualizedCommand({}}><CommandGroup- className="pt-1"style={{height: `${virtualizer.getTotalSize()}px`,width: "100%",@@ -199,6 +287,12 @@ function VirtualizedCommand({return (<CommandItemkey={option.value}+ value={+ typeof option.label === "string"+ ? option.label.replace(/"/g, '\\"') ++ (option.helper?.replace(/"/g, '\\"') ?? "")+ : undefined+ }onSelect={() => {onChange(isSelected@@ -222,7 +316,16 @@ function VirtualizedCommand({) : (<FaRegSquare className="mr-1.5 text-muted-foreground" />)}- <span className="line-clamp-1">{option.label}</span>+ {option.helper ? (+ <div className="flex flex-col">+ <p className="line-clamp-1">{option.label}</p>+ <p className="text-xs text-muted-foreground line-clamp-1">+ {option.helper}+ </p>+ </div>+ ) : (+ <span className="line-clamp-1">{option.label}</span>+ )}</div></CommandItem>);