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(mes): open a scanned ERP kanban URL on the ERP (#2045)

Brad Barbince332368abbf
diff --git a/apps/erp/app/routes/x+/_layout.tsx b/apps/erp/app/routes/x+/_layout.tsx
index 5acf4a0348..a116a65291 100644
--- a/apps/erp/app/routes/x+/_layout.tsx
+++ b/apps/erp/app/routes/x+/_layout.tsx
@@ -62,7 +62,7 @@ import type {
LoaderFunctionArgs,
ShouldRevalidateFunction
} from "react-router";
-import { Await, data, Outlet, useLoaderData, useNavigate } from "react-router";
+import { Await, data, Outlet, useLoaderData } from "react-router";
import { RealtimeDataProvider } from "~/components";
import ChangelogPanel from "~/components/ChangelogPanel";
import {
@@ -428,7 +428,6 @@ export default function AuthenticatedRoute() {
useEffect(() => {
shellLoadedAt = Date.now();
}, [loaderData]);
- const navigate = useNavigate();
const permissions = usePermissions();
const { isOpen, training, dismiss } = useTrainingPanel();
const changelogPanel = useChangelogPanel();
@@ -444,15 +443,7 @@ export default function AuthenticatedRoute() {
useNProgress();
useKeyboardWedge({
- test: (input) => input.startsWith(MES_URL) || input.startsWith(ERP_URL),
- callback: (input) => {
- try {
- const url = new URL(input);
- navigate(url.pathname + url.search);
- } catch {
- navigate(input);
- }
- }
+ test: (input) => input.startsWith(MES_URL) || input.startsWith(ERP_URL)
});
const userId = user?.id;
diff --git a/apps/mes/app/routes/x+/_layout.tsx b/apps/mes/app/routes/x+/_layout.tsx
index 154d506903..e1cb71edc8 100644
--- a/apps/mes/app/routes/x+/_layout.tsx
+++ b/apps/mes/app/routes/x+/_layout.tsx
@@ -68,8 +68,7 @@ import {
Form,
Outlet,
useLoaderData,
- useLocation,
- useNavigate
+ useLocation
} from "react-router";
import { AppSidebar } from "~/components";
import { ConsolePill } from "~/components/ConsolePill";
@@ -360,7 +359,6 @@ export default function AuthenticatedRoute() {
shellLoadedAt = Date.now();
}, [loaderData]);
- const navigate = useNavigate();
const { pathname } = useLocation();
const showTabBar = isTabBarPath(pathname);
const [moreOpen, setMoreOpen] = useState(false);
@@ -395,15 +393,7 @@ export default function AuthenticatedRoute() {
useKeyboardWedge({
test: (input) =>
(input.startsWith(MES_URL) || input.startsWith(ERP_URL)) &&
- !input.includes("/kanban/complete/"), // we handle this more gracefully in JobOperation
- callback: (input) => {
- try {
- const url = new URL(input);
- navigate(url.pathname + url.search);
- } catch {
- navigate(input);
- }
- }
+ !input.includes("/kanban/complete/") // we handle this more gracefully in JobOperation
});
const userId = user?.id;
diff --git a/packages/react/src/hooks/useKeyboardWedge.ts b/packages/react/src/hooks/useKeyboardWedge.ts
index b406639faf..5703068065 100644
--- a/packages/react/src/hooks/useKeyboardWedge.ts
+++ b/packages/react/src/hooks/useKeyboardWedge.ts
@@ -7,7 +7,7 @@ import { useNavigate } from "react-router";
interface UseKeyboardWedgeOptions {
test: (input: string) => boolean;
- callback: (input: string) => void;
+ callback?: (input: string) => void;
active?: boolean;
}
@@ -18,12 +18,20 @@ export function useKeyboardWedge(options?: UseKeyboardWedgeOptions) {
// Default test and callback for backward compatibility
const defaultTest = (input: string) => input.startsWith("http");
const defaultCallback = (input: string) => {
+ let url: URL;
try {
- const url = new URL(input);
- navigate(url.pathname + url.search);
+ url = new URL(input);
} catch {
navigate(input);
+ return;
}
+ // A link into the other app (an ERP kanban scanned in the MES) has a
+ // different origin, and its path does not exist here: load it there.
+ if (url.origin !== window.location.origin) {
+ window.location.assign(url.href);
+ return;
+ }
+ navigate(url.pathname + url.search);
};
const test = options?.test ?? defaultTest;