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(cad): hide reoptimize/retry affordances when the source file is gone
Sidwebworksc98337100ea1
diff --git a/apps/erp/app/components/CadModel.tsx b/apps/erp/app/components/CadModel.tsxindex df5313bac4..ec70ca31dc 100644--- a/apps/erp/app/components/CadModel.tsx+++ b/apps/erp/app/components/CadModel.tsx@@ -292,10 +292,12 @@ const CadModel = ({)}{artifacts?.size && artifacts?.optimizedSize ? (<div className="group absolute bottom-2 left-2 z-10 flex items-center gap-1.5 rounded-md border border-border bg-popover px-2 py-1 text-xs text-muted-foreground shadow-sm">- {artifacts.optimizerAvailable ? (+ {artifacts.optimizerAvailable &&+ artifacts.sourceAvailable !== false ? (// Hovering the badge swaps the lightning for a refresh// action: re-run the optimise from the source file (e.g.- // to pick up improved quality settings).+ // to pick up improved quality settings). Hidden when the+ // source no longer exists — nothing to re-run from.<buttontype="button"aria-label="Reoptimize from source file"diff --git a/apps/erp/app/routes/api+/model.artifacts.$modelUploadId.ts b/apps/erp/app/routes/api+/model.artifacts.$modelUploadId.tsindex 5e1d81b27b..f9e9f8a049 100644--- a/apps/erp/app/routes/api+/model.artifacts.$modelUploadId.ts+++ b/apps/erp/app/routes/api+/model.artifacts.$modelUploadId.ts@@ -48,26 +48,33 @@ export async function loader({ request, params }: LoaderFunctionArgs) {const rawCandidate =model.data?.originalPath ??(modelPath && !modelPath.toLowerCase().endsWith(".zst") ? modelPath : null);- if (rawCandidate) {- const svc = getCarbonServiceRole();- const probe = (bucket: string) =>- svc.storage+ const svc = getCarbonServiceRole();+ const exists = async (path: string) => {+ for (const bucket of ["private", "temp-staging"] as const) {+ const info = await svc.storage.from(bucket)- .info(rawCandidate)+ .info(path).catch(() => ({ data: null, error: true as const }));- const inDurable = await probe("private");- if (!inDurable.error && inDurable.data) {+ if (!info.error && info.data) return bucket;+ }+ return null;+ };+ if (rawCandidate) {+ const bucket = await exists(rawCandidate);+ if (bucket) {rawPath = rawCandidate;- rawBucket = "private";- } else {- const staged = await probe("temp-staging");- if (!staged.error && staged.data) {- rawPath = rawCandidate;- rawBucket = "temp-staging";- }- // Absent in both → pruned/gone; rawPath stays null (rely on the GLB).+ rawBucket = bucket;}+ // Absent in both → pruned/gone; rawPath stays null (rely on the GLB).}+ // Whether a reoptimise has a source to read: the `modelPath` object (an+ // `.xbf.zst` counts — it re-tessellates). A pruned/dangling source means the+ // refresh affordance would only ever fail — the client hides it.+ const sourceAvailable = modelPath+ ? rawCandidate === modelPath+ ? rawPath !== null+ : (await exists(modelPath)) !== null+ : false;return {optimizedModelPath: model.data?.optimizedModelPath ?? null,@@ -91,6 +98,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {// Cache-buster for the optimised GLB: it lives at a STABLE path behind an// immutable-cached preview URL, so a re-optimise would otherwise keep// serving the browser-cached old mesh.- optimizedAt: model.data?.optimizedAt ?? null+ optimizedAt: model.data?.optimizedAt ?? null,+ sourceAvailable};}diff --git a/apps/mes/app/routes/api+/model.artifacts.$modelUploadId.ts b/apps/mes/app/routes/api+/model.artifacts.$modelUploadId.tsindex 44d11711b4..82bf833363 100644--- a/apps/mes/app/routes/api+/model.artifacts.$modelUploadId.ts+++ b/apps/mes/app/routes/api+/model.artifacts.$modelUploadId.ts@@ -47,26 +47,33 @@ export async function loader({ request, params }: LoaderFunctionArgs) {const rawCandidate =model.data?.originalPath ??(modelPath && !modelPath.toLowerCase().endsWith(".zst") ? modelPath : null);- if (rawCandidate) {- const svc = getCarbonServiceRole();- const probe = (bucket: string) =>- svc.storage+ const svc = getCarbonServiceRole();+ const exists = async (path: string) => {+ for (const bucket of ["private", "temp-staging"] as const) {+ const info = await svc.storage.from(bucket)- .info(rawCandidate)+ .info(path).catch(() => ({ data: null, error: true as const }));- const inDurable = await probe("private");- if (!inDurable.error && inDurable.data) {+ if (!info.error && info.data) return bucket;+ }+ return null;+ };+ if (rawCandidate) {+ const bucket = await exists(rawCandidate);+ if (bucket) {rawPath = rawCandidate;- rawBucket = "private";- } else {- const staged = await probe("temp-staging");- if (!staged.error && staged.data) {- rawPath = rawCandidate;- rawBucket = "temp-staging";- }- // Absent in both → pruned/gone; rawPath stays null (rely on the GLB).+ rawBucket = bucket;}+ // Absent in both → pruned/gone; rawPath stays null (rely on the GLB).}+ // Whether a reoptimise has a source to read: the `modelPath` object (an+ // `.xbf.zst` counts — it re-tessellates). A pruned/dangling source means the+ // refresh affordance would only ever fail — the client hides it.+ const sourceAvailable = modelPath+ ? rawCandidate === modelPath+ ? rawPath !== null+ : (await exists(modelPath)) !== null+ : false;return {optimizedModelPath: model.data?.optimizedModelPath ?? null,@@ -84,6 +91,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {// Cache-buster for the optimised GLB: it lives at a STABLE path behind an// immutable-cached preview URL, so a re-optimise would otherwise keep// serving the browser-cached old mesh.- optimizedAt: model.data?.optimizedAt ?? null+ optimizedAt: model.data?.optimizedAt ?? null,+ sourceAvailable};}diff --git a/packages/viewer/src/useOptimizedModel.ts b/packages/viewer/src/useOptimizedModel.tsindex db2c06c481..162468ee09 100644--- a/packages/viewer/src/useOptimizedModel.ts+++ b/packages/viewer/src/useOptimizedModel.ts@@ -11,6 +11,10 @@ export type ModelArtifacts = {/** When the optimised GLB last landed — the client cache-buster for its* stable, immutable-cached URL. */optimizedAt?: string | null;+ /** Whether the reoptimise SOURCE (the modelPath object) still exists in+ * storage — pruned/dangling rows can't be re-optimised, so hosts hide the+ * refresh affordance. Absent (older server) → treat as available. */+ sourceAvailable?: boolean;lodPath: string | null;glbPath: string | null;thumbnailPath: string | null;@@ -222,6 +226,8 @@ export function useOptimizedModel({if (autoFiredRef.current === modelUploadId) return;// No optimiser configured → firing reoptimise just no-ops server-side; skip it.if (artifacts.optimizerAvailable === false) return;+ // No source left in storage → the run can only fail; don't fire.+ if (artifacts.sourceAvailable === false) return;if (hasInteractive ||optimizeInFlight ||@@ -296,9 +302,12 @@ export function useOptimizedModel({artifacts?.optimizerAvailable !== false;// Whether a manual retry can possibly succeed. When the optimiser isn't- // configured, hosts must not wire `onRetry` — otherwise ModelPreview's- // settled/no-preview state renders a retry button advertising a dead action.- const canRetry = artifacts?.optimizerAvailable !== false;+ // configured — or the reoptimise SOURCE no longer exists in storage — hosts+ // must not wire `onRetry`: ModelPreview's settled/no-preview state would+ // render a retry button advertising a dead action.+ const canRetry =+ artifacts?.optimizerAvailable !== false &&+ artifacts?.sourceAvailable !== false;return {artifacts,