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 table for parts to step description

Brad Barbin0a2b69779821
diff --git a/apps/erp/app/modules/production/ui/Jobs/JobBillOfProcess.tsx b/apps/erp/app/modules/production/ui/Jobs/JobBillOfProcess.tsx
index 0ff91b2af4..00f788dde7 100644
--- a/apps/erp/app/modules/production/ui/Jobs/JobBillOfProcess.tsx
+++ b/apps/erp/app/modules/production/ui/Jobs/JobBillOfProcess.tsx
@@ -1378,8 +1378,13 @@ function StepsListItem({
const submitted = useRef(false);
const fetcher = useFetcher<typeof editJobOperationStepAction>();
const [description, setDescription] = useState<JSONContent>(() => {
+ if (!attribute.description) return {};
+ // Handle both object and string formats
+ if (typeof attribute.description === "object") {
+ return attribute.description as JSONContent;
+ }
try {
- return attribute.description ? JSON.parse(attribute.description) : {};
+ return JSON.parse(attribute.description);
} catch (e) {
return {};
}
diff --git a/apps/mes/app/components/ItemThumbnail.tsx b/apps/mes/app/components/ItemThumbnail.tsx
index 7ac17e308f..97fb5e73c5 100644
--- a/apps/mes/app/components/ItemThumbnail.tsx
+++ b/apps/mes/app/components/ItemThumbnail.tsx
@@ -1,9 +1,14 @@
import { cva } from "class-variance-authority";
import { getPrivateUrl } from "~/utils/path";
+import { cn } from "@carbon/react";
+import { MethodItemTypeIcon } from "./Icons";
+import { LuSquareStack } from "react-icons/lu";
interface ItemThumbnailProps {
thumbnailPath?: string | null;
size?: "sm" | "md" | "lg" | "xl";
+ type?: "Part" | "Material" | "Tool" | "Service" | "Consumable" | "Fixture";
+ onClick?: () => void;
}
const itemVariants = cva(
@@ -50,14 +55,45 @@ const itemVariants = cva(
}
);
-const ItemThumbnail = ({ thumbnailPath, size = "md" }: ItemThumbnailProps) => {
+const iconVariants = cva("text-[#AAAAAA] dark:text-[#444]", {
+ variants: {
+ size: {
+ sm: "w-5 h-5",
+ md: "w-6 h-6",
+ lg: "w-7 h-7",
+ xl: "w-11 h-11",
+ },
+ },
+ defaultVariants: {
+ size: "md",
+ },
+});
+
+const ItemThumbnail = ({
+ thumbnailPath,
+ type,
+ size = "md",
+ onClick,
+}: ItemThumbnailProps) => {
return thumbnailPath ? (
<img
alt="thumbnail"
- className={itemVariants({ size, withPadding: false })}
+ className={cn(
+ itemVariants({ size, withPadding: false }),
+ thumbnailPath && "cursor-pointer"
+ )}
src={getPrivateUrl(thumbnailPath)}
+ onClick={onClick}
/>
- ) : null;
+ ) : (
+ <div className={cn(itemVariants({ size }))}>
+ {type ? (
+ <MethodItemTypeIcon className={iconVariants({ size })} type={type} />
+ ) : (
+ <LuSquareStack className={iconVariants({ size })} />
+ )}
+ </div>
+ );
};
export default ItemThumbnail;
diff --git a/apps/mes/app/components/JobOperation/components/Step.tsx b/apps/mes/app/components/JobOperation/components/Step.tsx
index b49e5f4d56..aea76481ee 100644
--- a/apps/mes/app/components/JobOperation/components/Step.tsx
+++ b/apps/mes/app/components/JobOperation/components/Step.tsx
@@ -13,7 +13,11 @@ import {
ModalHeader,
ModalTitle,
Switch,
+ Table,
+ Td,
+ Tbody,
toast,
+ Tr,
useDisclosure,
VStack,
type JSONContent,
@@ -23,7 +27,7 @@ import { useEffect, useMemo, useState } from "react";
import { useUser } from "~/hooks";
import { stepRecordValidator } from "~/services/models";
import type { JobOperationStep } from "~/services/types";
-import { path } from "~/utils/path";
+import { getPrivateUrl, path } from "~/utils/path";
import { useCarbon } from "@carbon/auth";
import {
@@ -36,7 +40,7 @@ import {
Submit,
ValidatedForm,
} from "@carbon/form";
-import { formatDateTime } from "@carbon/utils";
+import { formatDateTime, parseMentionsFromDocument } from "@carbon/utils";
import {
LuChevronDown,
LuChevronRight,
@@ -46,10 +50,11 @@ import {
LuTrash,
} from "react-icons/lu";
import { ProcedureStepTypeIcon } from "~/components/Icons";
-import { usePeople } from "~/stores";
+import { useItems, usePeople } from "~/stores";
import FileDropzone from "../../FileDropzone";
import { useNumberFormatter } from "@react-aria/i18n";
+import ItemThumbnail from "~/components/ItemThumbnail";
export function StepsListItem({
activeStep,
@@ -74,6 +79,9 @@ export function StepsListItem({
step;
const hasDescription = description && Object.keys(description).length > 0;
+ const mentionIds = hasDescription
+ ? parseMentionsFromDocument(description as JSONContent)
+ : [];
const disclosure = useDisclosure({
defaultIsOpen: !!hasDescription,
});
@@ -218,10 +226,53 @@ export function StepsListItem({
}}
/>
)}
+ {mentionIds.length > 0 && <ItemsSummaryTable itemsIds={mentionIds} />}
</div>
);
}
+function ItemsSummaryTable({ itemsIds }: { itemsIds: string[] }) {
+ const [allItems] = useItems();
+ const items = useMemo(() => {
+ return itemsIds.map((id) => allItems.find((item) => item.id === id));
+ }, [itemsIds, allItems]);
+ return (
+ <Table>
+ <Tbody>
+ {items.map(
+ (item) =>
+ item && (
+ <Tr className="bg-muted/50 hover:bg-muted/80" key={item.id}>
+ <Td className="flex-shrink-0 py-3 w-[60px]">
+ <ItemThumbnail
+ size="lg"
+ thumbnailPath={item?.thumbnailPath ?? undefined}
+ onClick={() => {
+ if (item?.thumbnailPath) {
+ window.open(
+ getPrivateUrl(item.thumbnailPath),
+ "_blank"
+ );
+ }
+ }}
+ />
+ </Td>
+ <Td className="flex-grow">
+ <div className="flex flex-col gap-1">
+ <span className="text-base font-medium">{item.name}</span>
+ <span className="text-sm font-mono text-muted-foreground">
+ {item.readableIdWithRevision ?? item.id}
+ </span>
+ </div>
+ </Td>
+ </Tr>
+ )
+ )}
+ </Tbody>
+ </Table>
+ );
+}
+
export function PreviewStepRecord({
activeStep,
step,
diff --git a/apps/mes/app/components/RealtimeDataProvider.tsx b/apps/mes/app/components/RealtimeDataProvider.tsx
index 212310eec4..0c6bfb63d1 100644
--- a/apps/mes/app/components/RealtimeDataProvider.tsx
+++ b/apps/mes/app/components/RealtimeDataProvider.tsx
@@ -46,7 +46,7 @@ const RealtimeDataProvider = ({ children }: { children: React.ReactNode }) => {
fetchAllFromTable(
carbon,
"item",
- "id, readableIdWithRevision, name, type, replenishmentSystem, itemTrackingType, active",
+ "id, readableIdWithRevision, name, type, replenishmentSystem, itemTrackingType, active, thumbnailPath, modelUpload:modelUploadId(thumbnailPath)",
(query) =>
query
.eq("companyId", companyId)
@@ -70,8 +70,23 @@ const RealtimeDataProvider = ({ children }: { children: React.ReactNode }) => {
hydratedFromServer = true;
- // @ts-ignore
- setItems(items.data ?? []);
+ type ItemWithModelUpload = Item & {
+ modelUpload?: { thumbnailPath: string | null } | null;
+ };
+ const itemData = (items.data ?? []) as unknown as ItemWithModelUpload[];
+ setItems(
+ itemData.map((item) => ({
+ id: item.id,
+ name: item.name,
+ readableIdWithRevision: item.readableIdWithRevision,
+ type: item.type,
+ replenishmentSystem: item.replenishmentSystem,
+ itemTrackingType: item.itemTrackingType,
+ active: item.active,
+ thumbnailPath:
+ item.thumbnailPath ?? item.modelUpload?.thumbnailPath ?? null,
+ }))
+ );
setPeople(
// @ts-ignore
people.data?.filter((p) => !p.email?.includes("@carbon.ms")) ?? []
@@ -82,13 +97,11 @@ const RealtimeDataProvider = ({ children }: { children: React.ReactNode }) => {
if (!companyId) return;
hydrate();
-
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [companyId, accessToken]);
useEffect(() => {
if (!channelRef.current && carbon && accessToken && realtimeAuthSet) {
-
channelRef.current = carbon
.channel("realtime:core")
.on(
@@ -116,11 +129,11 @@ const RealtimeDataProvider = ({ children }: { children: React.ReactNode }) => {
id: inserted.id,
name: inserted.name,
readableIdWithRevision: inserted.readableIdWithRevision,
- description: inserted.description,
replenishmentSystem: inserted.replenishmentSystem,
itemTrackingType: inserted.itemTrackingType,
type: inserted.type,
active: inserted.active,
+ thumbnailPath: inserted.thumbnailPath,
},
].sort((a, b) =>
a.readableIdWithRevision.localeCompare(
@@ -145,6 +158,7 @@ const RealtimeDataProvider = ({ children }: { children: React.ReactNode }) => {
replenishmentSystem: updated.replenishmentSystem,
type: updated.type,
active: updated.active,
+ thumbnailPath: updated.thumbnailPath,
};
}
return i;
diff --git a/apps/mes/app/stores/items.ts b/apps/mes/app/stores/items.ts
index 2f2f8864ab..7ca15dbad7 100644
--- a/apps/mes/app/stores/items.ts
+++ b/apps/mes/app/stores/items.ts
@@ -10,6 +10,7 @@ export type Item = ListItem & {
itemTrackingType: Database["public"]["Enums"]["itemTrackingType"];
replenishmentSystem: Database["public"]["Enums"]["itemReplenishmentSystem"];
active: boolean;
+ thumbnailPath: string | null;
};
const $itemsStore = atom<Item[]>([]);
diff --git a/packages/utils/src/tiptap.ts b/packages/utils/src/tiptap.ts
index c3b9deb6d1..f12efc21f2 100644
--- a/packages/utils/src/tiptap.ts
+++ b/packages/utils/src/tiptap.ts
@@ -1,3 +1,35 @@
+import type { JSONContent } from "@tiptap/react";
+
+/**
+ * Recursively extracts unique item mention IDs from a TipTap/ProseMirror JSON document.
+ * Handles deeply nested structures including paragraphs, lists, and other block elements.
+ */
+export function parseMentionsFromDocument(content: JSONContent): string[] {
+ const mentionIds = new Set<string>();
+
+ function traverse(node: JSONContent): void {
+ if (!node) return;
+
+ if (Array.isArray(node)) {
+ for (const child of node) {
+ traverse(child);
+ }
+ return;
+ }
+
+ if (node.type === "mention" && node.attrs?.id) {
+ mentionIds.add(node.attrs.id);
+ }
+
+ if (node.content) {
+ traverse(node.content);
+ }
+ }
+
+ traverse(content);
+ return Array.from(mentionIds);
+}
+
export const textToTiptap = (text: string) => {
const lines = text.split("\n");
const content = lines.map((line) => ({