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.

improvement(assembly): Play on a sub-assembly builds it from its first step; sub-assembly panel spacing and overlap fixes

aashu2fd824431cba
diff --git a/apps/erp/app/modules/production/ui/Assemblies/AssemblyStepList.tsx b/apps/erp/app/modules/production/ui/Assemblies/AssemblyStepList.tsx
index 416f1b7ef5..873c246251 100644
--- a/apps/erp/app/modules/production/ui/Assemblies/AssemblyStepList.tsx
+++ b/apps/erp/app/modules/production/ui/Assemblies/AssemblyStepList.tsx
@@ -676,7 +676,10 @@ export default function AssemblyStepList({
variant="ghost"
size="sm"
leftIcon={<LuArrowLeft />}
- onClick={() => setOpenHeader(null)}
+ onClick={() => {
+ onSelectStep(openHeaderId);
+ setOpenHeader(null);
+ }}
>
<Trans>All steps</Trans>
</Button>
diff --git a/apps/erp/app/modules/production/ui/Assemblies/AssemblySubAssemblyProperties.tsx b/apps/erp/app/modules/production/ui/Assemblies/AssemblySubAssemblyProperties.tsx
index 0baf5527ce..f447076baa 100644
--- a/apps/erp/app/modules/production/ui/Assemblies/AssemblySubAssemblyProperties.tsx
+++ b/apps/erp/app/modules/production/ui/Assemblies/AssemblySubAssemblyProperties.tsx
@@ -234,7 +234,10 @@ export default function AssemblySubAssemblyProperties({
}
>
{isDisabled ? (
- <span className="truncate text-xs text-foreground">
+ <span
+ className="max-w-[11rem] truncate text-xs text-foreground"
+ title={usedInLabel}
+ >
{usedInLabel}
</span>
) : (
@@ -310,7 +313,7 @@ export default function AssemblySubAssemblyProperties({
</VStack>
{!isDisabled && (
- <HStack spacing={2} className="w-full flex-wrap">
+ <div className="flex w-full flex-wrap gap-2">
<Button
variant="secondary"
leftIcon={<LuUngroup />}
@@ -337,7 +340,7 @@ export default function AssemblySubAssemblyProperties({
>
<Trans>Delete Sub-Assembly</Trans>
</Button>
- </HStack>
+ </div>
)}
{isDeleting && (
diff --git a/apps/erp/app/routes/x+/assembly+/$id.tsx b/apps/erp/app/routes/x+/assembly+/$id.tsx
index 9170061da5..b3348b537a 100644
--- a/apps/erp/app/routes/x+/assembly+/$id.tsx
+++ b/apps/erp/app/routes/x+/assembly+/$id.tsx
@@ -254,9 +254,8 @@ export default function AssemblyInstructionRoute() {
// steps in rather than animating fallback paths the plan is about to replace.
const isPlanning = isAssemblyPlanRunning(planJob);
- const [selectedStepId, setSelectedStepId] = useState<string | null>(
- steps[0]?.id ?? null
- );
+ // null = the default below (the first row of the list).
+ const [selectedStepId, setSelectedStepId] = useState<string | null>(null);
const [draftComponentNodeIds, setDraftComponentNodeIds] = useState<
string[] | null
>(null);
@@ -283,8 +282,11 @@ export default function AssemblyInstructionRoute() {
const [isAddingComponents, setIsAddingComponents] = useState(false);
const { selectedStep, activeStepIndex } = useMemo(() => {
+ // Default to the first row of the list (a sub-assembly's steps are stored
+ // before its header).
const step =
steps.find((candidate) => candidate.id === selectedStepId) ??
+ steps.find((candidate) => !candidate.parentStepId) ??
steps[0] ??
null;
return {
@@ -417,6 +419,15 @@ export default function AssemblyInstructionRoute() {
: activeStepIndex;
}, [selectedStep, subPlan, viewerSteps, activeStepIndex]);
+ // With a sub-assembly row selected, Play builds it from its first step.
+ const playFromStepIndex = useMemo(() => {
+ if (!selectedStep?.isSubAssembly) return null;
+ const first = viewerSteps.findIndex(
+ (step) => step.parentStepId === selectedStep.id
+ );
+ return first >= 0 ? first : null;
+ }, [selectedStep, viewerSteps]);
+
const subAssemblyName = useCallback(
(headerId: string) =>
viewerSteps.find((step) => step.id === headerId)?.title ||
@@ -463,11 +474,11 @@ export default function AssemblyInstructionRoute() {
// viewer, marked in the Components panel. Viewer-driven changes (playback,
// scrub, on-screen nav) pass selectComponents:false so auto-advance doesn't
// stomp the selection the user is working with.
- if (options?.selectComponents !== false) {
- const step = stepsRef.current.find(
- (candidate) => candidate.id === stepId
- );
- if (step) setSelectedNodeIds(step.componentNodeIds ?? []);
+ const step = stepsRef.current.find(
+ (candidate) => candidate.id === stepId
+ );
+ if (options?.selectComponents !== false && step) {
+ setSelectedNodeIds(step.componentNodeIds ?? []);
}
},
[]
@@ -766,6 +777,7 @@ export default function AssemblyInstructionRoute() {
isolationLabel={isolationLabel}
carryInLabel={carryInLabel}
activeStepIndex={Math.max(playerStepIndex, 0)}
+ playFromStepIndex={playFromStepIndex}
playStepNonce={playStepNonce}
onStepChange={(index) => {
const step = steps[index];
diff --git a/packages/viewer/src/AssemblyPlayer.tsx b/packages/viewer/src/AssemblyPlayer.tsx
index b094205885..d149175bbd 100644
--- a/packages/viewer/src/AssemblyPlayer.tsx
+++ b/packages/viewer/src/AssemblyPlayer.tsx
@@ -164,9 +164,16 @@ export type AssemblyPlayerProps = {
/**
* Plays only these steps (an opened sub-assembly): the timeline, counter and
* prev/next cover just them. Every step is still passed in `steps`, so parts
- * built earlier render correctly.
+ * built earlier render correctly. Without it every step plays, each
+ * sub-assembly's steps in turn before the build that receives it.
*/
scopeStepIds?: string[] | null;
+ /**
+ * Play starts at this step instead of carrying on after the active one. Set
+ * while a sub-assembly row is selected: the player shows its finished unit,
+ * and Play builds it from its first step.
+ */
+ playFromStepIndex?: number | null;
/**
* Shown in a pill at the top of the canvas while the active step belongs to
* a sub-assembly (it is built on its own). The host translates it.
@@ -225,6 +232,7 @@ export const AssemblyPlayer = forwardRef<
suppressFallbackMotions = false,
hideCaption = false,
scopeStepIds,
+ playFromStepIndex,
isolationLabel,
carryInLabel,
mode = "dark",
@@ -649,11 +657,11 @@ export const AssemblyPlayer = forwardRef<
useEffect(() => {
if (playStepNonce === playStepNonceRef.current) return;
playStepNonceRef.current = playStepNonce;
- if (isEditingMotionRef.current || stepCount === 0) return;
+ if (isEditingMotionRef.current || !playable[clampedIndex]) return;
onScrub(startTimes[clampedIndex] ?? 0); // seek to the step's start
setContinuous(false);
setIsPlaying(true);
- }, [playStepNonce, clampedIndex, stepCount, startTimes, onScrub]);
+ }, [playStepNonce, clampedIndex, playable, startTimes, onScrub]);
return (
<div className={cn("flex h-full w-full flex-col", className)}>
@@ -821,7 +829,9 @@ export const AssemblyPlayer = forwardRef<
: Number.POSITIVE_INFINITY;
const currentStepFinished =
nextIndex >= 0 && playheadRef.current >= nextStart - 0.05;
- if (!playable[clampedIndex]) {
+ if (playFromStepIndex != null && playable[playFromStepIndex]) {
+ goToStep(playFromStepIndex, { play: true });
+ } else if (!playable[clampedIndex]) {
// Sitting on a step that doesn't play (a used sub-assembly's
// header) → start from the next one that does.
const start = nextIndex >= 0 ? nextIndex : playableIndices[0];