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.

refactor(items): one source of truth for supersession mode color + label

Brad Barbin5c65da098818
diff --git a/apps/erp/app/components/ItemLifecycleBadge.tsx b/apps/erp/app/components/ItemLifecycleBadge.tsx
index bd09302f8b..f1baa44d42 100644
--- a/apps/erp/app/components/ItemLifecycleBadge.tsx
+++ b/apps/erp/app/components/ItemLifecycleBadge.tsx
@@ -1,9 +1,9 @@
import { Status } from "@carbon/react";
import { getItemLifecycleStatus } from "~/modules/items/ui/Item/ItemSupersessionForm";
-// Small supersession lifecycle badge (Phase-out / Spares only / Obsolete),
-// reused wherever an item is selected or displayed. Renders nothing for parts
-// with no supersession set.
+// Small supersession lifecycle badge showing the item's supersession mode
+// (Consume First / Prefer New / Stock Only / No Stock), reused wherever an item
+// is selected or displayed. Renders nothing for parts with no supersession set.
export function ItemLifecycleBadge({
mode
}: {
diff --git a/apps/erp/app/modules/items/ui/Item/ItemSupersessionForm.tsx b/apps/erp/app/modules/items/ui/Item/ItemSupersessionForm.tsx
index ffe86e9c04..8d9d165644 100644
--- a/apps/erp/app/modules/items/ui/Item/ItemSupersessionForm.tsx
+++ b/apps/erp/app/modules/items/ui/Item/ItemSupersessionForm.tsx
@@ -31,38 +31,40 @@ import {
type SupersessionMode = (typeof supersessionModes)[number];
-const modeDescriptions: Record<SupersessionMode, string> = {
- "Consume First": "Use remaining stock before switching to the successor",
- "Prefer New": "Default to the successor; old part as fallback only",
- "Stock Only": "Hold a minimum reserve for service; no production use",
- "No Stock": "Fully obsolete — do not plan or stock"
-};
-
-const modeStatusColor: Record<
+// Single source of truth for how each supersession mode is presented — the same
+// color is used everywhere the mode shows up (the mode picker options and the
+// item lifecycle badge), so the two never drift.
+const supersessionModeMeta: Record<
SupersessionMode,
- "green" | "blue" | "orange" | "red"
+ { color: "green" | "blue" | "orange" | "red"; description: string }
> = {
- "Consume First": "green",
- "Prefer New": "blue",
- "Stock Only": "orange",
- "No Stock": "red"
+ "Consume First": {
+ color: "green",
+ description: "Use remaining stock before switching to the successor"
+ },
+ "Prefer New": {
+ color: "blue",
+ description: "Default to the successor; old part as fallback only"
+ },
+ "Stock Only": {
+ color: "orange",
+ description: "Hold a minimum reserve for service; no production use"
+ },
+ "No Stock": {
+ color: "red",
+ description: "Fully obsolete — do not plan or stock"
+ }
};
// Derived lifecycle status shown on the item header (PRD: Active has no badge).
+// Labelled with the mode name so it matches the mode picker exactly.
export function getItemLifecycleStatus(
mode: SupersessionMode | null | undefined
-): { label: string; color: "orange" | "gray" | "red" } | null {
- switch (mode) {
- case "Consume First":
- case "Prefer New":
- return { label: "Phase-out", color: "orange" };
- case "Stock Only":
- return { label: "Spares only", color: "gray" };
- case "No Stock":
- return { label: "Obsolete", color: "red" };
- default:
- return null;
- }
+): { label: string; color: "green" | "blue" | "orange" | "red" } | null {
+ if (!mode) return null;
+ const meta = supersessionModeMeta[mode];
+ if (!meta) return null;
+ return { label: mode, color: meta.color };
}
type SupersessionChainLink = {
@@ -165,10 +167,14 @@ const ItemSupersessionForm = ({
label={t`Supersession Mode`}
termId="supersession-mode"
placeholder={t`None`}
- helperText={mode ? modeDescriptions[mode] : undefined}
+ helperText={
+ mode ? supersessionModeMeta[mode].description : undefined
+ }
options={supersessionModes.map((value) => ({
label: (
- <Status color={modeStatusColor[value]}>{value}</Status>
+ <Status color={supersessionModeMeta[value].color}>
+ {value}
+ </Status>
),
value
}))}