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.

fix(nav): collapse the rail on unpin; links between the ERP and the MES (#1980)

BettrCallRaul76cf4b8d07e1
diff --git a/apps/erp/app/components/Layout/Navigation/PrimaryNavigation.tsx b/apps/erp/app/components/Layout/Navigation/PrimaryNavigation.tsx
index 326077eb8d..321d75c3ab 100644
--- a/apps/erp/app/components/Layout/Navigation/PrimaryNavigation.tsx
+++ b/apps/erp/app/components/Layout/Navigation/PrimaryNavigation.tsx
@@ -80,6 +80,8 @@ const renderLink = (
label={link.name}
tag={link.tag}
external={link.external}
+ target={link.newTab ? "_blank" : undefined}
+ rel={link.newTab ? "noopener noreferrer" : undefined}
isActive={isActive}
trailing={goToKey ? <GoToHint goToKey={goToKey} /> : undefined}
/>
diff --git a/apps/erp/app/hooks/useModules.tsx b/apps/erp/app/hooks/useModules.tsx
index 1645aec7db..35d32da76f 100644
--- a/apps/erp/app/hooks/useModules.tsx
+++ b/apps/erp/app/hooks/useModules.tsx
@@ -141,7 +141,8 @@ function useModuleDefinitions(): ModuleDefinition[] {
to: path.to.external.mes,
icon: LuTvMinimalPlay,
role: "employee",
- external: true
+ external: true,
+ newTab: true
},
{
key: "users",
diff --git a/apps/erp/app/modules/production/ui/Jobs/JobHeader.tsx b/apps/erp/app/modules/production/ui/Jobs/JobHeader.tsx
index 653a5365ba..55a4f26be2 100644
--- a/apps/erp/app/modules/production/ui/Jobs/JobHeader.tsx
+++ b/apps/erp/app/modules/production/ui/Jobs/JobHeader.tsx
@@ -65,6 +65,7 @@ import {
LuTable,
LuTrash,
LuTriangleAlert,
+ LuTvMinimalPlay,
LuWorkflow,
LuZap
} from "react-icons/lu";
@@ -372,6 +373,23 @@ const JobHeader = () => {
</Button>
</RecordAction>
)}
+ {["Ready", "In Progress", "Paused"].includes(status ?? "") && (
+ <RecordAction slot="overflow">
+ <Button
+ leftIcon={<LuTvMinimalPlay />}
+ variant="secondary"
+ asChild
+ >
+ <a
+ href={path.to.external.mesJob(jobId)}
+ target="_blank"
+ rel="noopener noreferrer"
+ >
+ <Trans>Open in MES</Trans>
+ </a>
+ </Button>
+ </RecordAction>
+ )}
<RecordAction slot="overflow">
<DropdownMenu>
<DropdownMenuTrigger asChild>
diff --git a/apps/erp/app/types/index.ts b/apps/erp/app/types/index.ts
index e23b35fdfc..bdfb932e81 100644
--- a/apps/erp/app/types/index.ts
+++ b/apps/erp/app/types/index.ts
@@ -70,6 +70,8 @@ export type NavItem = Omit<Route, "icon"> & {
backgroundColor?: string;
foregroundColor?: string;
external?: boolean;
+ /** Opens in a new tab, leaving this one where it was. */
+ newTab?: boolean;
};
export type Result = {
diff --git a/apps/erp/app/utils/path.ts b/apps/erp/app/utils/path.ts
index 7fc0e5e168..b3a3149b86 100644
--- a/apps/erp/app/utils/path.ts
+++ b/apps/erp/app/utils/path.ts
@@ -1114,6 +1114,7 @@ export const path = {
external: {
mes: MES_URL,
mesBatch: (id: string) => `${MES_URL}/x/batch/${id}`,
+ mesJob: (id: string) => `${MES_URL}/x/job/${id}`,
mesJobOperation: (id: string) => `${MES_URL}/x/operation/${id}`,
mesJobOperationComplete: (id: string) => `${MES_URL}/x/end/${id}`,
mesJobOperationStart: (id: string, type: "Setup" | "Labor" | "Machine") =>
diff --git a/apps/mes/app/components/AppSidebar.tsx b/apps/mes/app/components/AppSidebar.tsx
index 1e8751b89d..26124d3739 100644
--- a/apps/mes/app/components/AppSidebar.tsx
+++ b/apps/mes/app/components/AppSidebar.tsx
@@ -29,6 +29,7 @@ import { useLingui } from "@lingui/react/macro";
import { Suspense, useMemo } from "react";
import {
LuActivity,
+ LuArrowLeft,
LuArrowUpRight,
LuCalendarDays,
LuChevronsUpDown,
@@ -162,6 +163,7 @@ export function AppSidebar({
}
footer={
<>
+ <BackToErpLink />
{timeCard}
<UserNav
consoleEnabled={consoleEnabled}
@@ -266,6 +268,23 @@ function CompanyLink({ company }: { company: Company }) {
);
}
+/**
+ * A labelled way back to the ERP, in the same tab. Desktop and tablet only:
+ * on phones the company row at the top of the More sheet leads there.
+ */
+function BackToErpLink() {
+ const { t } = useLingui();
+
+ return (
+ <NavRailLink
+ to={ERP_URL}
+ icon={<LuArrowLeft />}
+ label={t`Back to ERP`}
+ external
+ />
+ );
+}
+
export type QueueKey = keyof typeof MES_NAV_SHORTCUTS;
/** The task queues, in rail order; each one's ⌥-digit comes from its key. */
diff --git a/packages/locale/locales/de/mes.po b/packages/locale/locales/de/mes.po
index f6f7c8fb31..11a6176789 100644
--- a/packages/locale/locales/de/mes.po
+++ b/packages/locale/locales/de/mes.po
@@ -272,6 +272,9 @@ msgstr "Zurück"
msgid "Back to batch"
msgstr "Zurück zum Los"
+msgid "Back to ERP"
+msgstr "Zurück zum ERP"
+
msgid "Background"
msgstr "Hintergrund"
diff --git a/packages/locale/locales/en/mes.po b/packages/locale/locales/en/mes.po
index d1acfa7660..619a5f5a0b 100644
--- a/packages/locale/locales/en/mes.po
+++ b/packages/locale/locales/en/mes.po
@@ -272,6 +272,9 @@ msgstr "Back"
msgid "Back to batch"
msgstr "Back to batch"
+msgid "Back to ERP"
+msgstr "Back to ERP"
+
msgid "Background"
msgstr "Background"
diff --git a/packages/locale/locales/es/mes.po b/packages/locale/locales/es/mes.po
index c87beae4c4..41c219aa13 100644
--- a/packages/locale/locales/es/mes.po
+++ b/packages/locale/locales/es/mes.po
@@ -272,6 +272,9 @@ msgstr "Atrás"
msgid "Back to batch"
msgstr "Volver al lote de producción"
+msgid "Back to ERP"
+msgstr "Volver al ERP"
+
msgid "Background"
msgstr "Fondo"
diff --git a/packages/locale/locales/fr/mes.po b/packages/locale/locales/fr/mes.po
index 2805b8e41d..db5e157b20 100644
--- a/packages/locale/locales/fr/mes.po
+++ b/packages/locale/locales/fr/mes.po
@@ -272,6 +272,9 @@ msgstr "Retour"
msgid "Back to batch"
msgstr "Retour au lot de production"
+msgid "Back to ERP"
+msgstr "Retour à l'ERP"
+
msgid "Background"
msgstr "Arrière-plan"
diff --git a/packages/locale/locales/hi/mes.po b/packages/locale/locales/hi/mes.po
index 00d70cf9e6..11cefb82cd 100644
--- a/packages/locale/locales/hi/mes.po
+++ b/packages/locale/locales/hi/mes.po
@@ -272,6 +272,9 @@ msgstr "वापस"
msgid "Back to batch"
msgstr "बैच पर वापस"
+msgid "Back to ERP"
+msgstr "ERP पर वापस"
+
msgid "Background"
msgstr "पृष्ठभूमि"
diff --git a/packages/locale/locales/it/mes.po b/packages/locale/locales/it/mes.po
index a465093efc..dfdd801c32 100644
--- a/packages/locale/locales/it/mes.po
+++ b/packages/locale/locales/it/mes.po
@@ -272,6 +272,9 @@ msgstr "Indietro"
msgid "Back to batch"
msgstr "Torna al lotto di produzione"
+msgid "Back to ERP"
+msgstr "Torna all'ERP"
+
msgid "Background"
msgstr "Sfondo"
diff --git a/packages/locale/locales/ja/mes.po b/packages/locale/locales/ja/mes.po
index 9fef9b49a4..7cea5b80aa 100644
--- a/packages/locale/locales/ja/mes.po
+++ b/packages/locale/locales/ja/mes.po
@@ -272,6 +272,9 @@ msgstr "戻る"
msgid "Back to batch"
msgstr "バッチへ戻る"
+msgid "Back to ERP"
+msgstr "ERP へ戻る"
+
msgid "Background"
msgstr "背景"
diff --git a/packages/locale/locales/ko/mes.po b/packages/locale/locales/ko/mes.po
index 13864a224a..a08ed0cc87 100644
--- a/packages/locale/locales/ko/mes.po
+++ b/packages/locale/locales/ko/mes.po
@@ -272,6 +272,9 @@ msgstr "뒤로"
msgid "Back to batch"
msgstr "배치로 돌아가기"
+msgid "Back to ERP"
+msgstr "ERP로 돌아가기"
+
msgid "Background"
msgstr "배경"
diff --git a/packages/locale/locales/pl/mes.po b/packages/locale/locales/pl/mes.po
index efa4be361b..9441334b01 100644
--- a/packages/locale/locales/pl/mes.po
+++ b/packages/locale/locales/pl/mes.po
@@ -272,6 +272,9 @@ msgstr "Wstecz"
msgid "Back to batch"
msgstr "Powrót do partii produkcyjnej"
+msgid "Back to ERP"
+msgstr "Powrót do ERP"
+
msgid "Background"
msgstr "Tło"
diff --git a/packages/locale/locales/pt/mes.po b/packages/locale/locales/pt/mes.po
index 0c0d04ba7a..9d4f0de7df 100644
--- a/packages/locale/locales/pt/mes.po
+++ b/packages/locale/locales/pt/mes.po
@@ -272,6 +272,9 @@ msgstr "Voltar"
msgid "Back to batch"
msgstr "Voltar ao lote de produção"
+msgid "Back to ERP"
+msgstr "Voltar ao ERP"
+
msgid "Background"
msgstr "Fundo"
diff --git a/packages/locale/locales/ru/mes.po b/packages/locale/locales/ru/mes.po
index 28771a3753..244b9274e0 100644
--- a/packages/locale/locales/ru/mes.po
+++ b/packages/locale/locales/ru/mes.po
@@ -272,6 +272,9 @@ msgstr "Назад"
msgid "Back to batch"
msgstr "Вернуться к серии"
+msgid "Back to ERP"
+msgstr "Вернуться в ERP"
+
msgid "Background"
msgstr "Фон"
diff --git a/packages/locale/locales/tr/mes.po b/packages/locale/locales/tr/mes.po
index 3a9a62ae6f..597ee16a47 100644
--- a/packages/locale/locales/tr/mes.po
+++ b/packages/locale/locales/tr/mes.po
@@ -272,6 +272,9 @@ msgstr "Geri"
msgid "Back to batch"
msgstr "Partiye geri dön"
+msgid "Back to ERP"
+msgstr "ERP'ye geri dön"
+
msgid "Background"
msgstr "Arka plan"
diff --git a/packages/locale/locales/zh/mes.po b/packages/locale/locales/zh/mes.po
index 95d8b2923f..d36fcecb50 100644
--- a/packages/locale/locales/zh/mes.po
+++ b/packages/locale/locales/zh/mes.po
@@ -272,6 +272,9 @@ msgstr "返回"
msgid "Back to batch"
msgstr "返回生产批次"
+msgid "Back to ERP"
+msgstr "返回 ERP"
+
msgid "Background"
msgstr "背景"
diff --git a/packages/react/AGENTS.md b/packages/react/AGENTS.md
index 80ddbcde91..bf317a003b 100644
--- a/packages/react/AGENTS.md
+++ b/packages/react/AGENTS.md
@@ -43,7 +43,7 @@ import { Button, Card, HStack, VStack, IconButton, cn } from "@carbon/react";
- **Layout**: `VStack` / `HStack` with numeric `spacing` prop (maps to `space-y-*`/`space-x-*`)
- **Overlays**: `Drawer`, `Modal`, `ModalDrawer` (unified drawer/modal), `BottomSheet`, `Popover`. A controlled `Modal`/`Drawer` with no `onOpenChange` cannot be dismissed and shows no close button; never pass a handler that does nothing (`no-noop-open-change` check). A route rendered as a modal or drawer closes with `useCloseRoute()` (back when this tab has history, else the parent route), not `navigate(-1)`
- **Status**: `iconOnly` renders just the coloured icon, with the label in an always-on tooltip and as the `aria-label` (string children only) — for dense rows and narrow drawers. `TooltipContent` takes `anchor` to position against a different element than the trigger, when one tooltip serves many small hover targets (a strip of bars)
-- **App nav**: `NavRail` is the primary left nav of both the ERP and MES shells (56px icon rail, grows to 240px after a 150ms mouse hover or when pinned, left drawer below md that closes itself on navigation). The rail renders a pin toggle beside its `header` while expanded (it calls `SidebarProvider`'s `toggleSidebar`; ⌘B also pins, unless the provider gets `keyboardShortcut={false}`). The pin is not persisted: both apps pass `defaultOpen={false}`, and the provider writes no cookie (see `.ai/lessons.md`, "A cookie that was only ever written"). Optional `header` and `footer` slots; the header is a `NavRailSwitcher` — the company's logo (`logoLight`/`logoDark`, falling back to an initials `Avatar`) in the icon column with its name fading in, a menu trigger or, with `asChild`, a link, and a full-width row on phones; `NavRailGroup` adds a titled section that shows as a divider while collapsed. Entries are `NavRailItem` (a button, or `asChild` for a trigger/link) and `NavRailLink`; `label` is a string and doubles as the accessible name. A Radix menu/popover opened from a `NavRailItem` or `NavRailSwitcher` keeps the rail as it was (open or collapsed) until it closes. Render inside `SidebarProvider`; the shadcn-style `Sidebar*` primitives remain for other layouts
+- **App nav**: `NavRail` is the primary left nav of both the ERP and MES shells (56px icon rail, grows to 240px after a 150ms mouse hover or when pinned, left drawer below md that closes itself on navigation). The rail renders a pin toggle beside its `header` while expanded (it calls `SidebarProvider`'s `toggleSidebar`; ⌘B also pins, unless the provider gets `keyboardShortcut={false}`). Unpinning (the toggle, ⌘B or a page's `SidebarTrigger`) collapses the rail at once, also under the mouse; hover cannot reopen it until the pointer leaves the rail. The pin is not persisted: both apps pass `defaultOpen={false}`, and the provider writes no cookie (see `.ai/lessons.md`, "A cookie that was only ever written"). Optional `header` and `footer` slots; the header is a `NavRailSwitcher` — the company's logo (`logoLight`/`logoDark`, falling back to an initials `Avatar`) in the icon column with its name fading in, a menu trigger or, with `asChild`, a link, and a full-width row on phones; `NavRailGroup` adds a titled section that shows as a divider while collapsed. Entries are `NavRailItem` (a button, or `asChild` for a trigger/link) and `NavRailLink`; `label` is a string and doubles as the accessible name. A Radix menu/popover opened from a `NavRailItem` or `NavRailSwitcher` keeps the rail as it was (open or collapsed) until it closes. Render inside `SidebarProvider`; the shadcn-style `Sidebar*` primitives remain for other layouts
- **Links that prefetch**: `PrefetchLink` is a React Router `Link` that prefetches its destination when the pointer goes down on it. Use it instead of `<Link prefetch="intent">`, which prefetches on a 100 ms hover and so runs a page's loaders for every row the mouse passes over. The click reuses the prefetch only because `prefetchCacheMiddleware` (`@carbon/utils`, in each app's root `middleware`) gives a prefetch response a few seconds of private cache; without it both requests reach the server and the click waits behind the prefetch. `NavRailLink` and both apps' `Hyperlink` already use it
- **Record outlet**: `RecordOutlet` is the `<Outlet>` of every route under `/x`. It remounts the page inside it when that page is shown for a different record (the params of the route in the outlet, not of a drawer below it), so nothing seeded from the previous record survives. A plain `<Outlet>` there fails the `no-bare-outlet` check
- **Data**: `Table` (TanStack), chart components via sub-exports (`@carbon/react/Chart`)
diff --git a/packages/react/src/NavRail.tsx b/packages/react/src/NavRail.tsx
index 0c2acb53d7..43fd87e9dc 100644
--- a/packages/react/src/NavRail.tsx
+++ b/packages/react/src/NavRail.tsx
@@ -138,6 +138,23 @@ export function NavRail({
return () => setHolds((n) => n - 1);
}, []);
+ // The rail is expanded while pinned OR hovered, and the toggle sits inside
+ // it, so unpinning alone changed nothing: hover still held it open. An
+ // unpin (the toggle, ⌘B or a page's `SidebarTrigger`) drops the hover too,
+ // and a mouse still over the rail cannot reopen it until it leaves.
+ const hoverSuppressed = useRef(false);
+ const wasOpen = useRef(open);
+ useEffect(() => {
+ if (wasOpen.current && !open) {
+ cancelHoverOpen();
+ setHovered(false);
+ hoverSuppressed.current =
+ lastPointerType.current === "mouse" &&
+ (navRef.current?.matches(":hover") ?? false);
+ }
+ wasOpen.current = open;
+ }, [open, cancelHoverOpen]);
+
// Links, go-to shortcuts and redirects all land here: whatever navigated,
// the phone drawer must not stay over the destination.
// biome-ignore lint/correctness/useExhaustiveDependencies: runs per navigation
@@ -162,12 +179,15 @@ export function NavRail({
}
// Touch browsers leave `:hover` stuck on the last tapped element, so only
// a mouse's `:hover` counts.
- const raf = requestAnimationFrame(() =>
- setHovered(
+ const raf = requestAnimationFrame(() => {
+ const over =
lastPointerType.current === "mouse" &&
- (navRef.current?.matches(":hover") ?? false)
- )
- );
+ (navRef.current?.matches(":hover") ?? false);
+ // The pointer left while blocked: the leave was ignored, so end a
+ // collapse's hold-off here.
+ if (!over) hoverSuppressed.current = false;
+ setHovered(over && !hoverSuppressed.current);
+ });
return () => cancelAnimationFrame(raf);
}, [hoverBlocked, cancelHoverOpen, moveHoverCard]);
@@ -279,7 +299,7 @@ export function NavRail({
onPointerMove={(event) => {
lastPointerType.current = event.pointerType;
if (hoverBlocked || hovered || openTimer.current) return;
- if (event.pointerType !== "mouse") return;
+ if (event.pointerType !== "mouse" || hoverSuppressed.current) return;
openTimer.current = setTimeout(() => {
openTimer.current = undefined;
setHovered(true);
@@ -296,6 +316,7 @@ export function NavRail({
// The leave a Radix layer causes by disabling body pointer-events
// can arrive before this render knows about the hold.
if (document.body.style.pointerEvents === "none") return;
+ hoverSuppressed.current = false;
cancelHoverOpen();
setHovered(false);
moveHoverCard(null);