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.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
fix(mobile): desktop keeps its Escape, dialog clicks and MES operation dock; MES gets the viewport hint
aashu67df84961339
diff --git a/apps/erp/app/components/Table/Table.tsx b/apps/erp/app/components/Table/Table.tsxindex ec81a1bcbf..b10b8a26bc 100644--- a/apps/erp/app/components/Table/Table.tsx+++ b/apps/erp/app/components/Table/Table.tsx@@ -628,6 +628,7 @@ const Table = <T extends object>({focusOnSelectedCell();});+ const { isPhone } = useViewport();// Clicking outside the table clears the selected cell (and ends any edit). A// cell's editable input commits on blur first, so the value is saved before// this runs. Portaled dropdowns (e.g. a cell's combobox popover, or its@@ -638,7 +639,13 @@ const Table = <T extends object>({enabled: selectedCell != null,handler: (e) => {const target = e.target as HTMLElement | null;- if (target?.closest("[data-radix-popper-content-wrapper],[role=dialog]"))+ if (+ target?.closest(+ isPhone+ ? "[data-radix-popper-content-wrapper],[role=dialog]"+ : "[data-radix-popper-content-wrapper]"+ )+ )return;setIsEditing(false);setSelectedCell(null);@@ -1115,7 +1122,6 @@ const Table = <T extends object>({params.getAll("sort").filter(Boolean).length === 0 &&!params.get("search")?.trim();- const { isPhone } = useViewport();// Phones export from the toolbar's ⋯ (list and grid alike); desktop keeps// the toolbar's Download button.const csvExport = withCsvExportdiff --git a/apps/mes/app/components/JobDag/JobDag.tsx b/apps/mes/app/components/JobDag/JobDag.tsxindex 324fd443d5..6ead88cd02 100644--- a/apps/mes/app/components/JobDag/JobDag.tsx+++ b/apps/mes/app/components/JobDag/JobDag.tsx@@ -158,14 +158,13 @@ function computeLayout(}function JobDagInner({ operations, dependencies }: Props) {- const [direction, setDirection] = useState<LayoutDirection>("LR");const { t } = useLingui();const { isPhone } = useViewport();- // MES has no server viewport hint, so the first render is desktop.- // Switch a phone to top-to-bottom once, after hydration. The toggle stays.- useEffect(() => {- if (isPhone) setDirection("TB");- }, [isPhone]);+ // Phones read top to bottom until the operator picks a direction.+ const [chosenDirection, setDirection] = useState<LayoutDirection | null>(+ null+ );+ const direction = chosenDirection ?? (isPhone ? "TB" : "LR");const { fitView } = useReactFlow();// On a phone, fitting the whole graph shrinks nodes past reading size, so// fit no smaller than 0.6 and let the operator pan the rest.@@ -189,8 +188,8 @@ function JobDagInner({ operations, dependencies }: Props) {}, [layoutNodes, layoutEdges, setNodes, setEdges, fitView, fitViewOptions]);const toggleDirection = useCallback(() => {- setDirection((d) => (d === "LR" ? "TB" : "LR"));- }, []);+ setDirection(direction === "LR" ? "TB" : "LR");+ }, [direction]);const handleFitView = useCallback(() => {fitView(fitViewOptions);diff --git a/apps/mes/app/components/JobOperation/JobOperation.tsx b/apps/mes/app/components/JobOperation/JobOperation.tsxindex 17b4ca1acf..7a9039de97 100644--- a/apps/mes/app/components/JobOperation/JobOperation.tsx+++ b/apps/mes/app/components/JobOperation/JobOperation.tsx@@ -63,6 +63,7 @@ import {useKeyboardWedge,useMode,useRouteData,+ useViewport,VStack} from "@carbon/react";import type { TrackedEntityAttributes } from "@carbon/utils";@@ -244,6 +245,7 @@ export const JobOperation = ({workCenter}: JobOperationProps) => {const { t } = useLingui();+ const { isPhone } = useViewport();const { formatRelativeTime } = useDateFormatter();const [params, setParams] = useUrlParams();const origin = useOrigin();@@ -496,12 +498,16 @@ export const JobOperation = ({labor: t`Labor`,machine: t`Machine`} as const;- // The caption follows the toggle: the selected type's timer when it runs,- // else the first running one in the toggle's order (Setup, Machine, Labor).+ // Phones: the caption follows the toggle, the selected type's timer when it+ // runs, else the first running one in the toggle's order.const selectedType = eventType.toLowerCase() as keyof typeof workTypeLabels;- const runningType = active[selectedType]- ? selectedType- : (["setup", "machine", "labor"] as const).find((type) => active[type]);+ const runningType =+ isPhone && active[selectedType]+ ? selectedType+ : (isPhone+ ? (["setup", "machine", "labor"] as const)+ : (["setup", "labor", "machine"] as const)+ ).find((type) => active[type]);// Chat is one job's thread, so a Chat tab left open in the job scope falls// back to Details on the batch.const tab = scope === "batch" && activeTab === "chat" ? "details" : activeTab;@@ -2549,7 +2555,7 @@ export const JobOperation = ({>{/* Phones: the work-type picker on its own row, then the bigbutton with what is running beside it, then Log and More. */}- <div className="flex w-full min-w-0 items-center gap-2 lg:flex-col lg:py-2 max-lg:flex-wrap max-lg:gap-y-1 max-md:gap-y-2">+ <div className="flex w-full min-w-0 items-center gap-2 lg:flex-col lg:py-2 max-md:flex-wrap max-md:gap-y-2"><dl className="hidden w-full gap-3 rounded-lg border bg-card p-3 lg:grid lg:group-data-[collapsed=true]/dock:hidden"><div className="min-w-0"><dt className="text-xs text-muted-foreground">@@ -2615,12 +2621,9 @@ export const JobOperation = ({only; the rail and the phone bar stay icon-sized. */}<divclassName={cn(- "flex flex-col items-center gap-0.5 text-center lg:group-data-[collapsed=true]/dock:hidden",- // Tablets: one centred line over the controls, while a timer runs.- "md:max-lg:order-first md:max-lg:basis-full md:max-lg:flex-row md:max-lg:justify-center md:max-lg:gap-1",+ "flex flex-col items-center gap-0.5 text-center md:max-lg:hidden lg:group-data-[collapsed=true]/dock:hidden",// Phones: the caption beside the button, the type over the time.- "max-md:min-w-0 max-md:items-start max-md:gap-0 max-md:text-left max-md:whitespace-nowrap",- !runningType && "md:max-lg:hidden"+ "max-md:min-w-0 max-md:items-start max-md:gap-0 max-md:text-left max-md:whitespace-nowrap")}>{runningType ? (@@ -2629,13 +2632,7 @@ export const JobOperation = ({<span className="size-2 animate-pulse rounded-full bg-emerald-500" /><span>{workTypeLabels[runningType]}</span></span>- <span- aria-hidden- className="hidden text-xs text-muted-foreground md:max-lg:inline md:max-lg:text-sm"- >- ·- </span>- <span className="font-mono text-lg tabular-nums md:max-lg:text-sm max-md:text-base max-md:font-semibold max-md:leading-tight">+ <span className="font-mono text-lg tabular-nums max-md:text-base max-md:font-semibold max-md:leading-tight">{formatDurationMilliseconds(progress[runningType], {style: "short"})}@@ -2677,13 +2674,6 @@ export const JobOperation = ({: completeModal.onOpen}/>- <span className="whitespace-nowrap text-xs text-muted-foreground lg:hidden max-md:hidden">- {isBatched ? (- <Trans>Complete batch</Trans>- ) : (- <Trans>Log completed</Trans>- )}- </span></div><div className="flex flex-col items-center gap-0.5"><IconButtonWithTooltip@@ -2693,9 +2683,6 @@ export const JobOperation = ({tooltip={t`More Actions`}onClick={actionsSheet.onOpen}/>- <span className="whitespace-nowrap text-xs text-muted-foreground lg:hidden max-md:hidden">- <Trans>More</Trans>- </span></div></div><div className="hidden w-full flex-col gap-2 lg:flex lg:group-data-[collapsed=true]/dock:hidden">@@ -2755,7 +2742,7 @@ export const JobOperation = ({}}><BottomSheetContent className="max-w-md mx-auto">- <BottomSheetHeader>+ <BottomSheetHeader className="md:sr-only"><BottomSheetTitle><Trans>More actions</Trans></BottomSheetTitle>diff --git a/apps/mes/app/components/JobOperation/components/Controls.tsx b/apps/mes/app/components/JobOperation/components/Controls.tsxindex 067e43b68a..d7be198e7d 100644--- a/apps/mes/app/components/JobOperation/components/Controls.tsx+++ b/apps/mes/app/components/JobOperation/components/Controls.tsx@@ -212,11 +212,11 @@ export function WorkTypeToggle({aria-label={t`Toggle setup`}><LuTimer className="size-6 pt-1 max-md:size-4 max-md:pt-0" />- <span className="text-xxs max-lg:text-xs max-md:text-sm lg:group-data-[collapsed=true]/dock:sr-only">+ <span className="text-xxs max-md:text-sm lg:group-data-[collapsed=true]/dock:sr-only"><Trans>Setup</Trans></span>{active.setup && (- <span className="absolute -top-1 -right-1 h-3 w-3 max-lg:size-3.5 max-lg:ring-2 max-lg:ring-background max-md:top-1.5 max-md:right-1.5 max-md:size-2 max-md:ring-0 bg-emerald-500 rounded-full" />+ <span className="absolute -top-1 -right-1 h-3 w-3 max-md:top-1.5 max-md:right-1.5 max-md:size-2 bg-emerald-500 rounded-full" />)}</ToggleGroupItem>)}@@ -228,11 +228,11 @@ export function WorkTypeToggle({aria-label={t`Toggle labor`}><LuHardHat className="size-6 pt-1 max-md:size-4 max-md:pt-0" />- <span className="text-xxs max-lg:text-xs max-md:text-sm lg:group-data-[collapsed=true]/dock:sr-only">+ <span className="text-xxs max-md:text-sm lg:group-data-[collapsed=true]/dock:sr-only"><Trans>Labor</Trans></span>{active.labor && (- <span className="absolute -top-1 -right-1 h-3 w-3 max-lg:size-3.5 max-lg:ring-2 max-lg:ring-background max-md:top-1.5 max-md:right-1.5 max-md:size-2 max-md:ring-0 bg-emerald-500 rounded-full" />+ <span className="absolute -top-1 -right-1 h-3 w-3 max-md:top-1.5 max-md:right-1.5 max-md:size-2 bg-emerald-500 rounded-full" />)}</ToggleGroupItem>)}@@ -244,11 +244,11 @@ export function WorkTypeToggle({aria-label={t`Toggle machine`}><LuHammer className="size-6 pt-1 max-md:size-4 max-md:pt-0" />- <span className="text-xxs max-lg:text-xs max-md:text-sm lg:group-data-[collapsed=true]/dock:sr-only">+ <span className="text-xxs max-md:text-sm lg:group-data-[collapsed=true]/dock:sr-only"><Trans>Machine</Trans></span>{active.machine && (- <span className="absolute -top-1 -right-1 h-3 w-3 max-lg:size-3.5 max-lg:ring-2 max-lg:ring-background max-md:top-1.5 max-md:right-1.5 max-md:size-2 max-md:ring-0 bg-emerald-500 rounded-full" />+ <span className="absolute -top-1 -right-1 h-3 w-3 max-md:top-1.5 max-md:right-1.5 max-md:size-2 bg-emerald-500 rounded-full" />)}</ToggleGroupItem>)}diff --git a/apps/mes/app/components/JobOperation/hooks/useOperation.tsx b/apps/mes/app/components/JobOperation/hooks/useOperation.tsxindex c7eaf4be1e..8571249c95 100644--- a/apps/mes/app/components/JobOperation/hooks/useOperation.tsx+++ b/apps/mes/app/components/JobOperation/hooks/useOperation.tsx@@ -4,7 +4,7 @@import { useCarbon } from "@carbon/auth";import { useChangedRows } from "@carbon/query";-import { toast, useDisclosure, useInterval } from "@carbon/react";+import { toast, useDisclosure, useInterval, useViewport } from "@carbon/react";import {getLocalTimeZone,now,@@ -92,8 +92,9 @@ export function useOperation({);const [activeTab, setActiveTab] = useState("details");- // Opens on the timer that runs, so Pause shows for it. A Setup or Labor- // timer counts only when it is this user's; Machine counts for anyone+ const { isPhone } = useViewport();+ // Phones open on the timer that runs, so Pause shows for it. A Setup or+ // Labor timer counts only when it is this user's; Machine counts for anyone// (the same rule as `activeEvents` below). Else: Setup, Machine, Labor.const [eventType, setEventType] = useState<string>(() => {const isRunning = (type: string) =>@@ -103,7 +104,8 @@ export function useOperation({e.endTime === null &&(type === "Machine" || e.employeeId === user.id));- const running = (["Setup", "Machine", "Labor"] as const).find(isRunning);+ const running =+ isPhone && (["Setup", "Machine", "Labor"] as const).find(isRunning);if (running) {return running;}diff --git a/apps/mes/app/root.tsx b/apps/mes/app/root.tsxindex c29b574802..849f115309 100644--- a/apps/mes/app/root.tsx+++ b/apps/mes/app/root.tsx@@ -21,13 +21,15 @@ import {OperatingSystemContextProvider,Toaster,TooltipProvider,- useMode+ useMode,+ ViewportProvider} from "@carbon/react";import { RootErrorBoundary } from "@carbon/react/ErrorBoundary";import type { Theme } from "@carbon/utils";import {colorSchemeHintScript,getPreferenceHeaders,+ getViewportHint,isSearchParamOnlyNavigation,modeValidator,prefetchCacheMiddleware,@@ -149,6 +151,7 @@ export async function loader({ request, context }: LoaderFunctionArgs) {VERCEL_URL},...getMode(request),+ viewport: getViewportHint(request),theme: getTheme(request),preferences,result: context.get(flashResultContext)@@ -309,24 +312,26 @@ export default function App() {return (<QueryClientProvider client={queryClient}><OperatingSystemContextProvider platform={prefs.platform}>- <LocaleProvider locale={appLanguage} catalog={catalog}>- <I18nProvider locale={prefs.locale}>- <TooltipProvider>- <MotionConfig reducedMotion="user">- <Document- mode={mode}- theme={theme}- lang={appLanguage}- env={env}- >- <Outlet />- {/* Renders nothing outside development; the package strips itself. */}- <ReactQueryDevtools buttonPosition="bottom-right" />- </Document>- </MotionConfig>- </TooltipProvider>- </I18nProvider>- </LocaleProvider>+ <ViewportProvider initialViewport={loaderData?.viewport ?? "desktop"}>+ <LocaleProvider locale={appLanguage} catalog={catalog}>+ <I18nProvider locale={prefs.locale}>+ <TooltipProvider>+ <MotionConfig reducedMotion="user">+ <Document+ mode={mode}+ theme={theme}+ lang={appLanguage}+ env={env}+ >+ <Outlet />+ {/* Renders nothing outside development; the package strips itself. */}+ <ReactQueryDevtools buttonPosition="bottom-right" />+ </Document>+ </MotionConfig>+ </TooltipProvider>+ </I18nProvider>+ </LocaleProvider>+ </ViewportProvider></OperatingSystemContextProvider></QueryClientProvider>);diff --git a/packages/react/src/hooks/useEscape.tsx b/packages/react/src/hooks/useEscape.tsxindex 5d8335816c..8a7571d00f 100644--- a/packages/react/src/hooks/useEscape.tsx+++ b/packages/react/src/hooks/useEscape.tsx@@ -9,9 +9,7 @@ export default function useEscape() {useEffect(() => {const listener = (e: KeyboardEvent) => {- // A Radix layer (menu, popover, sheet) that closed on this Escape has- // already handled it.- if (e.key === "Escape" && !e.defaultPrevented) {+ if (e.key === "Escape") {callback(e);}};