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(ui): company switcher and pin toggle in the navigation rail (#1911)

Brad Barbin3855debf912b
diff --git a/.ai/lessons.md b/.ai/lessons.md
index 35b6fcfe8b..cf7a1f302f 100644
--- a/.ai/lessons.md
+++ b/.ai/lessons.md
@@ -3637,3 +3637,15 @@ A ✓ that a script prints after a step that is allowed to fail is not evidence.
**Applies to:** `apps/erp/app/routes/api+/v1+/lib/base.server.ts`, `apps/erp/app/routes/api+/mcp+/_index.ts`, every `@mcp`-tagged service taking `db: Kysely<KyselyDatabase>`.
+
+## A cookie that was only ever written is not a stored preference
+
+**Context:** The navigation rail's pin toggle (2026-10-13) first restored the pinned state from `SidebarProvider`'s `sidebar:state` cookie.
+
+**Problem:** `SidebarProvider` (`packages/react/src/Sidebar.tsx`) had written that cookie on every open/close for a long time, but no loader read it. Old sessions already held `sidebar:state=true` from a `SidebarTrigger` or ⌘B, so reading it opened the rail for users who had never pinned it.
+
+The write was then removed (nothing reads it), so the rail always starts collapsed.
+
+**Rule:** Do not start reading a cookie, local-storage key or column that code has only ever written. Its values were never a user's deliberate choice. Give the new preference a new name, or start every user from the default.
+
+**Applies to:** `SidebarProvider` and any other write-only client state (`document.cookie`, `localStorage`) that a loader or component begins to read.
diff --git a/.claude/skills/carbon-design/references/page-archetypes.md b/.claude/skills/carbon-design/references/page-archetypes.md
index 9f4b12fe44..2a52bb972e 100644
--- a/.claude/skills/carbon-design/references/page-archetypes.md
+++ b/.claude/skills/carbon-design/references/page-archetypes.md
@@ -29,15 +29,17 @@ unless they start with `apps/` or `packages/`.
```
┌──────┬──────────────────────────────────────────────────────────────────┐
│ RAIL │ ╭ content panel: bg-card, md:inset + rounded-2xl + border ───────╮ │
-│ w-14 │ │ TOPBAR 49px Company ▾ / Module / List / ID ✎ 🔔 Avatar │ │
-│ ⌕ │ ├────────────────────────────────────────────────────────────────┤ │
-│ mods │ │ <main> module layout (sub-nav + Outlet) or document workspace │ │
+│ w-14 │ │ TOPBAR 49px Module / List / ID ✎ 🔔 Avatar │ │
+│ Co ▾ │ ├────────────────────────────────────────────────────────────────┤ │
+│ ⌕ │ │ <main> module layout (sub-nav + Outlet) or document workspace │ │
+│ mods │ │ │ │
│ ⚙ │ ╰────────────────────────────────────────────────────────────────╯ │
└──────┴──────────────────────────────────────────────────────────────────┘
```
- Shell: `routes/x+/_layout.tsx`. Rail: `components/Layout/Navigation/PrimaryNavigation.tsx`,
built on the shared `NavRail` from `@carbon/react` (the same rail MES uses): icon rail that
- expands on mouse hover or when pinned with ⌘B, and pushes content. Modules are registered in `hooks/useModules.tsx`
+ expands on mouse hover or when pinned with the toggle beside the company switcher
+ (`Navigation/CompanySwitcher.tsx`, the rail's header), and pushes content. Modules are registered in `hooks/useModules.tsx`
(`{ key, permission, name, to, icon }`, Lucide icons, Settings pinned bottom).
- Topbar: breadcrumbs (from route `handle`), global ✎ Create menu
(`components/Layout/Topbar/CreateMenu.tsx`), notifications, avatar.
diff --git a/apps/erp/app/components/Breadcrumb.tsx b/apps/erp/app/components/Breadcrumb.tsx
index f31486705e..b05933739d 100644
--- a/apps/erp/app/components/Breadcrumb.tsx
+++ b/apps/erp/app/components/Breadcrumb.tsx
@@ -5,7 +5,7 @@
import { Button, cn, getValidChildren, PrefetchLink } from "@carbon/react";
import { useLingui } from "@lingui/react/macro";
import type { ComponentProps } from "react";
-import { cloneElement, forwardRef } from "react";
+import { cloneElement, createContext, forwardRef, useContext } from "react";
import type { LinkProps } from "react-router";
const Breadcrumbs = forwardRef<
@@ -36,6 +36,10 @@ const Breadcrumbs = forwardRef<
});
Breadcrumbs.displayName = "Breadcrumbs";
+// Whether the item a link sits in is the trail's last. Only the last crumb
+// (the current page) reads at full strength.
+const BreadcrumbPositionContext = createContext({ isLastChild: true });
+
const BreadcrumbItem = forwardRef<
HTMLLIElement,
ComponentProps<"li"> & {
@@ -49,7 +53,11 @@ const BreadcrumbItem = forwardRef<
{...props}
>
{!isFirstChild && <span className="text-muted-foreground">/</span>}
- {children}
+ <BreadcrumbPositionContext.Provider
+ value={{ isLastChild: isLastChild ?? true }}
+ >
+ {children}
+ </BreadcrumbPositionContext.Provider>
</li>
));
BreadcrumbItem.displayName = "BreadcrumbItem";
@@ -60,11 +68,13 @@ const BreadcrumbLink = forwardRef<
isCurrentPage?: boolean;
}
>(({ className, children, isCurrentPage, ...props }, ref) => {
+ const { isLastChild } = useContext(BreadcrumbPositionContext);
return (
<Button
variant="ghost"
className={cn(
"px-2 outline-none focus-visible:ring-transparent",
+ !isLastChild && "text-muted-foreground hover:text-foreground",
className
)}
asChild
diff --git a/apps/erp/app/components/Layout/Mobile/MobileMenu.tsx b/apps/erp/app/components/Layout/Mobile/MobileMenu.tsx
index db54aaed0f..ed870ee294 100644
--- a/apps/erp/app/components/Layout/Mobile/MobileMenu.tsx
+++ b/apps/erp/app/components/Layout/Mobile/MobileMenu.tsx
@@ -42,17 +42,17 @@ import {
useSettingsModule
} from "~/hooks/useModules";
import { path } from "~/utils/path";
+import { AddCompanyModal } from "../Navigation/AddCompanyModal";
import { useCompactModuleSidebar } from "../Navigation/CollapsibleSidebar";
+import {
+ useCompanyGroups,
+ useCompanySwitchRedirect
+} from "../Navigation/CompanySwitcher";
import { getModule } from "../Navigation/PrimaryNavigation";
import {
SheetNavStyleProvider,
SidebarPresentationProvider
} from "../Navigation/SidebarPresentation";
-import { AddCompanyModal } from "../Topbar/AddCompanyModal";
-import {
- useCompanyGroups,
- useCompanySwitchRedirect
-} from "../Topbar/CompanySwitcher";
/** The switcher whose finder covers the menu, if any. */
type Finder = "companies" | "modules";
@@ -179,7 +179,7 @@ function ModuleRows({ currentKey }: { currentKey: string | null }) {
/**
* The company switcher's finder: every company the user belongs to, the
* current one ticked, then Add Company for an admin (the desktop
- * breadcrumb's rule). Picking a company switches to it.
+ * rail switcher's rule). Picking a company switches to it.
*/
function CompanyFinder({
onClose,
diff --git a/apps/erp/app/components/Layout/Mobile/ProfileSheet.tsx b/apps/erp/app/components/Layout/Mobile/ProfileSheet.tsx
index 7be12e9551..eb34c4997e 100644
--- a/apps/erp/app/components/Layout/Mobile/ProfileSheet.tsx
+++ b/apps/erp/app/components/Layout/Mobile/ProfileSheet.tsx
@@ -33,7 +33,7 @@ import { path } from "~/utils/path";
import {
useCompanyGroups,
useCompanySwitchRedirect
-} from "../Topbar/CompanySwitcher";
+} from "../Navigation/CompanySwitcher";
import { NotificationsPanel } from "../Topbar/Notifications";
import { SheetRowButton, SheetRowContent, SheetRowGroup } from "./SheetRow";
diff --git a/apps/erp/app/components/Layout/Topbar/AddCompanyModal.tsx b/apps/erp/app/components/Layout/Navigation/AddCompanyModal.tsx
similarity index 100%
rename from apps/erp/app/components/Layout/Topbar/AddCompanyModal.tsx
rename to apps/erp/app/components/Layout/Navigation/AddCompanyModal.tsx
diff --git a/apps/erp/app/components/Layout/Navigation/CompanySwitcher.tsx b/apps/erp/app/components/Layout/Navigation/CompanySwitcher.tsx
new file mode 100644
index 0000000000..249912047d
--- /dev/null
+++ b/apps/erp/app/components/Layout/Navigation/CompanySwitcher.tsx
@@ -0,0 +1,194 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,
+// including ports, remain AGPLv3; serving them over a network requires releasing their source.
+
+import {
+ Avatar,
+ Badge,
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuGroup,
+ DropdownMenuIcon,
+ DropdownMenuItem,
+ DropdownMenuLabel,
+ DropdownMenuSeparator,
+ DropdownMenuTrigger,
+ HStack,
+ NavRailSwitcher,
+ ScrollArea,
+ useDisclosure,
+ useMode
+} from "@carbon/react";
+import { useLingui } from "@lingui/react/macro";
+import { useMemo } from "react";
+import { IoMdAdd } from "react-icons/io";
+import { LuChevronsUpDown } from "react-icons/lu";
+import { Form, Link, useLocation, useParams } from "react-router";
+import { useRouteData, useUser } from "~/hooks";
+import type { Company } from "~/modules/settings";
+import { path } from "~/utils/path";
+import { AddCompanyModal } from "./AddCompanyModal";
+
+// Switching company keeps a page that exists in every company (a list, a
+// settings page). A record's page does not, so that goes to the home page.
+export function useCompanySwitchRedirect() {
+ const params = useParams();
+ const { pathname, search } = useLocation();
+ return Object.keys(params).length === 0 ? `${pathname}${search}` : undefined;
+}
+
+/**
+ * The user's companies grouped by company group (single-company groups fold
+ * into "Companies"). Used by the company switcher and the compact Profile sheet.
+ */
+export function useCompanyGroups() {
+ const { t } = useLingui();
+ const routeData = useRouteData<{ company: Company; companies: Company[] }>(
+ path.to.authenticatedRoot
+ );
+ // The ungrouped heading is a translated label, and the fold below must
+ // compare against that same label, not the English source.
+ const ungrouped = t`Companies`;
+ return useMemo(() => {
+ if (!routeData?.companies) return [];
+
+ const groups = new Map<string, { name: string; companies: Company[] }>();
+
+ for (const c of routeData.companies) {
+ const groupName = c.companyGroupName ?? ungrouped;
+ const existing = groups.get(groupName);
+ if (existing) {
+ existing.companies.push(c);
+ } else {
+ groups.set(groupName, { name: groupName, companies: [c] });
+ }
+ }
+
+ // A group of one company folds into the ungrouped heading.
+ const result = new Map<string, { name: string; companies: Company[] }>();
+ for (const [key, group] of groups) {
+ const target = group.companies.length === 1 ? ungrouped : key;
+ const existing = result.get(target);
+ if (existing) {
+ existing.companies.push(...group.companies);
+ } else {
+ result.set(target, { name: target, companies: [...group.companies] });
+ }
+ }
+
+ return Array.from(result.values());
+ }, [routeData?.companies, ungrouped]);
+}
+
+/**
+ * The rail's header: the company's logo and name, which switch company when
+ * the user has more than one (or can add one). Desktop only — phones switch
+ * company from the Profile sheet.
+ */
+const CompanySwitcher = () => {
+ const { t } = useLingui();
+ const switchRedirect = useCompanySwitchRedirect();
+ const routeData = useRouteData<{ company: Company; companies: Company[] }>(
+ path.to.authenticatedRoot
+ );
+ const user = useUser();
+ const mode = useMode();
+ const companyGroups = useCompanyGroups();
+ const companyForm = useDisclosure();
+
+ const hasMultipleCompanies = (routeData?.companies?.length ?? 0) > 1;
+ const canCreateCompany = user.admin === true;
+
+ const brand = {
+ label: user.company.name ?? "",
+ logoLight: user.company.logoLightIcon,
+ logoDark: user.company.logoDarkIcon
+ };
+
+ if (!hasMultipleCompanies && !canCreateCompany) {
+ return (
+ <NavRailSwitcher asChild {...brand}>
+ <Link to={path.to.authenticatedRoot} />
+ </NavRailSwitcher>
+ );
+ }
+
+ return (
+ <>
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <NavRailSwitcher {...brand} trailing={<LuChevronsUpDown />} />
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="start" className="min-w-[240px]">
+ <ScrollArea className="max-h-[300px]">
+ {companyGroups.map((group, index) => (
+ <DropdownMenuGroup key={group.name}>
+ {index > 0 && <DropdownMenuSeparator />}
+ <DropdownMenuLabel>{group.name}</DropdownMenuLabel>
+ <DropdownMenuSeparator />
+ {group.companies.map((c) => {
+ const companyLogo =
+ mode === "dark" ? c.logoDarkIcon : c.logoLightIcon;
+ const isCurrent = c.companyId === user.company.id;
+
+ return (
+ <Form
+ key={c.companyId}
+ method="post"
+ action={path.to.companySwitch(c.companyId!)}
+ >
+ {switchRedirect && (
+ <input
+ type="hidden"
+ name="redirectTo"
+ value={switchRedirect}
+ />
+ )}
+ <DropdownMenuItem
+ className="flex items-center justify-between w-full"
+ asChild
+ disabled={isCurrent}
+ >
+ <button type="submit">
+ <HStack>
+ <Avatar
+ size="xs"
+ name={c.name ?? undefined}
+ src={companyLogo ?? undefined}
+ />
+ <span>{c.name}</span>
+ </HStack>
+ <Badge variant="secondary" className="ml-2">
+ {c.employeeType}
+ </Badge>
+ </button>
+ </DropdownMenuItem>
+ </Form>
+ );
+ })}
+ </DropdownMenuGroup>
+ ))}
+ </ScrollArea>
+
+ {canCreateCompany && (
+ <>
+ <DropdownMenuSeparator />
+ <DropdownMenuGroup>
+ <DropdownMenuItem onClick={companyForm.onOpen}>
+ <DropdownMenuIcon icon={<IoMdAdd />} />
+ {t`Add Company`}
+ </DropdownMenuItem>
+ </DropdownMenuGroup>
+ </>
+ )}
+ </DropdownMenuContent>
+ </DropdownMenu>
+ <AddCompanyModal
+ open={companyForm.isOpen}
+ onClose={companyForm.onClose}
+ />
+ </>
+ );
+};
+
+export default CompanySwitcher;
diff --git a/apps/erp/app/components/Layout/Navigation/PrimaryNavigation.tsx b/apps/erp/app/components/Layout/Navigation/PrimaryNavigation.tsx
index 00182233f8..326077eb8d 100644
--- a/apps/erp/app/components/Layout/Navigation/PrimaryNavigation.tsx
+++ b/apps/erp/app/components/Layout/Navigation/PrimaryNavigation.tsx
@@ -47,6 +47,7 @@ import {
import { useUIStore } from "~/stores/ui";
import type { Authenticated, NavItem } from "~/types";
import { SearchModal } from "../Topbar/Search";
+import CompanySwitcher from "./CompanySwitcher";
import { HiddenModulesPopover } from "./HiddenModulesPopover";
import { NavigationEditBar } from "./NavigationEditBar";
import { SortableNavItem } from "./SortableNavItem";
@@ -60,6 +61,12 @@ const POINTER_SENSOR_OPTIONS = { activationConstraint: { distance: 8 } };
// accent hover instead of the active-tinted one module links use.
const ACTION_HOVER = "hover:bg-accent hover:text-accent-foreground";
+// Expanded, Search reads as a field: an inset hairline rather than a border,
+// which would push its icon a pixel off the rail's icon column. Collapsed, it
+// is an icon like the rest.
+const SEARCH_BORDER =
+ "group-data-[state=expanded]:shadow-[inset_0_0_0_1px_hsl(var(--border))]";
+
// Only modules have a g-then-letter key; pass it for those.
const renderLink = (
link: Authenticated<NavItem>,
@@ -186,6 +193,8 @@ const PrimaryNavigation = () => {
<NavRail
forceExpanded={editMode.isEditing}
disableHover={editMode.isEditing || isSearchModalOpen}
+ // Phones switch company from the Profile sheet.
+ header={isMobile ? undefined : <CompanySwitcher />}
footer={footer}
>
{canSearch && <NavigationSearchButton />}
@@ -270,7 +279,7 @@ const NavigationSearchButton = () => {
setOpenMobile(false);
openSearchModal();
}}
- className={ACTION_HOVER}
+ className={cn(ACTION_HOVER, SEARCH_BORDER)}
data-hover-tone="accent"
trailing={
<ShortcutKey
diff --git a/apps/erp/app/components/Layout/Topbar/Breadcrumbs.tsx b/apps/erp/app/components/Layout/Topbar/Breadcrumbs.tsx
index b8972ca375..e4b8b84c9f 100644
--- a/apps/erp/app/components/Layout/Topbar/Breadcrumbs.tsx
+++ b/apps/erp/app/components/Layout/Topbar/Breadcrumbs.tsx
@@ -2,42 +2,17 @@
// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,
// including ports, remain AGPLv3; serving them over a network requires releasing their source.
-import {
- Avatar,
- Badge,
- Button,
- DropdownMenu,
- DropdownMenuContent,
- DropdownMenuGroup,
- DropdownMenuIcon,
- DropdownMenuItem,
- DropdownMenuLabel,
- DropdownMenuSeparator,
- DropdownMenuTrigger,
- HStack,
- ScrollArea,
- useDisclosure,
- useMode
-} from "@carbon/react";
+import { HStack } from "@carbon/react";
import { useLingui } from "@lingui/react/macro";
import type { ReactNode } from "react";
-import { useMemo } from "react";
-import { BsFillHexagonFill } from "react-icons/bs";
-import { IoMdAdd } from "react-icons/io";
-import { LuChevronsUpDown } from "react-icons/lu";
-import { Form, Link, useMatches } from "react-router";
+import { useMatches } from "react-router";
import { z } from "zod";
import {
BreadcrumbItem,
BreadcrumbLink,
Breadcrumbs as BreadcrumbsBase
} from "~/components";
-import { useRouteData, useUser } from "~/hooks";
-import type { Company } from "~/modules/settings";
import type { BreadcrumbSegment } from "~/utils/handle";
-import { path } from "~/utils/path";
-import { AddCompanyModal } from "./AddCompanyModal";
-import { useCompanySwitchRedirect } from "./CompanySwitcher";
export const BreadcrumbHandle = z.object({
breadcrumb: z.any(),
@@ -97,28 +72,9 @@ export function useBreadcrumbs() {
const Breadcrumbs = () => {
const breadcrumbs = useBreadcrumbs();
- const { company } = useUser();
- const mode = useMode();
- const logo = mode === "dark" ? company?.logoDarkIcon : company?.logoLightIcon;
-
return (
<HStack className="items-center h-full hidden md:flex -ml-2" spacing={0}>
- <Button isIcon asChild variant="ghost" size="lg">
- <Link to="/">
- {logo ? (
- <img
- src={logo}
- alt={`${company.name} logo`}
- className="w-full h-auto rounded"
- />
- ) : (
- <BsFillHexagonFill />
- )}
- </Link>
- </Button>
-
<BreadcrumbsBase className="line-clamp-1">
- <CompanyBreadcrumb />
{breadcrumbs.map((breadcrumb, i) => (
<BreadcrumbItem key={i}>
<BreadcrumbLink
@@ -134,157 +90,4 @@ const Breadcrumbs = () => {
);
};
-function CompanyBreadcrumb() {
- const switchRedirect = useCompanySwitchRedirect();
- const { t } = useLingui();
- const routeData = useRouteData<{ company: Company; companies: Company[] }>(
- path.to.authenticatedRoot
- );
- const user = useUser();
-
- const hasMultipleCompanies = Boolean(
- routeData?.companies && routeData?.companies.length > 1
- );
-
- const canCreateCompany = user.admin === true;
- const hasCompanyMenu = canCreateCompany || hasMultipleCompanies;
- const companyForm = useDisclosure();
-
- const mode = useMode();
-
- const companyGroups = useMemo(() => {
- if (!routeData?.companies) return [];
-
- const groups = new Map<
- string,
- { name: string; companies: typeof routeData.companies }
- >();
-
- for (const c of routeData.companies) {
- const groupName = c.companyGroupName ?? t`Companies`;
- const existing = groups.get(groupName);
- if (existing) {
- existing.companies.push(c);
- } else {
- groups.set(groupName, { name: groupName, companies: [c] });
- }
- }
-
- // If a group has only one company, move it to "Companies"
- const result = new Map<
- string,
- { name: string; companies: typeof routeData.companies }
- >();
- for (const [key, group] of groups) {
- if (group.companies.length === 1 && key !== "Companies") {
- const existing = result.get("Companies");
- if (existing) {
- existing.companies.push(...group.companies);
- } else {
- result.set("Companies", {
- name: "Companies",
- companies: [...group.companies]
- });
- }
- } else {
- const existing = result.get(key);
- if (existing) {
- existing.companies.push(...group.companies);
- } else {
- result.set(key, group);
- }
- }
- }
-
- return Array.from(result.values());
- }, [routeData?.companies, t]);
-
- return (
- <BreadcrumbItem isFirstChild>
- {hasCompanyMenu ? (
- <>
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <Button
- aria-current="page"
- variant="ghost"
- className="px-2 focus-visible:ring-transparent"
- rightIcon={<LuChevronsUpDown />}
- >
- {routeData?.company.name}
- </Button>
- </DropdownMenuTrigger>
- <DropdownMenuContent align="start" className="min-w-[240px]">
- <ScrollArea className="max-h-[300px]">
- {companyGroups.map((group, index) => (
- <DropdownMenuGroup key={group.name}>
- {index > 0 && <DropdownMenuSeparator />}
- <DropdownMenuLabel>{group.name}</DropdownMenuLabel>
- <DropdownMenuSeparator />
- {group.companies.map((c) => {
- const logo =
- mode === "dark" ? c.logoDarkIcon : c.logoLightIcon;
- return (
- <Form
- key={c.companyId}
- method="post"
- action={path.to.companySwitch(c.companyId!)}
- >
- {switchRedirect && (
- <input
- type="hidden"
- name="redirectTo"
- value={switchRedirect}
- />
- )}
- <DropdownMenuItem
- className="flex items-center justify-between w-full"
- asChild
- >
- <button type="submit">
- <HStack>
- <Avatar
- size="xs"
- name={c.name ?? undefined}
- src={logo ?? undefined}
- />
- <span>{c.name}</span>
- </HStack>
- <Badge variant="secondary" className="ml-2">
- {c.employeeType}
- </Badge>
- </button>
- </DropdownMenuItem>
- </Form>
- );
- })}
- </DropdownMenuGroup>
- ))}
- </ScrollArea>
-
- {canCreateCompany && (
- <>
- <DropdownMenuSeparator />
- <DropdownMenuGroup>
- <DropdownMenuItem onClick={companyForm.onOpen}>
- <DropdownMenuIcon icon={<IoMdAdd />} />
- {t`Add Company`}
- </DropdownMenuItem>
- </DropdownMenuGroup>
- </>
- )}
- </DropdownMenuContent>
- </DropdownMenu>
- <AddCompanyModal
- open={companyForm.isOpen}
- onClose={companyForm.onClose}
- />
- </>
- ) : (
- <BreadcrumbLink to="/">{routeData?.company.name}</BreadcrumbLink>
- )}
- </BreadcrumbItem>
- );
-}
-
export default Breadcrumbs;
diff --git a/apps/erp/app/components/Layout/Topbar/CompanySwitcher.tsx b/apps/erp/app/components/Layout/Topbar/CompanySwitcher.tsx
deleted file mode 100644
index 0745dbef4f..0000000000
--- a/apps/erp/app/components/Layout/Topbar/CompanySwitcher.tsx
+++ /dev/null
@@ -1,214 +0,0 @@
-// SPDX-License-Identifier: AGPL-3.0-only
-// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,
-// including ports, remain AGPLv3; serving them over a network requires releasing their source.
-
-import {
- Avatar,
- Badge,
- Button,
- DropdownMenu,
- DropdownMenuContent,
- DropdownMenuGroup,
- DropdownMenuIcon,
- DropdownMenuItem,
- DropdownMenuLabel,
- DropdownMenuSeparator,
- DropdownMenuTrigger,
- HStack,
- ScrollArea,
- useMode
-} from "@carbon/react";
-import { Trans, useLingui } from "@lingui/react/macro";
-import { useMemo } from "react";
-import { BsFillHexagonFill } from "react-icons/bs";
-import { LuChevronsUpDown, LuHouse } from "react-icons/lu";
-import { Form, Link, useLocation, useParams } from "react-router";
-import { useRouteData, useUser } from "~/hooks";
-import type { Company } from "~/modules/settings";
-import { path } from "~/utils/path";
-
-// Switching company keeps a page that exists in every company (a list, a
-// settings page). A record's page does not, so that goes to the home page.
-export function useCompanySwitchRedirect() {
- const params = useParams();
- const { pathname, search } = useLocation();
- return Object.keys(params).length === 0 ? `${pathname}${search}` : undefined;
-}
-
-/**
- * The user's companies grouped by company group (single-company groups fold
- * into "Companies"). Used by the company switcher and the compact Profile sheet.
- */
-export function useCompanyGroups() {
- const { t } = useLingui();
- const routeData = useRouteData<{ company: Company; companies: Company[] }>(
- path.to.authenticatedRoot
- );
- return useMemo(() => {
- if (!routeData?.companies) return [];
-
- const groups = new Map<string, { name: string; companies: Company[] }>();
-
- for (const c of routeData.companies) {
- const groupName = c.companyGroupName ?? t`Companies`;
- const existing = groups.get(groupName);
- if (existing) {
- existing.companies.push(c);
- } else {
- groups.set(groupName, { name: groupName, companies: [c] });
- }
- }
-
- // If a group has only one company, move it to "Companies"
- const result = new Map<string, { name: string; companies: Company[] }>();
- for (const [key, group] of groups) {
- if (group.companies.length === 1 && key !== "Companies") {
- const existing = result.get("Companies");
- if (existing) {
- existing.companies.push(...group.companies);
- } else {
- result.set("Companies", {
- name: "Companies",
- companies: [...group.companies]
- });
- }
- } else {
- const existing = result.get(key);
- if (existing) {
- existing.companies.push(...group.companies);
- } else {
- result.set(key, group);
- }
- }
- }
-
- return Array.from(result.values());
- }, [routeData?.companies, t]);
-}
-
-const CompanySwitcher = () => {
- const switchRedirect = useCompanySwitchRedirect();
- const routeData = useRouteData<{ company: Company; companies: Company[] }>(
- path.to.authenticatedRoot
- );
- const user = useUser();
- const mode = useMode();
-
- const hasMultipleCompanies = Boolean(
- routeData?.companies && routeData?.companies.length > 1
- );
-
- const canSwitchCompany = hasMultipleCompanies;
-
- const companyGroups = useCompanyGroups();
-
- if (!canSwitchCompany) {
- // Just show the company logo without dropdown
- const logo =
- mode === "dark"
- ? user.company?.logoDarkIcon
- : user.company?.logoLightIcon;
-
- return (
- <Button isIcon asChild variant="ghost" size="lg">
- <Link to="/">
- {logo ? (
- <img
- src={logo}
- alt={`${user.company.name} logo`}
- className="size-full object-contain rounded"
- />
- ) : (
- <BsFillHexagonFill />
- )}
- </Link>
- </Button>
- );
- }
-
- return (
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <Button
- variant="ghost"
- className="px-2 focus-visible:ring-transparent"
- rightIcon={<LuChevronsUpDown />}
- >
- {(() => {
- const logo =
- mode === "dark"
- ? user.company?.logoDarkIcon
- : user.company?.logoLightIcon;
- return logo ? (
- <img
- src={logo}
- alt={`${user.company.name} logo`}
- className="h-7 w-auto max-w-[140px] object-contain rounded"
- />
- ) : (
- <BsFillHexagonFill />
- );
- })()}
- </Button>
- </DropdownMenuTrigger>
- <DropdownMenuContent align="end" className="min-w-[240px]">
- <DropdownMenuItem asChild>
- <Link to={path.to.authenticatedRoot}>
- <DropdownMenuIcon icon={<LuHouse />} />
- <Trans>Dashboard</Trans>
- </Link>
- </DropdownMenuItem>
- <ScrollArea className="max-h-[300px]">
- {companyGroups.map((group, index) => (
- <DropdownMenuGroup key={group.name}>
- {index > 0 && <DropdownMenuSeparator />}
- <DropdownMenuLabel>{group.name}</DropdownMenuLabel>
- <DropdownMenuSeparator />
- {group.companies.map((c) => {
- const logo = mode === "dark" ? c.logoDarkIcon : c.logoLightIcon;
- const isCurrent = c.companyId === user.company.id;
-
- return (
- <Form
- key={c.companyId}
- method="post"
- action={path.to.companySwitch(c.companyId!)}
- >
- {switchRedirect && (
- <input
- type="hidden"
- name="redirectTo"
- value={switchRedirect}
- />
- )}
- <DropdownMenuItem
- className="flex items-center justify-between w-full"
- asChild
- disabled={isCurrent}
- >
- <button type="submit">
- <HStack>
- <Avatar
- size="xs"
- name={c.name ?? undefined}
- src={logo ?? undefined}
- />
- <span>{c.name}</span>
- </HStack>
- <Badge variant="secondary" className="ml-2">
- {c.employeeType}
- </Badge>
- </button>
- </DropdownMenuItem>
- </Form>
- );
- })}
- </DropdownMenuGroup>
- ))}
- </ScrollArea>
- </DropdownMenuContent>
- </DropdownMenu>
- );
-};
-
-export default CompanySwitcher;
diff --git a/apps/erp/app/routes/select-company+/_index.tsx b/apps/erp/app/routes/select-company+/_index.tsx
index 39e379413e..8cb8cc1026 100644
--- a/apps/erp/app/routes/select-company+/_index.tsx
+++ b/apps/erp/app/routes/select-company+/_index.tsx
@@ -64,7 +64,7 @@ export default function SelectCompany() {
const [query, setQuery] = useState("");
// A group name only tells the companies apart when more than one of the
- // user's companies shares it — mirrors the top-bar CompanySwitcher.
+ // user's companies shares it — mirrors the navigation rail's CompanySwitcher.
const sharedGroupNames = useMemo(() => {
const counts = new Map<string, number>();
for (const c of companies) {
diff --git a/apps/erp/app/routes/x+/_layout.tsx b/apps/erp/app/routes/x+/_layout.tsx
index 6f310b4b35..c770205cf3 100644
--- a/apps/erp/app/routes/x+/_layout.tsx
+++ b/apps/erp/app/routes/x+/_layout.tsx
@@ -533,7 +533,6 @@ export default function AuthenticatedRoute() {
<TooltipProvider>
<SidebarProvider
defaultOpen={false}
- keyboardShortcut={false}
className="h-screen min-h-0"
>
<PrimaryNavigation />
diff --git a/apps/mes/app/components/AppSidebar.tsx b/apps/mes/app/components/AppSidebar.tsx
index ce8af0a164..1e8751b89d 100644
--- a/apps/mes/app/components/AppSidebar.tsx
+++ b/apps/mes/app/components/AppSidebar.tsx
@@ -6,21 +6,32 @@
import type { Company } from "@carbon/auth";
import {
+ Avatar,
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuIcon,
+ DropdownMenuItem,
+ DropdownMenuLabel,
+ DropdownMenuRadioGroup,
+ DropdownMenuRadioItem,
+ DropdownMenuSeparator,
+ DropdownMenuTrigger,
+ HStack,
NavRail,
- NavRailBrand,
NavRailGroup,
NavRailLink,
+ NavRailSwitcher,
useMode,
useShortcutKeyMap,
useSidebar
} from "@carbon/react";
import { useLingui } from "@lingui/react/macro";
import { Suspense, useMemo } from "react";
-import { BsFillHexagonFill } from "react-icons/bs";
import {
LuActivity,
LuArrowUpRight,
LuCalendarDays,
+ LuChevronsUpDown,
LuCirclePlay,
LuClipboardList,
LuHistory,
@@ -28,7 +39,7 @@ import {
LuPackageCheck,
LuWrench
} from "react-icons/lu";
-import { Await, useLocation, useNavigate } from "react-router";
+import { Await, Link, useLocation, useNavigate } from "react-router";
import type { Location } from "~/services/types";
import { MES_NAV_SHORTCUTS } from "~/shortcuts";
import type { PinnedInUser } from "~/types";
@@ -38,7 +49,7 @@ import { EndShift } from "./EndShift";
import { MoreSheet } from "./MoreSheet";
import Suggestion from "./Suggestion";
import { TimeCardButton } from "./TimeCardButton";
-import { UserNav } from "./UserNav";
+import { UserNav, useSwitchCompany } from "./UserNav";
export function AppSidebar({
activeEvents,
@@ -141,13 +152,18 @@ export function AppSidebar({
return (
<NavRail
- header={<CompanyLink company={company} />}
+ header={
+ <CompanySwitcher
+ company={company}
+ companies={companies}
+ // An operator pinned in at a console station cannot switch company.
+ canSwitch={!(consoleMode && pinnedInUser)}
+ />
+ }
footer={
<>
{timeCard}
<UserNav
- company={company}
- companies={companies}
consoleEnabled={consoleEnabled}
consoleMode={consoleMode}
location={location}
@@ -163,23 +179,90 @@ export function AppSidebar({
);
}
-/** Leads back to the ERP. */
-function CompanyLink({ company }: { company: Company }) {
+/**
+ * The rail's header: the company's logo and name, which switch company and
+ * lead back to the ERP.
+ */
+function CompanySwitcher({
+ company,
+ companies,
+ canSwitch
+}: {
+ company: Company;
+ companies: Company[];
+ canSwitch: boolean;
+}) {
+ const { t } = useLingui();
const mode = useMode();
- const logo = mode === "dark" ? company.logoDarkIcon : company.logoLightIcon;
+ const switchCompany = useSwitchCompany();
+
+ // Nothing to switch to: the row is the link back to the ERP, as it was.
+ if (!canSwitch || companies.length < 2) {
+ return <CompanyLink company={company} />;
+ }
return (
- <NavRailBrand
- href={ERP_URL}
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <NavRailSwitcher
+ label={company.name ?? ""}
+ logoLight={company.logoLightIcon}
+ logoDark={company.logoDarkIcon}
+ trailing={<LuChevronsUpDown />}
+ />
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="start" className="min-w-[240px]">
+ <DropdownMenuLabel>{t`Companies`}</DropdownMenuLabel>
+ <DropdownMenuRadioGroup value={company.companyId!}>
+ {companies.map((c) => {
+ const companyLogo =
+ mode === "dark" ? c.logoDarkIcon : c.logoLightIcon;
+ return (
+ <DropdownMenuRadioItem
+ key={c.companyId}
+ value={c.companyId!}
+ onSelect={() => {
+ if (c.companyId !== company.companyId) {
+ switchCompany(c.companyId!);
+ }
+ }}
+ >
+ <HStack>
+ <Avatar
+ size="xs"
+ name={c.name ?? undefined}
+ src={companyLogo ?? undefined}
+ />
+ <span>{c.name}</span>
+ </HStack>
+ </DropdownMenuRadioItem>
+ );
+ })}
+ </DropdownMenuRadioGroup>
+ <DropdownMenuSeparator />
+ <DropdownMenuItem asChild>
+ <Link to={ERP_URL}>
+ <DropdownMenuIcon icon={<LuArrowUpRight />} />
+ {t`Open ERP`}
+ </Link>
+ </DropdownMenuItem>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ );
+}
+
+/** Leads back to the ERP; on phones, the More sheet's first row. */
+function CompanyLink({ company }: { company: Company }) {
+ return (
+ <NavRailSwitcher
+ asChild
label={company.name ?? ""}
- logo={
- logo ? (
- <img src={logo} alt="" className="size-6 rounded object-contain" />
- ) : (
- <BsFillHexagonFill />
- )
- }
- />
+ logoLight={company.logoLightIcon}
+ logoDark={company.logoDarkIcon}
+ trailing={<LuArrowUpRight className="md:hidden" />}
+ >
+ <Link to={ERP_URL} />
+ </NavRailSwitcher>
);
}
diff --git a/apps/mes/app/components/UserNav.tsx b/apps/mes/app/components/UserNav.tsx
index 5664788e1d..1ab242d963 100644
--- a/apps/mes/app/components/UserNav.tsx
+++ b/apps/mes/app/components/UserNav.tsx
@@ -3,7 +3,6 @@
// including ports, remain AGPLv3; serving them over a network requires releasing their source.
import { useAccountSettings } from "@carbon/account";
-import type { Company } from "@carbon/auth";
import { CONTROLLED_ENVIRONMENT } from "@carbon/auth";
import {
Avatar,
@@ -19,7 +18,6 @@ import {
DropdownMenuSubContent,
DropdownMenuSubTrigger,
DropdownMenuTrigger,
- HStack,
ItarDisclosure,
NavRailItem,
Switch,
@@ -32,7 +30,6 @@ import {
import { modeValidator } from "@carbon/utils";
import { Trans } from "@lingui/react/macro";
import {
- LuBuilding,
LuChevronDown,
LuLaptop,
LuLogOut,
@@ -44,7 +41,7 @@ import {
LuUser,
LuUsers
} from "react-icons/lu";
-import { Form, useFetcher } from "react-router";
+import { Form, useFetcher, useSubmit } from "react-router";
import { useUser } from "~/hooks";
import type { action } from "~/root";
import type { Location } from "~/services/types";
@@ -52,8 +49,6 @@ import type { PinnedInUser } from "~/types";
import { path } from "~/utils/path";
type UserNavProps = {
- company: Company;
- companies: Company[];
consoleEnabled?: boolean;
consoleMode: boolean;
location: string;
@@ -61,6 +56,24 @@ type UserNavProps = {
pinnedInUser: PinnedInUser | null;
};
+/**
+ * Switches the session to another of the user's companies. A navigation, not
+ * a fetcher: the shell's `shouldRevalidate` re-runs only after a mutation, and
+ * a fetcher's redirect reaches it as a plain GET, so the page kept showing the
+ * old company until a reload.
+ */
+export function useSwitchCompany() {
+ const submit = useSubmit();
+ return (companyId: string) => {
+ const form = new FormData();
+ form.append("companyId", companyId);
+ submit(form, {
+ method: "post",
+ action: path.to.switchCompany(companyId)
+ });
+ };
+}
+
/** The user menu's state and actions, shared by the rail menu and the phone More sheet. */
export function useUserNav({
consoleMode,
@@ -90,14 +103,7 @@ export function useUserNav({
fetcher.submit(formData, { method: "POST", action: path.to.location });
};
- const switchCompany = (companyId: string) => {
- const form = new FormData();
- form.append("companyId", companyId);
- fetcher.submit(form, {
- method: "post",
- action: path.to.switchCompany(companyId)
- });
- };
+ const switchCompany = useSwitchCompany();
const switchOperator = () => {
fetcher.submit(null, { method: "POST", action: path.to.consolePinOut });
@@ -150,8 +156,6 @@ export function useUserNav({
}
export function UserNav({
- company,
- companies,
consoleEnabled,
consoleMode,
location,
@@ -166,7 +170,6 @@ export function UserNav({
modePreference,
onModeChange,
updateLocation,
- switchCompany,
switchOperator,
toggleConsoleMode,
optimisticLocation,
@@ -225,37 +228,6 @@ export function UserNav({
</DropdownMenuItem>
<DropdownMenuSeparator />
- <DropdownMenuSub>
- <DropdownMenuSubTrigger>
- <DropdownMenuIcon icon={<LuBuilding />} />
- <Trans>Company</Trans>
- </DropdownMenuSubTrigger>
- <DropdownMenuSubContent>
- <DropdownMenuRadioGroup value={company.companyId!}>
- {companies.map((c) => {
- const logo =
- mode === "dark" ? c.logoDarkIcon : c.logoLightIcon;
- return (
- <DropdownMenuRadioItem
- key={c.companyId}
- value={c.companyId!}
- onSelect={() => switchCompany(c.companyId!)}
- >
- <HStack>
- <Avatar
- size="xs"
- name={c.name ?? undefined}
- src={logo ?? undefined}
- />
- <span>{c.name}</span>
- </HStack>
- </DropdownMenuRadioItem>
- );
- })}
- </DropdownMenuRadioGroup>
- </DropdownMenuSubContent>
- </DropdownMenuSub>
- <DropdownMenuSeparator />
{locations.length > 1 ? (
<>
<DropdownMenuSub>
diff --git a/packages/locale/locales/de/erp.po b/packages/locale/locales/de/erp.po
index 86e6adba56..e706e85634 100644
--- a/packages/locale/locales/de/erp.po
+++ b/packages/locale/locales/de/erp.po
@@ -5043,6 +5043,9 @@ msgstr "Position einklappen"
msgid "Collapse Machine"
msgstr "Maschine einklappen"
+msgid "Collapse navigation"
+msgstr "Navigation einklappen"
+
msgid "Collapse row"
msgstr "Zeile einklappen"
@@ -12031,6 +12034,9 @@ msgstr "Behalte bestehende Preise, nur neue Artikel hinzufügen"
msgid "Keep Line"
msgstr "Position behalten"
+msgid "Keep navigation open"
+msgstr "Navigation geöffnet lassen"
+
msgid "Keep only items where…"
msgstr "Nur Artikel behalten, bei denen…"
diff --git a/packages/locale/locales/de/mes.po b/packages/locale/locales/de/mes.po
index 5cf99f5738..68aecbcbe1 100644
--- a/packages/locale/locales/de/mes.po
+++ b/packages/locale/locales/de/mes.po
@@ -399,6 +399,9 @@ msgstr "Schließen"
msgid "Collapse characteristics table"
msgstr "Merkmalstabelle einklappen"
+msgid "Collapse navigation"
+msgstr "Navigation einklappen"
+
msgid "Collapse panel"
msgstr "Bereich reduzieren"
@@ -422,6 +425,9 @@ msgstr "Spalte: {0}"
msgid "Columns"
msgstr "Spalten"
+msgid "Companies"
+msgstr "Unternehmen"
+
msgid "Company"
msgstr "Unternehmen"
@@ -905,6 +911,9 @@ msgstr "Fertigungsauftrag-Laufkarte"
msgid "Jobs"
msgstr "Fertigungsaufträge"
+msgid "Keep navigation open"
+msgstr "Navigation geöffnet lassen"
+
msgid "Keep picking"
msgstr "Kommissionierung fortsetzen"
@@ -1308,6 +1317,9 @@ msgstr "Öffnen Sie einen Fertigungsauftrag in diesem Los"
msgid "Open an NCR for MRB disposition"
msgstr "Öffnen Sie einen NCR für MRB-Verwendungsentscheid"
+msgid "Open ERP"
+msgstr "ERP öffnen"
+
msgid "Open Jobs"
msgstr "Offene Fertigungsaufträge"
diff --git a/packages/locale/locales/en/erp.po b/packages/locale/locales/en/erp.po
index c117409897..df3138b42b 100644
--- a/packages/locale/locales/en/erp.po
+++ b/packages/locale/locales/en/erp.po
@@ -5043,6 +5043,9 @@ msgstr "Collapse line"
msgid "Collapse Machine"
msgstr "Collapse Machine"
+msgid "Collapse navigation"
+msgstr "Collapse navigation"
+
msgid "Collapse row"
msgstr "Collapse row"
@@ -12031,6 +12034,9 @@ msgstr "Keep existing pricing, only add new items"
msgid "Keep Line"
msgstr "Keep Line"
+msgid "Keep navigation open"
+msgstr "Keep navigation open"
+
msgid "Keep only items where…"
msgstr "Keep only items where…"
diff --git a/packages/locale/locales/en/mes.po b/packages/locale/locales/en/mes.po
index 60177a56ea..705b8c5be2 100644
--- a/packages/locale/locales/en/mes.po
+++ b/packages/locale/locales/en/mes.po
@@ -399,6 +399,9 @@ msgstr "Close"
msgid "Collapse characteristics table"
msgstr "Collapse characteristics table"
+msgid "Collapse navigation"
+msgstr "Collapse navigation"
+
msgid "Collapse panel"
msgstr "Collapse panel"
@@ -422,6 +425,9 @@ msgstr "Column: {0}"
msgid "Columns"
msgstr "Columns"
+msgid "Companies"
+msgstr "Companies"
+
msgid "Company"
msgstr "Company"
@@ -905,6 +911,9 @@ msgstr "Job Traveler"
msgid "Jobs"
msgstr "Jobs"
+msgid "Keep navigation open"
+msgstr "Keep navigation open"
+
msgid "Keep picking"
msgstr "Keep picking"
@@ -1308,6 +1317,9 @@ msgstr "Open a job in this batch"
msgid "Open an NCR for MRB disposition"
msgstr "Open an NCR for MRB disposition"
+msgid "Open ERP"
+msgstr "Open ERP"
+
msgid "Open Jobs"
msgstr "Open Jobs"
diff --git a/packages/locale/locales/es/erp.po b/packages/locale/locales/es/erp.po
index f950814e8f..530f6c7674 100644
--- a/packages/locale/locales/es/erp.po
+++ b/packages/locale/locales/es/erp.po
@@ -5043,6 +5043,9 @@ msgstr "Contraer línea"
msgid "Collapse Machine"
msgstr "Contraer máquina"
+msgid "Collapse navigation"
+msgstr "Contraer navegación"
+
msgid "Collapse row"
msgstr "Contraer fila"
@@ -12031,6 +12034,9 @@ msgstr "Mantener fijación de precios existente, solo agregar artículos nuevos"
msgid "Keep Line"
msgstr "Mantener línea"
+msgid "Keep navigation open"
+msgstr "Mantener navegación abierta"
+
msgid "Keep only items where…"
msgstr "Mantener solo elementos donde..."
diff --git a/packages/locale/locales/es/mes.po b/packages/locale/locales/es/mes.po
index 61ebc73b4b..a56b2174fa 100644
--- a/packages/locale/locales/es/mes.po
+++ b/packages/locale/locales/es/mes.po
@@ -399,6 +399,9 @@ msgstr "Cerrar"
msgid "Collapse characteristics table"
msgstr "Contraer tabla de características"
+msgid "Collapse navigation"
+msgstr "Contraer navegación"
+
msgid "Collapse panel"
msgstr "Contraer panel"
@@ -422,6 +425,9 @@ msgstr "Columna: {0}"
msgid "Columns"
msgstr "Columnas"
+msgid "Companies"
+msgstr "Empresas"
+
msgid "Company"
msgstr "Empresa"
@@ -905,6 +911,9 @@ msgstr "Hoja viajera"
msgid "Jobs"
msgstr "Órdenes de trabajo"
+msgid "Keep navigation open"
+msgstr "Mantener navegación abierta"
+
msgid "Keep picking"
msgstr "Continuar picking"
@@ -1308,6 +1317,9 @@ msgstr "Abrir una orden de trabajo en este lote de producción"
msgid "Open an NCR for MRB disposition"
msgstr "Abrir un NCR para la disposición de MRB"
+msgid "Open ERP"
+msgstr "Abrir ERP"
+
msgid "Open Jobs"
msgstr "Órdenes de trabajo abiertas"
diff --git a/packages/locale/locales/fr/erp.po b/packages/locale/locales/fr/erp.po
index a8faca64d2..a01ba40785 100644
--- a/packages/locale/locales/fr/erp.po
+++ b/packages/locale/locales/fr/erp.po
@@ -5043,6 +5043,9 @@ msgstr "Réduire la ligne"
msgid "Collapse Machine"
msgstr "Réduire Machine"
+msgid "Collapse navigation"
+msgstr "Réduire la navigation"
+
msgid "Collapse row"
msgstr "Réduire la ligne"
@@ -12031,6 +12034,9 @@ msgstr "Conserver la tarification existante, ajouter uniquement les nouveaux art
msgid "Keep Line"
msgstr "Conserver la ligne"
+msgid "Keep navigation open"
+msgstr "Garder la navigation ouverte"
+
msgid "Keep only items where…"
msgstr "Garder uniquement les articles où…"
diff --git a/packages/locale/locales/fr/mes.po b/packages/locale/locales/fr/mes.po
index 63064cfa28..de000f7455 100644
--- a/packages/locale/locales/fr/mes.po
+++ b/packages/locale/locales/fr/mes.po
@@ -399,6 +399,9 @@ msgstr "Fermer"
msgid "Collapse characteristics table"
msgstr "Réduire le tableau des caractéristiques"
+msgid "Collapse navigation"
+msgstr "Réduire la navigation"
+
msgid "Collapse panel"
msgstr "Réduire le panneau"
@@ -422,6 +425,9 @@ msgstr "Colonne : {0}"
msgid "Columns"
msgstr "Colonnes"
+msgid "Companies"
+msgstr "Sociétés"
+
msgid "Company"
msgstr "Société"
@@ -905,6 +911,9 @@ msgstr "Fiche suiveuse"
msgid "Jobs"
msgstr "Ordres de fabrication"
+msgid "Keep navigation open"
+msgstr "Garder la navigation ouverte"
+
msgid "Keep picking"
msgstr "Continuer le prélèvement"
@@ -1308,6 +1317,9 @@ msgstr "Ouvrir un ordre de fabrication dans ce lot de production"
msgid "Open an NCR for MRB disposition"
msgstr "Ouvrir une NCR pour le traitement du MRB"
+msgid "Open ERP"
+msgstr "Ouvrir l'ERP"
+
msgid "Open Jobs"
msgstr "Ordres de fabrication ouvertes"
diff --git a/packages/locale/locales/hi/erp.po b/packages/locale/locales/hi/erp.po
index 65cf9dd439..78e69b1200 100644
--- a/packages/locale/locales/hi/erp.po
+++ b/packages/locale/locales/hi/erp.po
@@ -5043,6 +5043,9 @@ msgstr "पंक्ति को संपीड़न करें"
msgid "Collapse Machine"
msgstr "मशीन को संक्षिप्त करें"
+msgid "Collapse navigation"
+msgstr "नेविगेशन संक्षिप्त करें"
+
msgid "Collapse row"
msgstr "पंक्ति संक्षिप्त करें"
@@ -12031,6 +12034,9 @@ msgstr "मौजूदा मूल्य निर्धारण रखें
msgid "Keep Line"
msgstr "पंक्ति रखें"
+msgid "Keep navigation open"
+msgstr "नेविगेशन खुला रखें"
+
msgid "Keep only items where…"
msgstr "केवल आइटम रखें जहां…"
diff --git a/packages/locale/locales/hi/mes.po b/packages/locale/locales/hi/mes.po
index fa76884d4d..160a1a0469 100644
--- a/packages/locale/locales/hi/mes.po
+++ b/packages/locale/locales/hi/mes.po
@@ -399,6 +399,9 @@ msgstr "बंद करें"
msgid "Collapse characteristics table"
msgstr "विशेषताएं तालिका संपीड़ित करें"
+msgid "Collapse navigation"
+msgstr "नेविगेशन संक्षिप्त करें"
+
msgid "Collapse panel"
msgstr "पैनल संक्षिप्त करें"
@@ -422,6 +425,9 @@ msgstr "कॉलम: {0}"
msgid "Columns"
msgstr "कॉलम"
+msgid "Companies"
+msgstr "कंपनियां"
+
msgid "Company"
msgstr "कंपनी"
@@ -905,6 +911,9 @@ msgstr "जॉब ट्रैवलर"
msgid "Jobs"
msgstr "जॉब"
+msgid "Keep navigation open"
+msgstr "नेविगेशन खुला रखें"
+
msgid "Keep picking"
msgstr "पिकिंग जारी रखें"
@@ -1308,6 +1317,9 @@ msgstr "इस बैच में एक जॉब खोलें"
msgid "Open an NCR for MRB disposition"
msgstr "MRB निपटान के लिए एक NCR खोलें"
+msgid "Open ERP"
+msgstr "ERP खोलें"
+
msgid "Open Jobs"
msgstr "खुले जॉब"
diff --git a/packages/locale/locales/it/erp.po b/packages/locale/locales/it/erp.po
index b7e17485ff..9144d9712a 100644
--- a/packages/locale/locales/it/erp.po
+++ b/packages/locale/locales/it/erp.po
@@ -5043,6 +5043,9 @@ msgstr "Comprimi riga"
msgid "Collapse Machine"
msgstr "Comprimi macchina"
+msgid "Collapse navigation"
+msgstr "Comprimi navigazione"
+
msgid "Collapse row"
msgstr "Comprimi riga"
@@ -12031,6 +12034,9 @@ msgstr "Mantieni la determinazione dei prezzi esistente, aggiungi solo nuovi art
msgid "Keep Line"
msgstr "Mantieni riga"
+msgid "Keep navigation open"
+msgstr "Mantieni navigazione aperta"
+
msgid "Keep only items where…"
msgstr "Mantieni solo gli elementi dove…"
diff --git a/packages/locale/locales/it/mes.po b/packages/locale/locales/it/mes.po
index 8f92c65846..deb7cb1914 100644
--- a/packages/locale/locales/it/mes.po
+++ b/packages/locale/locales/it/mes.po
@@ -399,6 +399,9 @@ msgstr "Chiudi"
msgid "Collapse characteristics table"
msgstr "Comprimi tabella delle caratteristiche"
+msgid "Collapse navigation"
+msgstr "Comprimi navigazione"
+
msgid "Collapse panel"
msgstr "Comprimi pannello"
@@ -422,6 +425,9 @@ msgstr "Colonna: {0}"
msgid "Columns"
msgstr "Colonne"
+msgid "Companies"
+msgstr "Aziende"
+
msgid "Company"
msgstr "Azienda"
@@ -905,6 +911,9 @@ msgstr "Cartellino di produzione"
msgid "Jobs"
msgstr "Ordini di produzione"
+msgid "Keep navigation open"
+msgstr "Mantieni navigazione aperta"
+
msgid "Keep picking"
msgstr "Continua il prelievo"
@@ -1308,6 +1317,9 @@ msgstr "Apri un ordine di produzione in questo lotto di produzione"
msgid "Open an NCR for MRB disposition"
msgstr "Apri un NCR per la disposizione MRB"
+msgid "Open ERP"
+msgstr "Apri ERP"
+
msgid "Open Jobs"
msgstr "Ordini Aperti"
diff --git a/packages/locale/locales/ja/erp.po b/packages/locale/locales/ja/erp.po
index adffb7374b..1177753637 100644
--- a/packages/locale/locales/ja/erp.po
+++ b/packages/locale/locales/ja/erp.po
@@ -5043,6 +5043,9 @@ msgstr "明細を折りたたむ"
msgid "Collapse Machine"
msgstr "機械を折りたたむ"
+msgid "Collapse navigation"
+msgstr "ナビゲーションを折りたたむ"
+
msgid "Collapse row"
msgstr "行を折りたたむ"
@@ -12031,6 +12034,9 @@ msgstr "既存の価格設定を保持し、新しい品目のみを追加"
msgid "Keep Line"
msgstr "明細を維持"
+msgid "Keep navigation open"
+msgstr "ナビゲーションを開いたままにする"
+
msgid "Keep only items where…"
msgstr "以下の条件を満たすアイテムのみを保持…"
diff --git a/packages/locale/locales/ja/mes.po b/packages/locale/locales/ja/mes.po
index 06d2d7f2ff..4afe8b1f3c 100644
--- a/packages/locale/locales/ja/mes.po
+++ b/packages/locale/locales/ja/mes.po
@@ -399,6 +399,9 @@ msgstr "閉じる"
msgid "Collapse characteristics table"
msgstr "特性テーブルを折りたたむ"
+msgid "Collapse navigation"
+msgstr "ナビゲーションを折りたたむ"
+
msgid "Collapse panel"
msgstr "パネルを折りたたむ"
@@ -422,6 +425,9 @@ msgstr "カラム: {0}"
msgid "Columns"
msgstr "列"
+msgid "Companies"
+msgstr "会社"
+
msgid "Company"
msgstr "会社"
@@ -905,6 +911,9 @@ msgstr "製造指図現品票"
msgid "Jobs"
msgstr "製造指図"
+msgid "Keep navigation open"
+msgstr "ナビゲーションを開いたままにする"
+
msgid "Keep picking"
msgstr "ピッキングを続ける"
@@ -1308,6 +1317,9 @@ msgstr "このバッチの製造指図を開く"
msgid "Open an NCR for MRB disposition"
msgstr "MRB処置のためにNCRを開く"
+msgid "Open ERP"
+msgstr "ERP を開く"
+
msgid "Open Jobs"
msgstr "オープン製造指図"
diff --git a/packages/locale/locales/ko/erp.po b/packages/locale/locales/ko/erp.po
index e183f5ed58..8eb20be059 100644
--- a/packages/locale/locales/ko/erp.po
+++ b/packages/locale/locales/ko/erp.po
@@ -5043,6 +5043,9 @@ msgstr "라인 접기"
msgid "Collapse Machine"
msgstr "기계 접기"
+msgid "Collapse navigation"
+msgstr "탐색 접기"
+
msgid "Collapse row"
msgstr "행 접기"
@@ -12031,6 +12034,9 @@ msgstr "기존 가격 책정을 유지하고 새 품목만 추가합니다."
msgid "Keep Line"
msgstr "라인 유지"
+msgid "Keep navigation open"
+msgstr "탐색 열어 두기"
+
msgid "Keep only items where…"
msgstr "...인 항목만 유지"
diff --git a/packages/locale/locales/ko/mes.po b/packages/locale/locales/ko/mes.po
index c98349214c..ebccd70c17 100644
--- a/packages/locale/locales/ko/mes.po
+++ b/packages/locale/locales/ko/mes.po
@@ -399,6 +399,9 @@ msgstr "닫기"
msgid "Collapse characteristics table"
msgstr "특성 표 축소"
+msgid "Collapse navigation"
+msgstr "탐색 접기"
+
msgid "Collapse panel"
msgstr "패널 축소"
@@ -422,6 +425,9 @@ msgstr "열: {0}"
msgid "Columns"
msgstr "열"
+msgid "Companies"
+msgstr "회사"
+
msgid "Company"
msgstr "회사"
@@ -905,6 +911,9 @@ msgstr "작업 이동표"
msgid "Jobs"
msgstr "작업 지시"
+msgid "Keep navigation open"
+msgstr "탐색 열어 두기"
+
msgid "Keep picking"
msgstr "피킹을 계속하세요"
@@ -1308,6 +1317,9 @@ msgstr "이 배치에서 작업 지시 열기"
msgid "Open an NCR for MRB disposition"
msgstr "MRB 처분 결정을 위해 NCR을 여세요"
+msgid "Open ERP"
+msgstr "ERP 열기"
+
msgid "Open Jobs"
msgstr "미결 작업 지시"
diff --git a/packages/locale/locales/nl/erp.po b/packages/locale/locales/nl/erp.po
index 7e000ec0d3..a383cd951c 100644
--- a/packages/locale/locales/nl/erp.po
+++ b/packages/locale/locales/nl/erp.po
@@ -1324,7 +1324,7 @@ msgid "Comments"
msgstr ""
msgid "Companies"
-msgstr ""
+msgstr "Bedrijven"
msgid "Company"
msgstr ""
diff --git a/packages/locale/locales/pl/erp.po b/packages/locale/locales/pl/erp.po
index 5d18467572..b79499d7aa 100644
--- a/packages/locale/locales/pl/erp.po
+++ b/packages/locale/locales/pl/erp.po
@@ -5043,6 +5043,9 @@ msgstr "Zwiń pozycję"
msgid "Collapse Machine"
msgstr "Zwiń maszynę"
+msgid "Collapse navigation"
+msgstr "Zwiń nawigację"
+
msgid "Collapse row"
msgstr "Zwiń wiersz"
@@ -12031,6 +12034,9 @@ msgstr "Zachowaj istniejące ceny, dodaj tylko nowe artykuły"
msgid "Keep Line"
msgstr "Zachowaj pozycję"
+msgid "Keep navigation open"
+msgstr "Pozostaw nawigację otwartą"
+
msgid "Keep only items where…"
msgstr "Zachowaj tylko przedmioty gdzie…"
diff --git a/packages/locale/locales/pl/mes.po b/packages/locale/locales/pl/mes.po
index 67f35ed045..1eb1781cc9 100644
--- a/packages/locale/locales/pl/mes.po
+++ b/packages/locale/locales/pl/mes.po
@@ -399,6 +399,9 @@ msgstr "Zamknij"
msgid "Collapse characteristics table"
msgstr "Zwiń tabelę cech"
+msgid "Collapse navigation"
+msgstr "Zwiń nawigację"
+
msgid "Collapse panel"
msgstr "Zwiń panel"
@@ -422,6 +425,9 @@ msgstr "Kolumna: {0}"
msgid "Columns"
msgstr "Kolumny"
+msgid "Companies"
+msgstr "Firmy"
+
msgid "Company"
msgstr "Firma"
@@ -905,6 +911,9 @@ msgstr "Przewodnik zlecenia"
msgid "Jobs"
msgstr "Zlecenia produkcyjne"
+msgid "Keep navigation open"
+msgstr "Pozostaw nawigację otwartą"
+
msgid "Keep picking"
msgstr "Kontynuuj kompletację"
@@ -1308,6 +1317,9 @@ msgstr "Otwórz zlecenie produkcyjne w tej partii produkcyjnej"
msgid "Open an NCR for MRB disposition"
msgstr "Otwórz NCR dla dyspozycji MRB"
+msgid "Open ERP"
+msgstr "Otwórz ERP"
+
msgid "Open Jobs"
msgstr "Otwarte Zlecenia produkcyjne"
diff --git a/packages/locale/locales/pt/erp.po b/packages/locale/locales/pt/erp.po
index ec0f7a4045..784a9b301c 100644
--- a/packages/locale/locales/pt/erp.po
+++ b/packages/locale/locales/pt/erp.po
@@ -5043,6 +5043,9 @@ msgstr "Recolher linha"
msgid "Collapse Machine"
msgstr "Recolher Máquina"
+msgid "Collapse navigation"
+msgstr "Recolher navegação"
+
msgid "Collapse row"
msgstr "Recolher linha"
@@ -12031,6 +12034,9 @@ msgstr "Manter precificação existente, apenas adicionar itens novos"
msgid "Keep Line"
msgstr "Manter linha"
+msgid "Keep navigation open"
+msgstr "Manter navegação aberta"
+
msgid "Keep only items where…"
msgstr "Manter apenas itens onde…"
diff --git a/packages/locale/locales/pt/mes.po b/packages/locale/locales/pt/mes.po
index 02f6d9662f..242d8d8fd4 100644
--- a/packages/locale/locales/pt/mes.po
+++ b/packages/locale/locales/pt/mes.po
@@ -399,6 +399,9 @@ msgstr "Fechar"
msgid "Collapse characteristics table"
msgstr "Recolher tabela de características"
+msgid "Collapse navigation"
+msgstr "Recolher navegação"
+
msgid "Collapse panel"
msgstr "Recolher painel"
@@ -422,6 +425,9 @@ msgstr "Coluna: {0}"
msgid "Columns"
msgstr "Colunas"
+msgid "Companies"
+msgstr "Empresas"
+
msgid "Company"
msgstr "Empresa"
@@ -905,6 +911,9 @@ msgstr "Ficha de acompanhamento"
msgid "Jobs"
msgstr "Ordens de produção"
+msgid "Keep navigation open"
+msgstr "Manter navegação aberta"
+
msgid "Keep picking"
msgstr "Continuar separação"
@@ -1308,6 +1317,9 @@ msgstr "Abrir uma ordem de produção neste lote de produção"
msgid "Open an NCR for MRB disposition"
msgstr "Abrir um NCR para disposição MRB"
+msgid "Open ERP"
+msgstr "Abrir ERP"
+
msgid "Open Jobs"
msgstr "Ordens de Produção Abertas"
diff --git a/packages/locale/locales/ru/erp.po b/packages/locale/locales/ru/erp.po
index e6fc9d23bf..1a0b80f375 100644
--- a/packages/locale/locales/ru/erp.po
+++ b/packages/locale/locales/ru/erp.po
@@ -5043,6 +5043,9 @@ msgstr "Свернуть строку"
msgid "Collapse Machine"
msgstr "Свернуть станок"
+msgid "Collapse navigation"
+msgstr "Свернуть навигацию"
+
msgid "Collapse row"
msgstr "Свернуть строку"
@@ -12031,6 +12034,9 @@ msgstr "Сохранить существующее ценообразовани
msgid "Keep Line"
msgstr "Оставить строку"
+msgid "Keep navigation open"
+msgstr "Не сворачивать навигацию"
+
msgid "Keep only items where…"
msgstr "Оставить только элементы где…"
diff --git a/packages/locale/locales/ru/mes.po b/packages/locale/locales/ru/mes.po
index 84451767e3..1f826c15d9 100644
--- a/packages/locale/locales/ru/mes.po
+++ b/packages/locale/locales/ru/mes.po
@@ -399,6 +399,9 @@ msgstr "Закрыть"
msgid "Collapse characteristics table"
msgstr "Свернуть таблицу характеристик"
+msgid "Collapse navigation"
+msgstr "Свернуть навигацию"
+
msgid "Collapse panel"
msgstr "Свернуть панель"
@@ -422,6 +425,9 @@ msgstr "Столбец: {0}"
msgid "Columns"
msgstr "Столбцы"
+msgid "Companies"
+msgstr "Организации"
+
msgid "Company"
msgstr "Организация"
@@ -905,6 +911,9 @@ msgstr "Маршрутный лист"
msgid "Jobs"
msgstr "Производственные заказы"
+msgid "Keep navigation open"
+msgstr "Не сворачивать навигацию"
+
msgid "Keep picking"
msgstr "Продолжить отбор"
@@ -1308,6 +1317,9 @@ msgstr "Открыть производственный заказ в этой
msgid "Open an NCR for MRB disposition"
msgstr "Открыть NCR для решения MRB"
+msgid "Open ERP"
+msgstr "Открыть ERP"
+
msgid "Open Jobs"
msgstr "Открытые производственные заказы"
diff --git a/packages/locale/locales/tr/erp.po b/packages/locale/locales/tr/erp.po
index fca607aae2..3e14994a09 100644
--- a/packages/locale/locales/tr/erp.po
+++ b/packages/locale/locales/tr/erp.po
@@ -5043,6 +5043,9 @@ msgstr "Satırı daralt"
msgid "Collapse Machine"
msgstr "Makineyi Daralt"
+msgid "Collapse navigation"
+msgstr "Gezinmeyi daralt"
+
msgid "Collapse row"
msgstr "Satırı Daralt"
@@ -12031,6 +12034,9 @@ msgstr "Mevcut fiyatlandırmayı koru, yalnızca yeni öğeler ekle"
msgid "Keep Line"
msgstr "Satırı koru"
+msgid "Keep navigation open"
+msgstr "Gezinmeyi açık tut"
+
msgid "Keep only items where…"
msgstr "Yalnızca öğeleri sakla…"
diff --git a/packages/locale/locales/tr/mes.po b/packages/locale/locales/tr/mes.po
index 27550730e1..89e06422c3 100644
--- a/packages/locale/locales/tr/mes.po
+++ b/packages/locale/locales/tr/mes.po
@@ -399,6 +399,9 @@ msgstr "Kapat"
msgid "Collapse characteristics table"
msgstr "Özellikler tablosunu daralt"
+msgid "Collapse navigation"
+msgstr "Gezinmeyi daralt"
+
msgid "Collapse panel"
msgstr "Paneli daralt"
@@ -422,6 +425,9 @@ msgstr "Sütun: {0}"
msgid "Columns"
msgstr "Sütunlar"
+msgid "Companies"
+msgstr "Şirketler"
+
msgid "Company"
msgstr "Şirket"
@@ -905,6 +911,9 @@ msgstr "İş emri takip kartı"
msgid "Jobs"
msgstr "İş emirleri"
+msgid "Keep navigation open"
+msgstr "Gezinmeyi açık tut"
+
msgid "Keep picking"
msgstr "Toplamaya devam et"
@@ -1308,6 +1317,9 @@ msgstr "Bu partizeki bir iş emrini aç"
msgid "Open an NCR for MRB disposition"
msgstr "MRB kararı için NCR aç"
+msgid "Open ERP"
+msgstr "ERP'yi aç"
+
msgid "Open Jobs"
msgstr "Açık İş emirleri"
diff --git a/packages/locale/locales/zh/erp.po b/packages/locale/locales/zh/erp.po
index aecdf055d6..18525fbb18 100644
--- a/packages/locale/locales/zh/erp.po
+++ b/packages/locale/locales/zh/erp.po
@@ -5043,6 +5043,9 @@ msgstr "折叠行"
msgid "Collapse Machine"
msgstr "折叠机器"
+msgid "Collapse navigation"
+msgstr "收起导航"
+
msgid "Collapse row"
msgstr "折叠行"
@@ -12031,6 +12034,9 @@ msgstr "保留现有定价,仅添加新物料"
msgid "Keep Line"
msgstr "保留行"
+msgid "Keep navigation open"
+msgstr "保持导航展开"
+
msgid "Keep only items where…"
msgstr "仅保留满足以下条件的物料…"
diff --git a/packages/locale/locales/zh/mes.po b/packages/locale/locales/zh/mes.po
index 7b19386eb7..05a1c5d7f6 100644
--- a/packages/locale/locales/zh/mes.po
+++ b/packages/locale/locales/zh/mes.po
@@ -399,6 +399,9 @@ msgstr "关闭"
msgid "Collapse characteristics table"
msgstr "折叠特性表格"
+msgid "Collapse navigation"
+msgstr "收起导航"
+
msgid "Collapse panel"
msgstr "折叠面板"
@@ -422,6 +425,9 @@ msgstr "列:{0}"
msgid "Columns"
msgstr "列"
+msgid "Companies"
+msgstr "公司"
+
msgid "Company"
msgstr "公司"
@@ -905,6 +911,9 @@ msgstr "工单流转卡"
msgid "Jobs"
msgstr "工单"
+msgid "Keep navigation open"
+msgstr "保持导航展开"
+
msgid "Keep picking"
msgstr "继续拣货"
@@ -1308,6 +1317,9 @@ msgstr "打开此生产批次中的工单"
msgid "Open an NCR for MRB disposition"
msgstr "为MRB处置打开NCR"
+msgid "Open ERP"
+msgstr "打开 ERP"
+
msgid "Open Jobs"
msgstr "未结工单"
diff --git a/packages/react/AGENTS.md b/packages/react/AGENTS.md
index 24ddb0e6d3..ab331c0b67 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, expands after a 150ms mouse hover or when pinned via `SidebarProvider` (⌘B unless `keyboardShortcut={false}`, as in the ERP), left drawer below md that closes itself on navigation). Optional `header` (use `NavRailBrand` for a logo + name) and `footer` slots; `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` 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}`). 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 47b1f50523..0c2acb53d7 100644
--- a/packages/react/src/NavRail.tsx
+++ b/packages/react/src/NavRail.tsx
@@ -4,7 +4,7 @@
"use client";
-import { Trans } from "@lingui/react/macro";
+import { Trans, useLingui } from "@lingui/react/macro";
import { Slot, Slottable } from "@radix-ui/react-slot";
import type { ButtonHTMLAttributes, MouseEvent, ReactNode } from "react";
import {
@@ -16,13 +16,19 @@ import {
useRef,
useState
} from "react";
-import { LuArrowUpRight } from "react-icons/lu";
+import { LuPanelLeft } from "react-icons/lu";
import type { LinkProps } from "react-router";
import { Link, useLocation } from "react-router";
+import { Avatar } from "./Avatar";
import { Drawer, DrawerContent, DrawerTitle } from "./Drawer";
+import { useMode } from "./hooks/useMode";
+import { IconButton } from "./IconButton";
import { PrefetchLink } from "./PrefetchLink";
import { Separator } from "./Separator";
+import { ShortcutKey } from "./ShortcutKey";
import { useSidebar } from "./Sidebar";
+import { SHORTCUTS } from "./shortcuts";
+import { Tooltip, TooltipContent, TooltipTrigger } from "./Tooltip";
import { cn } from "./utils/cn";
import { VStack } from "./VStack";
@@ -46,8 +52,9 @@ export const navRailItemClasses = [
/**
* The primary left navigation shared by the ERP and MES app shells: a 56px
- * icon rail that grows to 208px while a mouse hovers it or while it is pinned
- * open (a `SidebarTrigger`, or ⌘B where the provider binds it), and a left drawer below `md`. Open state
+ * icon rail that grows to 240px while a mouse hovers it or while it is pinned
+ * open, and a left drawer below `md`. The toggle beside the `header` pins it,
+ * as do ⌘B and a `SidebarTrigger`. Open state
* comes from `SidebarProvider`, so it must be rendered inside one.
*
* Expanding the rail, by hover or by pin, pushes the page right rather than
@@ -60,6 +67,19 @@ const HOVER_OPEN_DELAY_MS = 150;
// popover it triggered is open, so a tap on a collapsed rail never opens it.
const NavRailHoldContext = createContext<(() => () => void) | null>(null);
+/**
+ * Freeze the rail while the menu or popover an item triggers is open. Radix
+ * triggers pass their open state to the item as `data-state`.
+ */
+function useNavRailHold(triggerProps: object) {
+ const isOpen =
+ (triggerProps as Record<string, unknown>)["data-state"] === "open";
+ const hold = useContext(NavRailHoldContext);
+ useEffect(() => {
+ if (isOpen && hold) return hold();
+ }, [isOpen, hold]);
+}
+
export function NavRail({
children,
header,
@@ -155,7 +175,15 @@ export function NavRail({
<NavRailHoldContext.Provider value={hold}>
<VStack spacing={1} className="flex flex-col justify-between h-full px-2">
<VStack spacing={1}>
- {header ? <div className="w-full pb-2">{header}</div> : null}
+ {header ? (
+ // As tall as the app's top bar (ERP `--topbar-height`, MES
+ // `--header-height`) and as far down: the rail's padding plus the
+ // content panel's 1px border. The logo centres on the bar.
+ <div className="mt-px mb-2 flex h-[var(--topbar-height,var(--header-height,2.5rem))] w-full shrink-0 items-center gap-1">
+ {header}
+ <NavRailToggle />
+ </div>
+ ) : null}
{children}
</VStack>
{footer ? <VStack spacing={1}>{footer}</VStack> : null}
@@ -220,7 +248,7 @@ export function NavRail({
data-state={state}
className={cn(
"sticky top-0 h-svh z-50 hidden md:block shrink-0",
- "w-14 data-[state=expanded]:w-[13rem]",
+ "w-14 data-[state=expanded]:w-[15rem]",
"transition-[width] duration-200 ease-[cubic-bezier(0.23,1,0.32,1)] motion-reduce:transition-none"
)}
>
@@ -230,7 +258,7 @@ export function NavRail({
data-sliding-hover=""
className={cn(
"absolute inset-y-0 left-0 bg-background py-2 group",
- "w-14 data-[state=expanded]:w-[13rem]",
+ "w-14 data-[state=expanded]:w-[15rem]",
"transition-[width] duration-200 ease-[cubic-bezier(0.23,1,0.32,1)] motion-reduce:transition-none",
"flex flex-col justify-between",
"hide-scrollbar overflow-y-auto scrollbar-thin scrollbar-track-transparent scrollbar-thumb-accent"
@@ -324,13 +352,7 @@ export const NavRailItem = forwardRef<HTMLButtonElement, NavRailItemProps>(
) => {
const Comp = asChild ? Slot : "button";
- // Radix triggers (menus, popovers) pass their open state as `data-state`.
- const isTriggerOpen =
- (props as Record<string, unknown>)["data-state"] === "open";
- const hold = useContext(NavRailHoldContext);
- useEffect(() => {
- if (isTriggerOpen && hold) return hold();
- }, [isTriggerOpen, hold]);
+ useNavRailHold(props);
return (
<Comp
@@ -429,41 +451,122 @@ export function NavRailLink({
);
}
-/** For `header`: the logo sits in the icon column, the name has equal margins. */
-export function NavRailBrand({
- href,
- logo,
- label
-}: {
- href: string;
- logo: ReactNode;
+type NavRailSwitcherProps = Omit<
+ ButtonHTMLAttributes<HTMLButtonElement>,
+ "children"
+> & {
+ /** The company's logo for each colour mode; its initials stand in for none. */
+ logoLight?: string | null;
+ logoDark?: string | null;
+ /** Also the accessible name unless `aria-label` is given. */
label: string;
-}) {
- return (
- <a
- href={href}
- aria-label={label}
- className={cn(
- "relative flex h-10 w-full items-center gap-2 rounded-md px-2",
- "text-sm font-medium text-foreground select-none",
- "transition-[background-color] duration-100 ease-out hover:bg-active/60",
- focusRingClasses
- )}
- >
- <span className="flex size-6 shrink-0 items-center justify-center [&>svg]:size-4">
- {logo}
- </span>
- <span
- aria-hidden
- className="min-w-0 flex-1 truncate md:opacity-0 transition-opacity duration-200 group-data-[state=expanded]:opacity-100"
+ /** After the name, e.g. chevrons for a menu or an arrow for a link out. */
+ trailing?: ReactNode;
+ asChild?: boolean;
+ children?: ReactNode;
+};
+
+/**
+ * For `header`: the company. The logo sits in the icon column, so it stays put
+ * as the rail grows, and the name fades in beside it. A menu trigger by
+ * default; with `asChild`, a link. On phones it is a full-width row.
+ */
+export const NavRailSwitcher = forwardRef<
+ HTMLButtonElement,
+ NavRailSwitcherProps
+>(
+ (
+ {
+ logoLight,
+ logoDark,
+ label,
+ trailing,
+ asChild = false,
+ className,
+ children,
+ ...props
+ },
+ ref
+ ) => {
+ const Comp = asChild ? Slot : "button";
+ const logo = useMode() === "dark" ? logoDark : logoLight;
+ // Its menu is a portal: without the hold, the rail collapses under it.
+ useNavRailHold(props);
+
+ return (
+ <Comp
+ ref={ref}
+ type={asChild ? undefined : "button"}
+ aria-label={label}
+ {...props}
+ className={cn(
+ "relative flex h-10 shrink-0 items-center rounded-md select-none",
+ // Fills the header row beside the toggle. Not on phones: there it
+ // sits in a sheet's column, where flex-1 would collapse its height.
+ "max-md:w-full md:w-10 md:group-data-[state=expanded]:min-w-0 md:group-data-[state=expanded]:flex-1",
+ "text-sm font-medium text-foreground",
+ "transition-[background-color] duration-100 ease-out hover:bg-active/60 data-[state=open]:bg-active/60",
+ focusRingClasses,
+ className
+ )}
>
- {label}
- </span>
- <LuArrowUpRight
- aria-hidden
- className="hidden size-4 shrink-0 text-muted-foreground max-md:block"
- />
- </a>
+ <span className="absolute left-2 top-2 flex size-6 items-center justify-center [&>svg]:size-4">
+ {logo ? (
+ <img src={logo} alt="" className="size-6 rounded object-contain" />
+ ) : (
+ <Avatar size="xs" name={label} />
+ )}
+ </span>
+ <span
+ aria-hidden
+ className={cn(
+ "absolute left-12 right-2 flex min-w-0 items-center gap-1",
+ "md:opacity-0 transition-opacity duration-200 group-data-[state=expanded]:opacity-100"
+ )}
+ >
+ <span className="min-w-0 flex-1 truncate text-left">{label}</span>
+ {trailing ? (
+ <span className="flex shrink-0 text-muted-foreground [&>svg]:size-3.5">
+ {trailing}
+ </span>
+ ) : null}
+ </span>
+ <Slottable>{children}</Slottable>
+ </Comp>
+ );
+ }
+);
+NavRailSwitcher.displayName = "NavRailSwitcher";
+
+/**
+ * Keeps the rail open (pinned) or lets it collapse back to icons on mouse
+ * leave. Shown only while the rail is expanded: collapsed, it is only wide
+ * enough for the logo, and hovering it expands it.
+ */
+function NavRailToggle() {
+ const { t } = useLingui();
+ const { open, toggleSidebar } = useSidebar();
+ const label = open ? t`Collapse navigation` : t`Keep navigation open`;
+
+ return (
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <IconButton
+ aria-label={label}
+ aria-pressed={open}
+ icon={<LuPanelLeft />}
+ variant="ghost"
+ onClick={toggleSidebar}
+ className="hidden shrink-0 text-muted-foreground group-data-[state=expanded]:inline-flex"
+ />
+ </TooltipTrigger>
+ <TooltipContent side="right">
+ <span className="flex items-center gap-2">
+ {label}
+ <ShortcutKey shortcut={SHORTCUTS.sidebarToggle} variant="small" />
+ </span>
+ </TooltipContent>
+ </Tooltip>
);
}
diff --git a/packages/react/src/Sidebar.tsx b/packages/react/src/Sidebar.tsx
index 6aadc776cd..f587ad5bf7 100644
--- a/packages/react/src/Sidebar.tsx
+++ b/packages/react/src/Sidebar.tsx
@@ -26,8 +26,6 @@ import {
import { cn } from "./utils/cn";
import { useViewport } from "./Viewport";
-const SIDEBAR_COOKIE_NAME = "sidebar:state";
-const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7;
const SIDEBAR_WIDTH = "16rem";
const SIDEBAR_WIDTH_MOBILE = "18rem";
const SIDEBAR_WIDTH_ICON = "3rem";
@@ -96,9 +94,6 @@ const SidebarProvider = React.forwardRef<
} else {
_setOpen(openState);
}
-
- // This sets the cookie to keep the sidebar state.
- document.cookie = `${SIDEBAR_COOKIE_NAME}=${openState}; path=/; max-age=${SIDEBAR_COOKIE_MAX_AGE}`;
},
[setOpenProp, open]
);
diff --git a/packages/react/src/index.tsx b/packages/react/src/index.tsx
index 4c5d2a25f3..7e344738ce 100644
--- a/packages/react/src/index.tsx
+++ b/packages/react/src/index.tsx
@@ -273,11 +273,11 @@ import type { MultiSelectProps } from "./MultiSelect";
import { MultiSelect } from "./MultiSelect";
import {
NavRail,
- NavRailBrand,
NavRailDivider,
NavRailGroup,
NavRailItem,
NavRailLink,
+ NavRailSwitcher,
navRailItemClasses
} from "./NavRail";
import type { NumberFieldProps } from "./Number";
@@ -621,11 +621,11 @@ export {
NumberField,
NumberIncrementStepper,
NavRail,
- NavRailBrand,
NavRailDivider,
NavRailGroup,
NavRailItem,
NavRailLink,
+ NavRailSwitcher,
navRailItemClasses,
NumberInput,
NumberInputGroup,