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(viewer): staged optimise progress + Load Preview affordance

Sidwebworksa851ed0650b3
diff --git a/apps/erp/app/components/CadModel.tsx b/apps/erp/app/components/CadModel.tsx
index 748795785e..e9660fe7e2 100644
--- a/apps/erp/app/components/CadModel.tsx
+++ b/apps/erp/app/components/CadModel.tsx
@@ -31,6 +31,7 @@ import { LuCloudUpload, LuZap } from "react-icons/lu";
import { useFetcher, useRevalidator } from "react-router";
import { useModelUpload, useUser } from "~/hooks";
import { getPrivateUrl, getRawModelUrl, path } from "~/utils/path";
+import { ModelOptimizeProgress } from "./ModelOptimizeProgress";
import { ModelUploadProgress } from "./ModelUploadProgress";
const SIZE_LIMIT = getFileSizeLimit("CAD_MODEL_UPLOAD");
@@ -189,10 +190,26 @@ const CadModel = ({
const reoptimizeFetcher = useFetcher<{ success: boolean }>();
// A server GLB may still be on its way while a fresh file uploads or the
// optimise job runs. Raws <= MODEL_RAW_KEEP_MAX_BYTES render in-browser (WASM
- // tier) in the meantime; bigger ones show a spinner until the GLB lands, then
- // "preview unavailable" if it never does (optimise failed / non-mesh).
+ // tier) in the meantime; bigger ones show a staged optimise progress overlay
+ // until the GLB lands, then "preview unavailable" if it never does.
const awaitingModel = pending || Boolean(file);
+ const hasInteractive = Boolean(
+ artifacts?.optimizedModelPath || artifacts?.glbPath
+ );
+ const rawRenderable = Boolean(
+ (artifacts?.rawPath && (artifacts.size ?? 0) <= MODEL_RAW_KEEP_MAX_BYTES) ||
+ (file && file.size <= MODEL_RAW_KEEP_MAX_BYTES)
+ );
+ // Staged progress overlay: an optimise is running and nothing else can
+ // render (no artifact yet, raw too big / absent). When the raw tier renders,
+ // the optimise runs silently behind it and the GLB swaps in on success.
+ const optimizeInFlight =
+ artifacts?.optimizeStatus === "Queued" ||
+ artifacts?.optimizeStatus === "Processing";
+ const showOptimizeProgress =
+ optimizeInFlight && !hasInteractive && !rawRenderable && upload === null;
+
const onDelete = async () => {
if (!carbon) {
toast.error("Failed to initialize carbon client");
@@ -379,6 +396,11 @@ const CadModel = ({
mode={mode}
className={viewerClassName}
onRetry={!isReadOnly && modelPath ? onRetry : undefined}
+ retryLabel={
+ artifacts?.optimizeStatus === "Failed"
+ ? "Retry"
+ : "Load Preview"
+ }
onCancelWait={modelPath ? onCancelWait : undefined}
onDelete={canDelete ? deleteModal.onOpen : undefined}
/>
@@ -392,6 +414,15 @@ const CadModel = ({
/>
</div>
)}
+ {showOptimizeProgress && modelPath && (
+ <div className="absolute inset-0 z-30 flex items-center justify-center rounded-lg bg-background/95 p-6">
+ <ModelOptimizeProgress
+ key={`${modelPath}:${artifacts?.optimizeStatus}`}
+ modelUploadId={modelIdFromPath(modelPath) ?? ""}
+ queued={artifacts?.optimizeStatus === "Queued"}
+ />
+ </div>
+ )}
{artifacts?.size && artifacts?.optimizedSize ? (
<div className="pointer-events-none 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">
<LuZap className="size-3 shrink-0 text-emerald-500" />
diff --git a/apps/erp/app/components/ModelOptimizeProgress.tsx b/apps/erp/app/components/ModelOptimizeProgress.tsx
new file mode 100644
index 0000000000..6534261262
--- /dev/null
+++ b/apps/erp/app/components/ModelOptimizeProgress.tsx
@@ -0,0 +1,121 @@
+import { BarProgress, Button, cn } from "@carbon/react";
+import { useEffect, useState } from "react";
+import { LuCheck, LuLoaderCircle } from "react-icons/lu";
+import { useFetcher } from "react-router";
+import { path } from "~/utils/path";
+
+const STEPS = [
+ "Reading the CAD file",
+ "Optimizing the geometry",
+ "Preparing the viewer"
+];
+
+// Elapsed thresholds (s) at which the next step activates. The assembler
+// doesn't publish per-phase progress for optimise, so the checklist is paced
+// locally — honest about the coarse signal (queued/processing) while giving
+// the same staged feel as the convert progress UI.
+const STEP_AT = [0, 4, 15];
+
+function formatElapsed(seconds: number) {
+ if (seconds < 60) return `${seconds}s`;
+ return `${Math.floor(seconds / 60)}m ${seconds % 60}s`;
+}
+
+/**
+ * Staged checklist for a running model optimise (same visual language as
+ * ModelConvertProgress). Shown while the eager optimise runs and no preview
+ * tier can render. Cancel stamps the row Failed and cancels the assembler job.
+ */
+export function ModelOptimizeProgress({
+ modelUploadId,
+ queued = false,
+ className
+}: {
+ modelUploadId: string;
+ /** Job accepted but not picked up yet — first step reads as waiting. */
+ queued?: boolean;
+ className?: string;
+}) {
+ const cancelFetcher = useFetcher<{ success: boolean }>();
+ const [elapsed, setElapsed] = useState(0);
+
+ useEffect(() => {
+ const clock = setInterval(() => setElapsed((s) => s + 1), 1000);
+ return () => clearInterval(clock);
+ }, []);
+
+ const activeIndex = queued
+ ? 0
+ : STEP_AT.filter((t) => elapsed >= t).length - 1;
+ const fraction = queued
+ ? 0
+ : Math.min(
+ (activeIndex + Math.min(elapsed / 30, 0.8)) / STEPS.length,
+ 0.97
+ );
+
+ return (
+ <div
+ className={cn(
+ "flex w-[340px] flex-col gap-4 rounded-xl border border-border bg-card p-6 shadow-lg",
+ className
+ )}
+ >
+ <BarProgress progress={fraction} max={1} activeClassName="bg-primary" />
+ <div className="flex flex-col gap-2.5">
+ {STEPS.map((label, i) => {
+ const state =
+ !queued && i < activeIndex
+ ? "done"
+ : i === activeIndex
+ ? "active"
+ : "pending";
+ return (
+ <div key={label} className="flex items-center gap-2.5 text-sm">
+ <span className="flex h-5 w-5 items-center justify-center">
+ {state === "done" ? (
+ <LuCheck className="h-4 w-4 text-emerald-500 animate-in fade-in zoom-in-75 motion-reduce:animate-none" />
+ ) : state === "active" ? (
+ <LuLoaderCircle className="h-4 w-4 animate-spin text-primary motion-reduce:animate-none" />
+ ) : (
+ <span className="h-1.5 w-1.5 rounded-full bg-muted-foreground/30" />
+ )}
+ </span>
+ <span
+ className={
+ state === "pending"
+ ? "text-muted-foreground/40"
+ : state === "active"
+ ? "text-foreground"
+ : "text-muted-foreground"
+ }
+ >
+ {i === 0 && queued ? "Waiting for a worker…" : label}
+ </span>
+ </div>
+ );
+ })}
+ </div>
+ <div className="flex items-center justify-between">
+ <p className="text-xs tabular-nums text-muted-foreground">
+ {formatElapsed(elapsed)}
+ </p>
+ <cancelFetcher.Form
+ method="post"
+ action={path.to.api.modelOptimizeCancel}
+ >
+ <input type="hidden" name="modelUploadId" value={modelUploadId} />
+ <Button
+ type="submit"
+ size="sm"
+ variant="ghost"
+ isLoading={cancelFetcher.state !== "idle"}
+ isDisabled={cancelFetcher.state !== "idle"}
+ >
+ Cancel
+ </Button>
+ </cancelFetcher.Form>
+ </div>
+ </div>
+ );
+}
diff --git a/packages/viewer/src/ModelPreview.tsx b/packages/viewer/src/ModelPreview.tsx
index 975f701257..5efca454f0 100644
--- a/packages/viewer/src/ModelPreview.tsx
+++ b/packages/viewer/src/ModelPreview.tsx
@@ -53,6 +53,9 @@ export type ModelPreviewProps = {
downloadName?: string;
/** Re-run optimise when the model settled with no GLB (shows a Retry button). */
onRetry?: () => void;
+ /** Label for the retry action — e.g. "Load Preview" when the model was never
+ * optimised (first-time affordance) vs the default "Retry" after a failure. */
+ retryLabel?: string;
/** Called when the user cancels the "preparing" wait — the host should cancel
* the in-flight optimise (job + run) so the row doesn't stay stuck. */
onCancelWait?: () => void;
@@ -80,6 +83,7 @@ export function ModelPreview({
rawFile = null,
downloadName,
onRetry,
+ retryLabel = "Retry",
onCancelWait,
mode = "dark",
onDelete,
@@ -280,7 +284,7 @@ export function ModelPreview({
className="flex items-center gap-1.5 rounded-md border border-border bg-popover px-3 py-1.5 text-xs font-medium text-foreground shadow-sm transition-transform hover:bg-accent active:scale-[0.96]"
>
<LuRotateCw className="size-3.5" />
- Retry
+ {retryLabel}
</button>
)}
{onDelete && (