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 thumbnail to MES detail page
Rob Carrington6d4ef4259dd1
diff --git a/apps/mes/app/components/ItemThumbnail.tsx b/apps/mes/app/components/ItemThumbnail.tsxnew file mode 100644index 0000000000..dd1a2c40a1--- /dev/null+++ b/apps/mes/app/components/ItemThumbnail.tsx@@ -0,0 +1,63 @@+import { cva } from "class-variance-authority";+import { getPrivateUrl } from "~/utils/path";++interface ItemThumbnailProps {+ thumbnailPath?: string | null;+ size?: "sm" | "md" | "lg" | "xl";+}++const itemVariants = cva(+ "bg-gradient-to-bl from-muted to-muted/40 rounded-lg border-2 border-transparent",+ {+ variants: {+ size: {+ sm: "w-7 h-7",+ md: "w-9 h-9",+ lg: "w-11 h-11",+ xl: "w-16 h-16",+ },+ withPadding: {+ true: "",+ false: "p-0",+ },+ },+ compoundVariants: [+ {+ withPadding: true,+ size: "sm",+ class: "p-1",+ },+ {+ withPadding: true,+ size: "md",+ class: "p-1.5",+ },+ {+ withPadding: true,+ size: "lg",+ class: "p-2",+ },+ {+ withPadding: true,+ size: "xl",+ class: "p-2.5",+ },+ ],+ defaultVariants: {+ size: "md",+ withPadding: true,+ },+ }+);++const ItemThumbnail = ({ thumbnailPath, size = "md" }: ItemThumbnailProps) => {+ return thumbnailPath ? (+ <img+ alt="thumbnail"+ className={itemVariants({ size, withPadding: false })}+ src={getPrivateUrl(thumbnailPath)}+ />+ ) : null;+};++export default ItemThumbnail;diff --git a/apps/mes/app/components/JobOperation.tsx b/apps/mes/app/components/JobOperation.tsxindex 96d15e4f78..ebba627b21 100644--- a/apps/mes/app/components/JobOperation.tsx+++ b/apps/mes/app/components/JobOperation.tsx@@ -112,6 +112,7 @@ import {LuTimer,} from "react-icons/lu";import { MethodIcon, MethodItemTypeIcon } from "~/components/Icons";+import ItemThumbnail from "./ItemThumbnail";import ScrapReason from "./ScrapReason";type JobOperationProps = {@@ -121,6 +122,7 @@ type JobOperationProps = {materials: Promise<PostgrestResponse<JobMaterial>>;operation: OperationWithDetails;job: Job;+ thumbnailPath: string | null;};export const JobOperation = ({@@ -130,6 +132,7 @@ export const JobOperation = ({job,materials,operation: originalOperation,+ thumbnailPath,}: JobOperationProps) => {useRealtime("job", `id=eq.${job.id}`);const {@@ -273,12 +276,17 @@ export const JobOperation = ({<TabsContent value="details" className="flex flex-col"><ScrollArea className="w-full h-[calc(100vh-var(--header-height)*2-var(--controls-height)-2rem)] overflow-y-auto"><div className="flex items-start justify-between p-4">- <div className="flex flex-col flex-grow">- <Heading size="h2">{operation.itemReadableId}</Heading>- <p className="text-muted-foreground line-clamp-1">- {operation.itemDescription}- </p>- </div>+ <HStack>+ <div className="flex flex-col flex-grow">+ <Heading size="h2">{operation.itemReadableId}</Heading>+ <p className="text-muted-foreground line-clamp-1">+ {operation.itemDescription}+ </p>+ </div>+ {thumbnailPath && (+ <ItemThumbnail thumbnailPath={thumbnailPath} size="xl" />+ )}+ </HStack><div className="flex flex-col flex-shrink items-end"><Heading size="h2">{operation.operationQuantity}</Heading><p className="text-muted-foreground line-clamp-1">@@ -288,7 +296,7 @@ export const JobOperation = ({</div><Separator /><div className="flex items-start p-4">- <div className="grid gap-4 md:grid-cols-1 md:grid-cols-2 w-full">+ <div className="grid gap-4 sm:grid-cols-1 md:grid-cols-2 w-full"><div className="rounded-xl border bg-card text-card-foreground shadow"><div className="p-6 flex flex-row items-center justify-between space-y-0 pb-2"><h3 className="tracking-tight text-sm font-medium">diff --git a/apps/mes/app/routes/x+/active.$operationId.tsx b/apps/mes/app/routes/x+/active.$operationId.tsxindex 640a00c337..d57ae47360 100644--- a/apps/mes/app/routes/x+/active.$operationId.tsx+++ b/apps/mes/app/routes/x+/active.$operationId.tsx@@ -10,7 +10,7 @@ export default function OperationRoute() {const { operationId } = useParams();if (!operationId) throw new Error("Operation ID is required");- const { events, job, files, materials, operation } =+ const { events, job, files, materials, operation, thumbnailPath } =useLoaderData<typeof loader>();return (@@ -21,6 +21,7 @@ export default function OperationRoute() {materials={materials}operation={operation}job={job}+ thumbnailPath={thumbnailPath}/>);}diff --git a/apps/mes/app/routes/x+/operations.$workCenterId.$operationId.tsx b/apps/mes/app/routes/x+/operations.$workCenterId.$operationId.tsxindex 895529059a..6b046e606d 100644--- a/apps/mes/app/routes/x+/operations.$workCenterId.$operationId.tsx+++ b/apps/mes/app/routes/x+/operations.$workCenterId.$operationId.tsx@@ -11,7 +11,7 @@ export default function OperationRoute() {if (!operationId) throw new Error("Operation ID is required");if (!workCenterId) throw new Error("Work Center ID is required");- const { events, job, files, materials, operation } =+ const { events, job, files, materials, operation, thumbnailPath } =useLoaderData<typeof loader>();return (@@ -22,6 +22,7 @@ export default function OperationRoute() {materials={materials}operation={operation}job={job}+ thumbnailPath={thumbnailPath}/>);}diff --git a/apps/mes/app/routes/x+/recent.$operationId.tsx b/apps/mes/app/routes/x+/recent.$operationId.tsxindex 3739d30085..23c396b947 100644--- a/apps/mes/app/routes/x+/recent.$operationId.tsx+++ b/apps/mes/app/routes/x+/recent.$operationId.tsx@@ -10,7 +10,7 @@ export default function OperationRoute() {const { operationId } = useParams();if (!operationId) throw new Error("Operation ID is required");- const { events, job, files, materials, operation } =+ const { events, job, files, materials, operation, thumbnailPath } =useLoaderData<typeof loader>();return (@@ -21,6 +21,7 @@ export default function OperationRoute() {materials={materials}operation={operation}job={job}+ thumbnailPath={thumbnailPath}/>);}diff --git a/apps/mes/app/services/operation.server.ts b/apps/mes/app/services/operation.server.tsindex 9eb64d4060..c12477db70 100644--- a/apps/mes/app/services/operation.server.ts+++ b/apps/mes/app/services/operation.server.ts@@ -13,6 +13,7 @@ import {getJobOperationById,getProductionEventsForJobOperation,getProductionQuantitiesForJobOperation,+ getThumbnailPathByItemId,} from "./operations.service";export async function loader({ request, params }: LoaderFunctionArgs) {@@ -45,6 +46,15 @@ export async function loader({ request, params }: LoaderFunctionArgs) {);}+ if (!job.data.itemId) {+ throw redirect(+ path.to.operations,+ await flash(request, error("Item ID is required", "Failed to fetch item"))+ );+ }++ const thumbnailPath = await getThumbnailPathByItemId(client, job.data.itemId);+return defer({events: events.data ?? [],quantities: (quantities.data ?? []).reduce(@@ -64,5 +74,6 @@ export async function loader({ request, params }: LoaderFunctionArgs) {files: getJobFiles(client, companyId, job.data),materials: getJobMaterialsByOperationId(client, operation.data?.[0]),operation: makeDurations(operation.data?.[0]) as OperationWithDetails,+ thumbnailPath,});}diff --git a/apps/mes/app/services/operations.service.ts b/apps/mes/app/services/operations.service.tsindex c4d19ad0de..9c891c52e0 100644--- a/apps/mes/app/services/operations.service.ts+++ b/apps/mes/app/services/operations.service.ts@@ -196,6 +196,36 @@ export function getFileType(fileName: string): (typeof documentTypes)[number] {return "Other";}+export async function getThumbnailPathByItemId(+ client: SupabaseClient<Database>,+ itemId: string+) {+ const { data: item } = await client+ .from("item")+ .select("thumbnailPath, modelUploadId")+ .eq("id", itemId)+ .single();++ if (!item) return null;++ const { thumbnailPath, modelUploadId } = item;++ if (!modelUploadId) return thumbnailPath;++ const { data: modelUpload } = await client+ .from("modelUpload")+ .select("thumbnailPath")+ .eq("id", modelUploadId)+ .single();++ const modelUploadThumbnailPath = modelUpload?.thumbnailPath;++ if (!thumbnailPath && modelUploadThumbnailPath) {+ return modelUploadThumbnailPath;+ }+ return thumbnailPath;+}+export async function getJobFiles(client: SupabaseClient<Database>,companyId: string,diff --git a/apps/mes/app/utils/path.ts b/apps/mes/app/utils/path.tsindex 3cf15b802f..27a7fd22cb 100644--- a/apps/mes/app/utils/path.ts+++ b/apps/mes/app/utils/path.ts@@ -58,6 +58,10 @@ export const removeSubdomain = (url?: string): string => {return domain;};+export const getPrivateUrl = (path: string) => {+ return `/file/preview/private/${path}`;+};+export const getStoragePath = (bucket: string, path: string) => {return `${SUPABASE_API_URL}/storage/v1/object/public/${bucket}/${path}`;};