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: navigation in BOM explorer

Sidwebworksf35d23edd4d9
diff --git a/apps/erp/app/modules/production/ui/Jobs/JobBoMExplorer.tsx b/apps/erp/app/modules/production/ui/Jobs/JobBoMExplorer.tsx
index a100b7e6bb..b4119b7888 100644
--- a/apps/erp/app/modules/production/ui/Jobs/JobBoMExplorer.tsx
+++ b/apps/erp/app/modules/production/ui/Jobs/JobBoMExplorer.tsx
@@ -67,6 +67,7 @@ const JobBoMExplorer = ({ method }: JobBoMExplorerProps) => {
selectNode,
collapseAllBelowDepth,
scrollToNode,
+ deselectAllNodes,
virtualizer
} = useTree({
tree: method,
@@ -90,8 +91,13 @@ const JobBoMExplorer = ({ method }: JobBoMExplorerProps) => {
});
const [selectedMaterialId, setSelectedMaterialId] = useBom();
- // biome-ignore lint/correctness/useExhaustiveDependencies: suppressed due to migration
+ // biome-ignore lint/correctness/useExhaustiveDependencies: supress
useEffect(() => {
+ if (location.pathname === path.to.jobDetails(jobId!)) {
+ deselectAllNodes();
+ return;
+ }
+
if (selectedMaterialId) {
const node = method.find(
(m) => m.data.methodMaterialId === selectedMaterialId
@@ -107,7 +113,7 @@ const JobBoMExplorer = ({ method }: JobBoMExplorerProps) => {
selectNode(node.id);
}
}
- }, [selectedMaterialId, methodId]);
+ }, [selectedMaterialId, methodId, location.pathname, jobId]);
return (
<VStack className="flex-1 h-full w-full">
diff --git a/apps/erp/app/stores/bom.ts b/apps/erp/app/stores/bom.ts
index e2453f722f..9641a2a066 100644
--- a/apps/erp/app/stores/bom.ts
+++ b/apps/erp/app/stores/bom.ts
@@ -1,5 +1,17 @@
-import { atom } from "nanostores";
-import { useNanoStore } from "~/hooks";
+import { useUrlParams } from "~/hooks";
-const $bomStore = atom<string | null>(null);
-export const useBom = () => useNanoStore($bomStore, "bom");
+const PARAM_KEY = "material_id";
+
+export const useBom = () => {
+ const [params, setParams] = useUrlParams();
+
+ const id = params.get(PARAM_KEY);
+
+ const setId = (id: string | null) => {
+ setParams({
+ [PARAM_KEY]: id || undefined
+ });
+ };
+
+ return [id, setId] as const;
+};