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.

ui-nit(erp): assembly instruction phone header lives in Overview; Make Active / New Version show only there

aashu268fae36ed0a
diff --git a/apps/erp/app/modules/production/ui/Assemblies/AssemblyInstructionHeader.tsx b/apps/erp/app/modules/production/ui/Assemblies/AssemblyInstructionHeader.tsx
index 440365e7cb..a99750cf4e 100644
--- a/apps/erp/app/modules/production/ui/Assemblies/AssemblyInstructionHeader.tsx
+++ b/apps/erp/app/modules/production/ui/Assemblies/AssemblyInstructionHeader.tsx
@@ -9,7 +9,8 @@ import {
DropdownMenuItem,
Input,
MENU_ITEM_SHORTCUTS,
- useDisclosure
+ useDisclosure,
+ useViewport
} from "@carbon/react";
import { Trans, useLingui } from "@lingui/react/macro";
import { useState } from "react";
@@ -33,39 +34,45 @@ import AssemblyInstructionStatus from "./AssemblyInstructionStatus";
const itemTypesWithDetails = ["Part", "Material", "Tool", "Consumable"];
-const AssemblyInstructionHeader = () => {
+function useInstruction() {
const { id } = useParams();
if (!id) throw new Error("id not found");
-
const routeData = useRouteData<{
instruction: AssemblyInstruction;
versions: AssemblyInstructionVersion[];
}>(path.to.assemblyInstruction(id));
- const instruction = routeData?.instruction;
- const versions = routeData?.versions ?? [];
-
- const { t } = useLingui();
- const permissions = usePermissions();
- const user = useUser();
- const { toggleExplorer, toggleProperties } = usePanels();
- const deleteDisclosure = useDisclosure();
- const activateDisclosure = useDisclosure();
+ return {
+ id,
+ instruction: routeData?.instruction,
+ versions: routeData?.versions ?? []
+ };
+}
- const nameFetcher = useFetcher<{}>();
+function useNewVersion() {
+ const { id, instruction } = useInstruction();
const newVersionFetcher = useFetcher<{}>();
- const invalidateFetcher = useFetcher<{ success: boolean }>();
+ const onNewVersion = () => {
+ if (!instruction) return;
+ const formData = new FormData();
+ formData.append("copyFromId", instruction.id);
+ newVersionFetcher.submit(formData, {
+ method: "post",
+ action: path.to.assemblyInstructionVersionNew(id)
+ });
+ };
+ return {
+ onNewVersion,
+ isCreatingVersion: newVersionFetcher.state !== "idle"
+ };
+}
+function InstructionNameInput() {
+ const { id, instruction } = useInstruction();
+ const permissions = usePermissions();
+ const nameFetcher = useFetcher<{}>();
const [name, setName] = useState(instruction?.name ?? "");
-
- const isDraft = instruction?.status === "Draft";
- const canUpdate = permissions.can("update", "production");
- const canCreate = permissions.can("create", "production");
- const isCreatingVersion = newVersionFetcher.state !== "idle";
-
- const [items] = useItems();
- const item = instruction?.itemId
- ? items.find((i) => i.id === instruction.itemId)
- : undefined;
+ const isEditable =
+ instruction?.status === "Draft" && permissions.can("update", "production");
const onUpdateName = (value: string) => {
if (!instruction || !value.trim() || value === instruction.name) return;
@@ -79,37 +86,131 @@ const AssemblyInstructionHeader = () => {
});
};
- const onNewVersion = () => {
- if (!instruction) return;
- const formData = new FormData();
- formData.append("copyFromId", instruction.id);
- newVersionFetcher.submit(formData, {
- method: "post",
- action: path.to.assemblyInstructionVersionNew(id)
- });
- };
-
- const nameInput = (
+ return (
<Input
className="mr-2 w-auto min-w-0 max-w-[320px] font-semibold text-foreground field-sizing-content"
value={name}
borderless
- onChange={
- isDraft && canUpdate ? (e) => setName(e.target.value) : undefined
- }
- onBlur={
- isDraft && canUpdate ? (e) => onUpdateName(e.target.value) : undefined
- }
+ onChange={isEditable ? (e) => setName(e.target.value) : undefined}
+ onBlur={isEditable ? (e) => onUpdateName(e.target.value) : undefined}
/>
);
- const statusBadge = (
- <AssemblyInstructionStatus status={instruction?.status} />
+}
+
+function InstructionStatus() {
+ const { instruction } = useInstruction();
+ const user = useUser();
+ if (!instruction) return null;
+ return (
+ <>
+ <AssemblyInstructionStatus status={instruction.status} />
+ <Badge variant="outline" className="shrink-0 tabular-nums">
+ <Trans>Version {instruction.version}</Trans>
+ </Badge>
+ <span className="hidden whitespace-nowrap text-xs text-muted-foreground lg:inline">
+ {instruction.createdBy === user.id ? (
+ <Trans>
+ By you · edited{" "}
+ <DateTime
+ value={instruction.updatedAt ?? instruction.createdAt}
+ variant="relative"
+ />
+ </Trans>
+ ) : (
+ <Trans>
+ edited{" "}
+ <DateTime
+ value={instruction.updatedAt ?? instruction.createdAt}
+ variant="relative"
+ />
+ </Trans>
+ )}
+ </span>
+ </>
);
- const versionBadge = instruction && (
- <Badge variant="outline" className="shrink-0 tabular-nums">
- <Trans>Version {instruction.version}</Trans>
- </Badge>
+}
+
+/** The next step: New Version on a published instruction, else Make Active. */
+function InstructionPrimaryAction() {
+ const { t } = useLingui();
+ const { id, instruction } = useInstruction();
+ const permissions = usePermissions();
+ const activateDisclosure = useDisclosure();
+ const { onNewVersion, isCreatingVersion } = useNewVersion();
+ if (!instruction) return null;
+
+ if (instruction.status === "Published") {
+ if (!permissions.can("create", "production")) return null;
+ return (
+ <RecordAction slot="primary">
+ <Button
+ isDisabled={isCreatingVersion}
+ isLoading={isCreatingVersion}
+ onClick={onNewVersion}
+ >
+ <Trans>New Version</Trans>
+ </Button>
+ </RecordAction>
+ );
+ }
+
+ return (
+ <>
+ <RecordAction slot="primary">
+ <Button
+ isDisabled={!permissions.can("update", "production")}
+ onClick={activateDisclosure.onOpen}
+ >
+ <Trans>Make Active</Trans>
+ </Button>
+ </RecordAction>
+ {activateDisclosure.isOpen && (
+ <Confirm
+ isOpen
+ title={t`Make Active`}
+ text={t`Make version ${instruction.version} active? This publishes it, archives the currently active version, and repoints in-flight job operations to it.`}
+ confirmText={t`Make Active`}
+ action={path.to.assemblyInstructionActivate(id)}
+ onCancel={activateDisclosure.onClose}
+ onSubmit={activateDisclosure.onClose}
+ />
+ )}
+ </>
+ );
+}
+
+/**
+ * Phones: the name, status and next step at the top of the Overview tab, so
+ * Steps and Properties get the full height.
+ */
+export function AssemblyInstructionOverviewHero() {
+ return (
+ <div className="flex shrink-0 flex-col gap-1.5 border-b border-border bg-card px-4 py-3">
+ <InstructionNameInput />
+ <div className="flex min-w-0 flex-wrap items-center gap-1.5 empty:hidden">
+ <InstructionStatus />
+ </div>
+ <InstructionPrimaryAction />
+ </div>
);
+}
+
+const AssemblyInstructionHeader = () => {
+ const { id, instruction, versions } = useInstruction();
+ const { t } = useLingui();
+ const { isPhone } = useViewport();
+ const permissions = usePermissions();
+ const { toggleExplorer, toggleProperties } = usePanels();
+ const deleteDisclosure = useDisclosure();
+ const invalidateFetcher = useFetcher<{ success: boolean }>();
+ const { onNewVersion, isCreatingVersion } = useNewVersion();
+ const canCreate = permissions.can("create", "production");
+
+ const [items] = useItems();
+ const item = instruction?.itemId
+ ? items.find((i) => i.id === instruction.itemId)
+ : undefined;
+
const menuItems = (
<>
{item && itemTypesWithDetails.includes(item.type) && (
@@ -150,41 +251,15 @@ const AssemblyInstructionHeader = () => {
</>
);
- const editedBy = instruction && (
- <span className="hidden whitespace-nowrap text-xs text-muted-foreground lg:inline">
- {instruction.createdBy === user.id ? (
- <Trans>
- By you · edited{" "}
- <DateTime
- value={instruction.updatedAt ?? instruction.createdAt}
- variant="relative"
- />
- </Trans>
- ) : (
- <Trans>
- edited{" "}
- <DateTime
- value={instruction.updatedAt ?? instruction.createdAt}
- variant="relative"
- />
- </Trans>
- )}
- </span>
- );
-
return (
<>
+ {/* Phones show the name, status and next step on the Overview tab
+ (AssemblyInstructionOverviewHero), not above the tab row. */}
<RecordHeader
- title={nameInput}
+ title={isPhone ? null : <InstructionNameInput />}
titleInHero
menu={menuItems}
- status={
- <>
- {statusBadge}
- {versionBadge}
- {editedBy}
- </>
- }
+ status={isPhone ? undefined : <InstructionStatus />}
onToggleExplorer={toggleExplorer}
onToggleProperties={toggleProperties}
actions={
@@ -212,28 +287,7 @@ const AssemblyInstructionHeader = () => {
/>
</RecordAction>
)}
- {instruction?.status === "Published"
- ? canCreate && (
- <RecordAction slot="primary">
- <Button
- isDisabled={isCreatingVersion}
- isLoading={isCreatingVersion}
- onClick={onNewVersion}
- >
- <Trans>New Version</Trans>
- </Button>
- </RecordAction>
- )
- : instruction && (
- <RecordAction slot="primary">
- <Button
- isDisabled={!canUpdate}
- onClick={activateDisclosure.onOpen}
- >
- <Trans>Make Active</Trans>
- </Button>
- </RecordAction>
- )}
+ {isPhone ? null : <InstructionPrimaryAction />}
</>
}
/>
@@ -251,17 +305,6 @@ const AssemblyInstructionHeader = () => {
}}
/>
)}
- {activateDisclosure.isOpen && instruction && (
- <Confirm
- isOpen
- title={t`Make Active`}
- text={t`Make version ${instruction.version} active? This publishes it, archives the currently active version, and repoints in-flight job operations to it.`}
- confirmText={t`Make Active`}
- action={path.to.assemblyInstructionActivate(id)}
- onCancel={activateDisclosure.onClose}
- onSubmit={activateDisclosure.onClose}
- />
- )}
</>
);
};
diff --git a/apps/erp/app/routes/x+/assembly+/$id.tsx b/apps/erp/app/routes/x+/assembly+/$id.tsx
index 782dcdebef..31b4affe6e 100644
--- a/apps/erp/app/routes/x+/assembly+/$id.tsx
+++ b/apps/erp/app/routes/x+/assembly+/$id.tsx
@@ -13,7 +13,8 @@ import {
Spinner,
toast,
useInterval,
- useMode
+ useMode,
+ useViewport
} from "@carbon/react";
import { redirect } from "@carbon/utils";
import type {
@@ -61,7 +62,9 @@ import {
} from "~/modules/production";
import { isAssemblerServiceHealthy } from "~/modules/production/production.server";
import AssemblyInstructionExplorer from "~/modules/production/ui/Assemblies/AssemblyInstructionExplorer";
-import AssemblyInstructionHeader from "~/modules/production/ui/Assemblies/AssemblyInstructionHeader";
+import AssemblyInstructionHeader, {
+ AssemblyInstructionOverviewHero
+} from "~/modules/production/ui/Assemblies/AssemblyInstructionHeader";
import AssemblyInstructionProperties from "~/modules/production/ui/Assemblies/AssemblyInstructionProperties";
import { SUB_ASSEMBLY_PARAM } from "~/modules/production/ui/Assemblies/AssemblyStepList";
import { ModelConvertProgress } from "~/modules/production/ui/Assemblies/ModelConvertProgress";
@@ -367,6 +370,7 @@ export default function AssemblyInstructionRoute() {
// An opened sub-assembly (?subAssembly=) scopes the player to its steps.
const { t } = useLingui();
+ const { isPhone } = useViewport();
const [searchParams] = useSearchParams();
const requestedSubAssembly = searchParams.get(SUB_ASSEMBLY_PARAM);
const openSubAssemblyId =
@@ -716,120 +720,123 @@ export default function AssemblyInstructionRoute() {
/>
}
content={
- <div className="relative bg-card h-[calc(100dvh-var(--topbar-height)-var(--header-height)-var(--content-inset))] w-full">
- {glbPath && graphPath && isPlanning && (
- <div className="absolute left-1/2 top-3 z-10 flex -translate-x-1/2 items-center gap-2 rounded-full border border-border bg-card px-3 py-1.5 shadow-lg">
- <Spinner className="h-3.5 w-3.5" />
- <span className="whitespace-nowrap text-xs font-medium text-foreground">
- Planning motion…
- </span>
- <cancelPlanFetcher.Form
- method="post"
- action={path.to.assemblyJobsCancel(id!)}
- >
- <input type="hidden" name="kind" value="plan" />
- <button
- type="submit"
- disabled={cancelPlanFetcher.state !== "idle"}
- className="text-xs text-muted-foreground underline-offset-2 hover:text-foreground hover:underline disabled:opacity-50"
+ <div className="flex h-[calc(100dvh-var(--topbar-height)-var(--header-height)-var(--content-inset))] w-full flex-col">
+ {isPhone ? <AssemblyInstructionOverviewHero /> : null}
+ <div className="relative min-h-0 w-full flex-1 bg-card">
+ {glbPath && graphPath && isPlanning && (
+ <div className="absolute left-1/2 top-3 z-10 flex -translate-x-1/2 items-center gap-2 rounded-full border border-border bg-card px-3 py-1.5 shadow-lg">
+ <Spinner className="h-3.5 w-3.5" />
+ <span className="whitespace-nowrap text-xs font-medium text-foreground">
+ Planning motion…
+ </span>
+ <cancelPlanFetcher.Form
+ method="post"
+ action={path.to.assemblyJobsCancel(id!)}
>
- Cancel
- </button>
- </cancelPlanFetcher.Form>
- </div>
- )}
- {glbPath && graphPath ? (
- <ClientOnly
- fallback={
- <div className="flex h-full w-full items-center justify-center">
- <Spinner className="h-10 w-10" />
- </div>
- }
- >
- {() => (
- <AssemblyPlayer
- ref={playerRef}
- glbUrl={getPrivateUrl(glbPath)}
- graphUrl={getPrivateUrl(graphPath)}
- steps={viewerSteps}
- scopeStepIds={scopeStepIds}
- isolationLabel={isolationLabel}
- carryInLabel={carryInLabel}
- activeStepIndex={Math.max(playerStepIndex, 0)}
- playFromStepIndex={playFromStepIndex}
- playStepNonce={playStepNonce}
- onStepChange={(index) => {
- const step = steps[index];
- if (step)
- onSelectStep(step.id, {
- selectComponents: false
- });
- }}
- onSelectComponents={onSelectComponents}
- onGraphLoaded={setGraph}
- highlightedNodeIds={selectedNodeIds}
- focusedNodeIds={focusedNodeIds}
- readOnly={isDisabled}
- editMotion={
- editingStepId &&
- selectedStep?.id === editingStepId &&
- draftMotion
- ? { stepId: editingStepId, motion: draftMotion }
- : null
- }
- onMotionChange={onMotionChange}
- units={namedUnits}
- suppressFallbackMotions={isPlanning}
- componentPickerActive={isAddingComponents}
- autoPlay={false}
- mode={mode}
- className="h-full"
- />
- )}
- </ClientOnly>
- ) : (isActivelyConverting || isAwaitingPickup) &&
- modelUpload?.id ? (
- <ModelConvertProgress
- modelUploadId={modelUpload.id}
- instructionId={id!}
- />
- ) : modelUpload?.processingStatus === "Failed" ? (
- <Empty>
- <p className="text-sm font-medium text-foreground">
- Couldn't prepare this model
- </p>
- <p className="max-w-[320px] text-center text-sm text-muted-foreground">
- {modelUpload?.processingError ??
- "Something went wrong converting the CAD file for 3D viewing."}
- </p>
- <retryFetcher.Form
- method="post"
- action={path.to.assemblyModelConvert(id!)}
+ <input type="hidden" name="kind" value="plan" />
+ <button
+ type="submit"
+ disabled={cancelPlanFetcher.state !== "idle"}
+ className="text-xs text-muted-foreground underline-offset-2 hover:text-foreground hover:underline disabled:opacity-50"
+ >
+ Cancel
+ </button>
+ </cancelPlanFetcher.Form>
+ </div>
+ )}
+ {glbPath && graphPath ? (
+ <ClientOnly
+ fallback={
+ <div className="flex h-full w-full items-center justify-center">
+ <Spinner className="h-10 w-10" />
+ </div>
+ }
>
- <Button
- type="submit"
- variant="secondary"
- isLoading={retryFetcher.state !== "idle"}
- isDisabled={
- retryFetcher.state !== "idle" ||
- !permissions.can("update", "production")
- }
+ {() => (
+ <AssemblyPlayer
+ ref={playerRef}
+ glbUrl={getPrivateUrl(glbPath)}
+ graphUrl={getPrivateUrl(graphPath)}
+ steps={viewerSteps}
+ scopeStepIds={scopeStepIds}
+ isolationLabel={isolationLabel}
+ carryInLabel={carryInLabel}
+ activeStepIndex={Math.max(playerStepIndex, 0)}
+ playFromStepIndex={playFromStepIndex}
+ playStepNonce={playStepNonce}
+ onStepChange={(index) => {
+ const step = steps[index];
+ if (step)
+ onSelectStep(step.id, {
+ selectComponents: false
+ });
+ }}
+ onSelectComponents={onSelectComponents}
+ onGraphLoaded={setGraph}
+ highlightedNodeIds={selectedNodeIds}
+ focusedNodeIds={focusedNodeIds}
+ readOnly={isDisabled}
+ editMotion={
+ editingStepId &&
+ selectedStep?.id === editingStepId &&
+ draftMotion
+ ? { stepId: editingStepId, motion: draftMotion }
+ : null
+ }
+ onMotionChange={onMotionChange}
+ units={namedUnits}
+ suppressFallbackMotions={isPlanning}
+ componentPickerActive={isAddingComponents}
+ autoPlay={false}
+ mode={mode}
+ className="h-full"
+ />
+ )}
+ </ClientOnly>
+ ) : (isActivelyConverting || isAwaitingPickup) &&
+ modelUpload?.id ? (
+ <ModelConvertProgress
+ modelUploadId={modelUpload.id}
+ instructionId={id!}
+ />
+ ) : modelUpload?.processingStatus === "Failed" ? (
+ <Empty>
+ <p className="text-sm font-medium text-foreground">
+ Couldn't prepare this model
+ </p>
+ <p className="max-w-[320px] text-center text-sm text-muted-foreground">
+ {modelUpload?.processingError ??
+ "Something went wrong converting the CAD file for 3D viewing."}
+ </p>
+ <retryFetcher.Form
+ method="post"
+ action={path.to.assemblyModelConvert(id!)}
>
- Try again
- </Button>
- </retryFetcher.Form>
- </Empty>
- ) : (
- <Empty>
- <p className="text-sm font-medium text-foreground">
- Model not ready yet
- </p>
- <p className="max-w-[320px] text-center text-sm text-muted-foreground">
- This model hasn't been prepared for 3D viewing. It'll
- appear here once processing starts.
- </p>
- </Empty>
- )}
+ <Button
+ type="submit"
+ variant="secondary"
+ isLoading={retryFetcher.state !== "idle"}
+ isDisabled={
+ retryFetcher.state !== "idle" ||
+ !permissions.can("update", "production")
+ }
+ >
+ Try again
+ </Button>
+ </retryFetcher.Form>
+ </Empty>
+ ) : (
+ <Empty>
+ <p className="text-sm font-medium text-foreground">
+ Model not ready yet
+ </p>
+ <p className="max-w-[320px] text-center text-sm text-muted-foreground">
+ This model hasn't been prepared for 3D viewing. It'll
+ appear here once processing starts.
+ </p>
+ </Empty>
+ )}
+ </div>
</div>
}
properties={