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
fix(mes): render image-only step descriptions on work instructions
Sidwebworks6edf96b4b3f7
diff --git a/apps/mes/app/components/JobOperation/components/Step.tsx b/apps/mes/app/components/JobOperation/components/Step.tsxindex fe15098bdc..aa7cc827e5 100644--- a/apps/mes/app/components/JobOperation/components/Step.tsx+++ b/apps/mes/app/components/JobOperation/components/Step.tsx@@ -34,6 +34,7 @@ import {VStack} from "@carbon/react";import {+ documentHasImages,parseMentionsFromDocument,stripSpecialCharacters,tiptapToText@@ -80,9 +81,13 @@ function hasStepDescription(description: JobOperationStep["description"]): boolean {if (!description) return false;- const text = tiptapToText(description as JSONContent).trim();+ const doc = description as JSONContent;+ const text = tiptapToText(doc).trim();if (text.length > 0 && text !== "{}") return true;- return parseMentionsFromDocument(description as JSONContent).length > 0;+ if (parseMentionsFromDocument(doc).length > 0) return true;+ // A step's reference imagery is frequently an image-only description (no text,+ // no @-mention). Without this the description block — and its <img> — is hidden.+ return documentHasImages(doc);}export function StepsListItem({diff --git a/packages/utils/src/tiptap.test.ts b/packages/utils/src/tiptap.test.tsnew file mode 100644index 0000000000..48ff4320c9--- /dev/null+++ b/packages/utils/src/tiptap.test.ts@@ -0,0 +1,55 @@+import { describe, expect, it } from "vitest";+import { documentHasImages } from "./tiptap";++describe("documentHasImages", () => {+ it("returns false for empty / textless documents", () => {+ expect(documentHasImages(null)).toBe(false);+ expect(documentHasImages(undefined)).toBe(false);+ expect(documentHasImages({})).toBe(false);+ expect(documentHasImages({ type: "doc", content: [] })).toBe(false);+ expect(+ documentHasImages({+ type: "doc",+ content: [+ { type: "paragraph", content: [{ type: "text", text: "hello" }] }+ ]+ })+ ).toBe(false);+ });++ it("detects a top-level image node (image-only description)", () => {+ expect(+ documentHasImages({+ type: "doc",+ content: [+ { type: "image", attrs: { src: "/file/preview/private/x.png" } }+ ]+ })+ ).toBe(true);+ });++ it("detects updatedImage and deeply nested images", () => {+ expect(+ documentHasImages({+ type: "doc",+ content: [{ type: "updatedImage", attrs: { src: "a.png" } }]+ })+ ).toBe(true);+ expect(+ documentHasImages({+ type: "doc",+ content: [+ {+ type: "bulletList",+ content: [+ {+ type: "listItem",+ content: [{ type: "image", attrs: { src: "b.png" } }]+ }+ ]+ }+ ]+ })+ ).toBe(true);+ });+});diff --git a/packages/utils/src/tiptap.ts b/packages/utils/src/tiptap.tsindex b3dd8bab6a..ea02e8558c 100644--- a/packages/utils/src/tiptap.ts+++ b/packages/utils/src/tiptap.ts@@ -30,6 +30,34 @@ export function parseMentionsFromDocument(content: JSONContent): string[] {return Array.from(mentionIds);}+/**+ * True when a TipTap/ProseMirror JSON document contains at least one image node+ * (`image` or `updatedImage`). Reference imagery is often the entire content of a+ * step description with no accompanying text, so a plain text/mention check alone+ * (see {@link parseMentionsFromDocument}) reports such a description as empty.+ */+export function documentHasImages(+ content: JSONContent | null | undefined+): boolean {+ if (!content) return false;++ function traverse(node: JSONContent): boolean {+ if (!node) return false;++ if (Array.isArray(node)) {+ return node.some(traverse);+ }++ if (node.type === "image" || node.type === "updatedImage") {+ return true;+ }++ return node.content ? traverse(node.content) : false;+ }++ return traverse(content);+}+export const textToTiptap = (text: string) => {const lines = text.split("\n");const content = lines.map((line) =>