Skip to content

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.

feat: add parameters and attributes to mes

Brad Barbin135b42570b16
diff --git a/apps/mes/app/components/Icons.tsx b/apps/mes/app/components/Icons.tsx
index 8029f578a4..5eaada219a 100644
--- a/apps/mes/app/components/Icons.tsx
+++ b/apps/mes/app/components/Icons.tsx
@@ -5,11 +5,18 @@ import {
LuAtom,
LuCircleCheck,
LuCircleX,
+ LuClock,
+ LuFlaskConical,
LuHammer,
LuHeadphones,
+ LuImage,
+ LuList,
LuPizza,
+ LuQrCode,
LuShoppingCart,
LuSquare,
+ LuToggleLeft,
+ LuUser,
} from "react-icons/lu";
import {
@@ -33,6 +40,7 @@ import { MediumPriorityIcon } from "~/assets/icons/MediumPriorityIcon";
import { TodoStatusIcon } from "~/assets/icons/TodoStatusIcon";
import type { documentTypes } from "~/services/models";
import type { Operation } from "~/services/types";
+import { Database } from "../../../../packages/database/src/types";
type FileIconProps = {
type: (typeof documentTypes)[number];
@@ -41,6 +49,29 @@ type FileIconProps = {
const documentIconBaseClase = "w-6 h-6 flex-shrink-0";
+export function DeadlineIcon({
+ deadlineType,
+ overdue,
+}: {
+ deadlineType: Operation["jobDeadlineType"];
+ overdue: boolean;
+}) {
+ switch (deadlineType) {
+ case "ASAP":
+ return <BsExclamationSquareFill className="text-red-500" />;
+ case "Hard Deadline":
+ return <HighPriorityIcon className={cn(overdue ? "text-red-500" : "")} />;
+ case "Soft Deadline":
+ return (
+ <MediumPriorityIcon className={cn(overdue ? "text-red-500" : "")} />
+ );
+ case "No Deadline":
+ return <LowPriorityIcon />;
+ default:
+ return null;
+ }
+}
+
export const FileIcon = ({ type, className }: FileIconProps) => {
switch (type) {
case "Document":
@@ -170,25 +201,27 @@ export function OperationStatusIcon({
}
}
-export function DeadlineIcon({
- deadlineType,
- overdue,
+export const ProcedureAttributeTypeIcon = ({
+ type,
+ className,
}: {
- deadlineType: Operation["jobDeadlineType"];
- overdue: boolean;
-}) {
- switch (deadlineType) {
- case "ASAP":
- return <BsExclamationSquareFill className="text-red-500" />;
- case "Hard Deadline":
- return <HighPriorityIcon className={cn(overdue ? "text-red-500" : "")} />;
- case "Soft Deadline":
- return (
- <MediumPriorityIcon className={cn(overdue ? "text-red-500" : "")} />
- );
- case "No Deadline":
- return <LowPriorityIcon />;
- default:
- return null;
+ type: Database["public"]["Enums"]["procedureAttributeType"];
+ className?: string;
+}) => {
+ switch (type) {
+ case "Value":
+ return <LuQrCode className={cn("text-foreground", className)} />;
+ case "Measurement":
+ return <LuFlaskConical className={cn("text-emerald-500", className)} />;
+ case "Checkbox":
+ return <LuToggleLeft className={cn("text-purple-600", className)} />;
+ case "Timestamp":
+ return <LuClock className={cn("text-blue-500", className)} />;
+ case "Person":
+ return <LuUser className={cn("text-yellow-600", className)} />;
+ case "List":
+ return <LuList className={cn("text-orange-600", className)} />;
+ case "File":
+ return <LuImage className={cn("text-indigo-500", className)} />;
}
-}
+};
diff --git a/apps/mes/app/components/JobOperation.tsx b/apps/mes/app/components/JobOperation.tsx
index 64bbe014cc..19cad772f7 100644
--- a/apps/mes/app/components/JobOperation.tsx
+++ b/apps/mes/app/components/JobOperation.tsx
@@ -88,6 +88,8 @@ import {
import type {
Job,
JobMaterial,
+ JobOperationParameter,
+ JobOperationAttribute,
OperationWithDetails,
ProductionEvent,
ProductionQuantity,
@@ -128,6 +130,7 @@ import { flushSync } from "react-dom";
import { FaTasks } from "react-icons/fa";
import { FaCheck, FaPause, FaPlay, FaPlus, FaTrash } from "react-icons/fa6";
import {
+ LuActivity,
LuAxis3D,
LuChevronLeft,
LuClipboardCheck,
@@ -136,32 +139,42 @@ import {
LuGitBranchPlus,
LuHammer,
LuHardHat,
+ LuInfo,
+ LuList,
LuSend,
LuTimer,
LuTriangleAlert,
} from "react-icons/lu";
-import { MethodIcon, MethodItemTypeIcon } from "~/components/Icons";
+import {
+ MethodIcon,
+ MethodItemTypeIcon,
+ ProcedureAttributeTypeIcon,
+} from "~/components/Icons";
import { getFileType } from "~/services/operations.service";
import { useItems, usePeople } from "~/stores";
import ItemThumbnail from "./ItemThumbnail";
import ScrapReason from "./ScrapReason";
type JobOperationProps = {
+ attributes: Promise<PostgrestResponse<JobOperationAttribute>>;
events: ProductionEvent[];
files: Promise<StorageItem[]>;
materials: Promise<PostgrestResponse<JobMaterial>>;
operation: OperationWithDetails;
+ parameters: Promise<PostgrestResponse<JobOperationParameter>>;
job: Job;
thumbnailPath: string | null;
workCenter: Promise<PostgrestSingleResponse<{ name: string }>>;
};
export const JobOperation = ({
+ attributes,
events,
files,
job,
materials,
operation: originalOperation,
+ parameters,
thumbnailPath,
workCenter,
}: JobOperationProps) => {
@@ -261,7 +274,7 @@ export const JobOperation = ({
}
value="instructions"
>
- Instructions
+ Procedure
</TabsTrigger>
<TabsTrigger variant="primary" value="chat">
Chat
@@ -421,8 +434,8 @@ export const JobOperation = ({
</div>
</div>
</div>
- <Separator />
+ <Separator />
<div className="flex flex-col items-start justify-between w-full">
<div className="flex flex-col gap-4 p-4 w-full">
<HStack className="justify-between w-full">
@@ -533,6 +546,84 @@ export const JobOperation = ({
</Suspense>
</div>
</div>
+
+ <Suspense key={operationId} fallback={<TableSkeleton />}>
+ <Await resolve={attributes}>
+ {(resolvedAttributes) =>
+ Array.isArray(resolvedAttributes?.data) &&
+ resolvedAttributes?.data.length > 0 && (
+ <>
+ <Separator />
+ <div className="flex flex-col items-start justify-between w-full">
+ <div className="flex flex-col gap-4 p-4 w-full">
+ <HStack className="justify-between w-full">
+ <Heading size="h3">Attributes</Heading>
+ </HStack>
+ <div className="border rounded-lg">
+ {resolvedAttributes.data
+ .sort(
+ (a, b) =>
+ (a.sortOrder ?? 0) - (b.sortOrder ?? 0)
+ )
+ .map((a, index) => (
+ <AttributesListItem
+ key={a.id}
+ attribute={a}
+ operationId={operationId}
+ className={
+ index === resolvedAttributes.data.length - 1
+ ? "border-none"
+ : ""
+ }
+ />
+ ))}
+ </div>
+ </div>
+ </div>
+ </>
+ )
+ }
+ </Await>
+ </Suspense>
+
+ <Suspense key={operationId} fallback={<TableSkeleton />}>
+ <Await resolve={parameters}>
+ {(resolvedParameters) =>
+ Array.isArray(resolvedParameters?.data) &&
+ resolvedParameters?.data.length > 0 && (
+ <>
+ <Separator />
+ <div className="flex flex-col items-start justify-between w-full">
+ <div className="flex flex-col gap-4 p-4 w-full">
+ <HStack className="justify-between w-full">
+ <Heading size="h3">Parameters</Heading>
+ </HStack>
+ <div className="border rounded-lg">
+ {resolvedParameters.data
+ .sort((a, b) =>
+ (a.key ?? "").localeCompare(b.key ?? "")
+ )
+ .map((p, index) => (
+ <ParametersListItem
+ key={p.id}
+ parameter={p}
+ operationId={operationId}
+ className={
+ index === resolvedParameters.data.length - 1
+ ? "border-none"
+ : ""
+ }
+ />
+ ))}
+ </div>
+ </div>
+ </div>
+ </>
+ )
+ }
+ </Await>
+ </Suspense>
+
<Separator />
<div className="flex flex-col items-start justify-between w-full">
<div className="flex flex-col gap-4 p-4 w-full">
@@ -2083,3 +2174,113 @@ function IssueModal({
</Modal>
);
}
+
+const unitOfMeasures = [
+ { label: "Ohms", value: "OHM" },
+ { label: "Amps", value: "AMP" },
+ { label: "Volts", value: "VOLT" },
+ { label: "Hertz", value: "HZ" },
+];
+
+function AttributesListItem({
+ attribute,
+ operationId,
+ className,
+}: {
+ attribute: JobOperationAttribute;
+ operationId?: string;
+ className: string;
+}) {
+ const {
+ id,
+ name,
+ description,
+ type,
+ unitOfMeasureCode,
+ minValue,
+ maxValue,
+ listValues,
+ } = attribute;
+
+ const fetcher = useFetcher<{ success: boolean }>();
+
+ if (!operationId) return null;
+ return (
+ <div className={cn("border-b p-6", className)}>
+ <div className="flex flex-1 justify-between items-center w-full">
+ <HStack spacing={4} className="w-1/2">
+ <HStack spacing={4} className="flex-1">
+ <div className="bg-muted border rounded-full flex items-center justify-center p-2">
+ <ProcedureAttributeTypeIcon type={type} />
+ </div>
+ <VStack spacing={0}>
+ <HStack>
+ <span className="text-foreground text-sm font-medium">
+ {name}
+ </span>
+ {description && (
+ <span className="text-muted-foreground text-sm">
+ {description}
+ </span>
+ )}
+ </HStack>
+ {type === "Measurement" && (
+ <span className="text-xs text-muted-foreground text-right">
+ {minValue !== null && maxValue !== null
+ ? `Must be between ${minValue} and ${maxValue} ${
+ unitOfMeasures.find(
+ (u) => u.value === unitOfMeasureCode
+ )?.label
+ }`
+ : minValue !== null
+ ? `Must be > ${minValue} ${
+ unitOfMeasures.find(
+ (u) => u.value === unitOfMeasureCode
+ )?.label
+ }`
+ : `Must be < ${maxValue} ${
+ unitOfMeasures.find(
+ (u) => u.value === unitOfMeasureCode
+ )?.label
+ }`}
+ </span>
+ )}
+ </VStack>
+ </HStack>
+ </HStack>
+ <div className="flex items-center justify-end gap-2"></div>
+ </div>
+ </div>
+ );
+}
+
+function ParametersListItem({
+ parameter,
+ operationId,
+ className,
+}: {
+ parameter: JobOperationParameter;
+ operationId?: string;
+ className: string;
+}) {
+ const { key, value } = parameter;
+
+ if (!operationId) return null;
+ return (
+ <div className={cn("border-b p-6", className)}>
+ <div className="flex flex-1 justify-between items-center w-full">
+ <HStack spacing={4} className="w-1/2">
+ <HStack spacing={4} className="flex-1">
+ <div className="bg-muted border rounded-full flex items-center justify-center p-2">
+ <LuActivity />
+ </div>
+ <p className="text-foreground text-sm font-medium">{key}</p>
+ </HStack>
+ </HStack>
+ <div className="flex items-center justify-end gap-2">
+ <p className="text-foreground text-sm">{value}</p>
+ </div>
+ </div>
+ </div>
+ );
+}
diff --git a/apps/mes/app/routes/x+/operation.$operationId.tsx b/apps/mes/app/routes/x+/operation.$operationId.tsx
index 3b2d3cea98..3db603a665 100644
--- a/apps/mes/app/routes/x+/operation.$operationId.tsx
+++ b/apps/mes/app/routes/x+/operation.$operationId.tsx
@@ -8,10 +8,12 @@ import { flash } from "@carbon/auth/session.server";
import type { LoaderFunctionArgs } from "@vercel/remix";
import { defer, redirect } from "@vercel/remix";
import {
+ getJobAttributesByOperationId,
getJobByOperationId,
getJobFiles,
getJobMaterialsByOperationId,
getJobOperationById,
+ getJobParametersByOperationId,
getProductionEventsForJobOperation,
getProductionQuantitiesForJobOperation,
getThumbnailPathByItemId,
@@ -66,6 +68,10 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
);
return defer({
+ attributes: getJobAttributesByOperationId(
+ serviceRole,
+ operation.data?.[0].id
+ ),
events: events.data ?? [],
quantities: (quantities.data ?? []).reduce(
(acc, curr) => {
@@ -89,6 +95,10 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
),
materials: getJobMaterialsByOperationId(serviceRole, operation.data?.[0]),
operation: makeDurations(operation.data?.[0]) as OperationWithDetails,
+ parameters: getJobParametersByOperationId(
+ serviceRole,
+ operation.data?.[0].id
+ ),
workCenter: getWorkCenter(serviceRole, operation.data?.[0].workCenterId),
thumbnailPath,
});
@@ -99,21 +109,25 @@ export default function OperationRoute() {
if (!operationId) throw new Error("Operation ID is required");
const {
+ attributes,
events,
job,
files,
materials,
operation,
+ parameters,
workCenter,
thumbnailPath,
} = useLoaderData<typeof loader>();
return (
<JobOperation
+ attributes={attributes}
events={events}
files={files}
materials={materials}
operation={operation}
+ parameters={parameters}
job={job}
thumbnailPath={thumbnailPath}
workCenter={workCenter}
diff --git a/apps/mes/app/services/operations.service.ts b/apps/mes/app/services/operations.service.ts
index bc73b721e7..dbc4574921 100644
--- a/apps/mes/app/services/operations.service.ts
+++ b/apps/mes/app/services/operations.service.ts
@@ -128,6 +128,33 @@ export function getFileType(fileName: string): (typeof documentTypes)[number] {
return "Other";
}
+export async function getJobAttributesByOperationId(
+ client: SupabaseClient<Database>,
+ operationId: string
+) {
+ return client
+ .from("jobOperationAttribute")
+ .select("*")
+ .eq("operationId", operationId);
+}
+
+export async function getJobByOperationId(
+ client: SupabaseClient<Database>,
+ operationId: string
+) {
+ const operation = await client
+ .from("jobOperation")
+ .select("jobId")
+ .eq("id", operationId)
+ .single();
+ if (operation.error) return operation;
+ return client
+ .from("jobs")
+ .select("*")
+ .eq("id", operation.data.jobId)
+ .single();
+}
+
export async function getJobFiles(
client: SupabaseClient<Database>,
companyId: string,
@@ -211,21 +238,14 @@ export async function getJobOperationsByWorkCenter(
});
}
-export async function getJobByOperationId(
+export async function getJobParametersByOperationId(
client: SupabaseClient<Database>,
operationId: string
) {
- const operation = await client
- .from("jobOperation")
- .select("jobId")
- .eq("id", operationId)
- .single();
- if (operation.error) return operation;
return client
- .from("jobs")
+ .from("jobOperationParameter")
.select("*")
- .eq("id", operation.data.jobId)
- .single();
+ .eq("operationId", operationId);
}
export async function getLocationsByCompany(
diff --git a/apps/mes/app/services/types.ts b/apps/mes/app/services/types.ts
index 78f2e9d4df..4c14be57d6 100644
--- a/apps/mes/app/services/types.ts
+++ b/apps/mes/app/services/types.ts
@@ -1,9 +1,11 @@
import type { FileObject } from "@supabase/storage-js";
import type {
+ getJobAttributesByOperationId,
getJobByOperationId,
getJobMaterialsByOperationId,
getJobOperationById,
getJobOperationsByWorkCenter,
+ getJobParametersByOperationId,
getLocationsByCompany,
getProductionEventsForJobOperation,
getProductionQuantitiesForJobOperation,
@@ -37,6 +39,14 @@ export type JobMaterial = NonNullable<
Awaited<ReturnType<typeof getJobMaterialsByOperationId>>["data"]
>[number];
+export type JobOperationAttribute = NonNullable<
+ Awaited<ReturnType<typeof getJobAttributesByOperationId>>["data"]
+>[number];
+
+export type JobOperationParameter = NonNullable<
+ Awaited<ReturnType<typeof getJobParametersByOperationId>>["data"]
+>[number];
+
export type Operation = BaseOperation & Durations;
export type OperationWithDetails = BaseOperationWithDetails & Durations;
diff --git a/packages/database/supabase/migrations/20250216192838_procedures.sql b/packages/database/supabase/migrations/20250216192838_procedures.sql
index fb13b7479c..398fff3461 100644
--- a/packages/database/supabase/migrations/20250216192838_procedures.sql
+++ b/packages/database/supabase/migrations/20250216192838_procedures.sql
@@ -466,4 +466,16 @@ FOR DELETE USING (
get_companies_with_employee_permission ('production_delete')
)::text[]
)
-);
\ No newline at end of file
+);
+
+ALTER TABLE "methodOperation" ADD COLUMN "procedureId" TEXT;
+ALTER TABLE "methodOperation" ADD CONSTRAINT "methodOperation_procedureId_fkey" FOREIGN KEY ("procedureId") REFERENCES "procedure"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+ALTER TABLE "jobOperation" ADD COLUMN "procedureId" TEXT;
+ALTER TABLE "jobOperation" ADD CONSTRAINT "jobOperation_procedureId_fkey" FOREIGN KEY ("procedureId") REFERENCES "procedure"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+ALTER TABLE "quoteOperation" ADD COLUMN "procedureId" TEXT;
+ALTER TABLE "quoteOperation" ADD CONSTRAINT "quoteOperation_procedureId_fkey" FOREIGN KEY ("procedureId") REFERENCES "procedure"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+
+