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.

refactor(erp): extract shared BoMExplorer component

Sidwebworks7cad0bd6f226
diff --git a/apps/erp/app/components/BoMExplorer/BoMExplorer.tsx b/apps/erp/app/components/BoMExplorer/BoMExplorer.tsx
new file mode 100644
index 0000000000..8cc03ff186
--- /dev/null
+++ b/apps/erp/app/components/BoMExplorer/BoMExplorer.tsx
@@ -0,0 +1,650 @@
+import {
+ Badge,
+ Copy,
+ cn,
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuIcon,
+ DropdownMenuItem,
+ DropdownMenuSeparator,
+ DropdownMenuTrigger,
+ HoverCard,
+ HoverCardContent,
+ HoverCardTrigger,
+ HStack,
+ IconButton,
+ Input,
+ InputGroup,
+ InputLeftElement,
+ VStack
+} from "@carbon/react";
+import { Trans, useLingui } from "@lingui/react/macro";
+import type { Dispatch, ReactNode, SetStateAction } from "react";
+import { createContext, useContext, useMemo, useRef, useState } from "react";
+import {
+ LuBraces,
+ LuChevronDown,
+ LuChevronRight,
+ LuChevronsUpDown,
+ LuEllipsisVertical,
+ LuExternalLink,
+ LuSearch,
+ LuTable
+} from "react-icons/lu";
+import { Link, useNavigate, useSearchParams } from "react-router";
+import { useOptimisticLocation } from "~/hooks";
+import { useIntegrations } from "~/hooks/useIntegrations";
+import { getLinkToItemDetails } from "~/modules/items/ui/Item/ItemForm";
+import { generateBomIds } from "~/utils/bom";
+import { MethodIcon, MethodItemTypeIcon, OnshapeStatus } from "../Icons";
+import type { FlatTree, FlatTreeItem, NodeState } from "../TreeView";
+import { LevelLine, TreeView, useTree } from "../TreeView";
+
+/**
+ * Structural contract every BoM tree node (JobMethod / Method / QuoteMethod)
+ * satisfies. Variants may carry extra fields; the shared explorer only reads
+ * these.
+ */
+export type BoMExplorerNodeData = {
+ description: string;
+ itemReadableId: string;
+ itemId: string;
+ itemType: string;
+ methodType: string;
+ quantity: number;
+ methodMaterialId: string;
+ kit?: boolean | null;
+ isRoot?: boolean | null;
+ version?: string | number | null;
+ unitOfMeasureCode?: string | null;
+ externalId?: unknown;
+ isPickDescendant?: boolean | null;
+};
+
+type BoMNode = FlatTreeItem<BoMExplorerNodeData>;
+
+type BoMExplorerContextValue = {
+ tree: FlatTree<BoMExplorerNodeData>;
+ nodes: ReturnType<typeof useTree>["nodes"];
+ getTreeProps: ReturnType<typeof useTree>["getTreeProps"];
+ getNodeProps: ReturnType<typeof useTree>["getNodeProps"];
+ virtualizer: ReturnType<typeof useTree>["virtualizer"];
+ parentRef: React.MutableRefObject<HTMLDivElement | null>;
+ toggleExpandNode: (id: string) => void;
+ expandAllBelowDepth: (depth: number) => void;
+ collapseAllBelowDepth: (depth: number) => void;
+ selectNode: (id: string, scrollIntoView?: boolean) => void;
+ deselectAllNodes: () => void;
+ allExpanded: boolean;
+ filterText: string;
+ setFilterText: (text: string) => void;
+ bomIdMap: Map<string, string>;
+ // Single shared "which node's preview is open" so only one hover card shows
+ // at a time (opening one row closes the others).
+ openNodeId: string | null;
+ setOpenNodeId: Dispatch<SetStateAction<string | null>>;
+ getNodePath: (node: BoMNode) => string;
+ getRootVersion: (node: BoMNode) => string | number | null | undefined;
+ onNodeClick: (node: BoMNode) => void;
+};
+
+const BoMExplorerContext = createContext<BoMExplorerContextValue | null>(null);
+
+export function useBoMExplorer() {
+ const context = useContext(BoMExplorerContext);
+ if (!context) {
+ throw new Error("useBoMExplorer must be used within a BoMExplorerProvider");
+ }
+ return context;
+}
+
+type BoMExplorerProviderProps<T extends BoMExplorerNodeData> = {
+ tree: FlatTree<T>;
+ /**
+ * Route for a node. May include a query string (e.g. `?methodId=`) — the
+ * shared click handler appends `materialId` with the right separator.
+ */
+ getNodePath: (node: FlatTreeItem<T>) => string;
+ /** Version shown on the root node's badge. Defaults to `node.data.version`. */
+ getRootVersion?: (
+ node: FlatTreeItem<T>
+ ) => string | number | null | undefined;
+ /** Controlled filter text (e.g. from an external search input). */
+ filterText?: string;
+ children: ReactNode;
+};
+
+export function BoMExplorerProvider<T extends BoMExplorerNodeData>({
+ tree: treeProp,
+ getNodePath: getNodePathProp,
+ getRootVersion: getRootVersionProp,
+ filterText: filterTextProp,
+ children
+}: BoMExplorerProviderProps<T>) {
+ const tree = treeProp as FlatTree<BoMExplorerNodeData>;
+ const getNodePath = getNodePathProp as (node: BoMNode) => string;
+ const getRootVersion =
+ (getRootVersionProp as
+ | ((node: BoMNode) => string | number | null | undefined)
+ | undefined) ?? ((node: BoMNode) => node.data.version);
+
+ const parentRef = useRef<HTMLDivElement>(null);
+ const navigate = useNavigate();
+ const location = useOptimisticLocation();
+ const [, setSearchParams] = useSearchParams();
+
+ const [filterTextInternal, setFilterTextInternal] = useState("");
+ const filterText = filterTextProp ?? filterTextInternal;
+
+ const [openNodeId, setOpenNodeId] = useState<string | null>(null);
+
+ const {
+ nodes,
+ getTreeProps,
+ getNodeProps,
+ toggleExpandNode,
+ expandAllBelowDepth,
+ collapseAllBelowDepth,
+ deselectAllNodes,
+ selectNode,
+ virtualizer
+ } = useTree({
+ tree,
+ // biome-ignore lint/suspicious/noEmptyBlockStatements: selection is URL-driven
+ onSelectedIdChanged: () => {},
+ estimatedRowHeight: () => 32,
+ parentRef,
+ filter: {
+ value: { text: filterText },
+ fn: (value, node) => {
+ if (value.text === "") return true;
+ return node.data.description
+ .toLowerCase()
+ .includes(value.text.toLowerCase());
+ }
+ },
+ isEager: true
+ });
+
+ const allExpanded = useMemo(
+ () => tree.every((m) => !m.hasChildren || nodes[m.id]?.expanded),
+ [tree, nodes]
+ );
+
+ // Generate hierarchical BOM IDs (1, 1.1, 1.1.1, etc.)
+ const bomIds = useMemo(() => generateBomIds(tree), [tree]);
+ const bomIdMap = useMemo(
+ () => new Map(tree.map((node, index) => [node.id, bomIds[index]])),
+ [tree, bomIds]
+ );
+
+ const onNodeClick = (node: BoMNode) => {
+ selectNode(node.id, false);
+
+ const nodePath = getNodePath(node);
+ const separator = nodePath.includes("?") ? "&" : "?";
+ const fullPath = `${nodePath}${separator}materialId=${node.data.methodMaterialId}`;
+ const nodePathname = nodePath.split("?")[0];
+
+ if (location.pathname !== nodePathname) {
+ navigate(fullPath, { replace: true });
+ } else {
+ setSearchParams((prev) => {
+ prev.set("materialId", node.data.methodMaterialId);
+ return prev;
+ });
+ }
+ };
+
+ return (
+ <BoMExplorerContext.Provider
+ value={{
+ tree,
+ nodes,
+ getTreeProps,
+ getNodeProps,
+ virtualizer,
+ parentRef,
+ toggleExpandNode,
+ expandAllBelowDepth,
+ collapseAllBelowDepth,
+ selectNode,
+ deselectAllNodes,
+ allExpanded,
+ filterText,
+ setFilterText: setFilterTextInternal,
+ bomIdMap,
+ openNodeId,
+ setOpenNodeId,
+ getNodePath,
+ getRootVersion,
+ onNodeClick
+ }}
+ >
+ {children}
+ </BoMExplorerContext.Provider>
+ );
+}
+
+export function BoMExplorerSearch() {
+ const { t } = useLingui();
+ const { filterText, setFilterText } = useBoMExplorer();
+
+ return (
+ <InputGroup size="sm" className="flex flex-grow">
+ <InputLeftElement>
+ <LuSearch className="h-4 w-4" />
+ </InputLeftElement>
+ <Input
+ placeholder={t`Search...`}
+ value={filterText}
+ onChange={(e) => setFilterText(e.target.value)}
+ />
+ </InputGroup>
+ );
+}
+
+type BoMExplorerActionsProps = {
+ triggerVariant?: "ghost" | "secondary";
+ children?: ReactNode;
+};
+
+/**
+ * Dropdown with the shared expand/collapse action; variant-specific items
+ * (export links, etc.) compose in as children.
+ */
+export function BoMExplorerActions({
+ triggerVariant = "secondary",
+ children
+}: BoMExplorerActionsProps) {
+ const { t } = useLingui();
+ const { allExpanded, expandAllBelowDepth, collapseAllBelowDepth } =
+ useBoMExplorer();
+
+ return (
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <IconButton
+ aria-label={t`Actions`}
+ variant={triggerVariant}
+ size="sm"
+ icon={<LuEllipsisVertical />}
+ />
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="end">
+ <DropdownMenuItem
+ onClick={() => {
+ if (allExpanded) {
+ collapseAllBelowDepth(1);
+ } else {
+ expandAllBelowDepth(0);
+ }
+ }}
+ >
+ <DropdownMenuIcon icon={<LuChevronsUpDown />} />
+ {allExpanded ? (
+ <Trans>Collapse all</Trans>
+ ) : (
+ <Trans>Expand all</Trans>
+ )}
+ </DropdownMenuItem>
+ {children && (
+ <>
+ <DropdownMenuSeparator />
+ {children}
+ </>
+ )}
+ </DropdownMenuContent>
+ </DropdownMenu>
+ );
+}
+
+type BoMExportMenuItemsProps = {
+ csvHref: (withOperations: boolean) => string;
+ jsonHref: (withOperations: boolean) => string;
+};
+
+/**
+ * The four BoM / BoM+BoP export links. Pure props (no context) so it also
+ * works in standalone menus like BoMActions.
+ */
+export function BoMExportMenuItems({
+ csvHref,
+ jsonHref
+}: BoMExportMenuItemsProps) {
+ return (
+ <>
+ <DropdownMenuItem asChild>
+ <a href={csvHref(false)} target="_blank" rel="noreferrer">
+ <DropdownMenuIcon icon={<LuTable />} />
+ <div className="flex flex-grow items-center gap-4 justify-between">
+ <span>BoM</span>
+ <Badge variant="green" className="text-xs">
+ CSV
+ </Badge>
+ </div>
+ </a>
+ </DropdownMenuItem>
+ <DropdownMenuItem asChild>
+ <a href={csvHref(true)} target="_blank" rel="noreferrer">
+ <DropdownMenuIcon icon={<LuTable />} />
+ <div className="flex flex-grow items-center gap-4 justify-between">
+ <span>BoM + BoP</span>
+ <Badge variant="green" className="text-xs">
+ CSV
+ </Badge>
+ </div>
+ </a>
+ </DropdownMenuItem>
+ <DropdownMenuItem asChild>
+ <a href={jsonHref(false)} target="_blank" rel="noreferrer">
+ <DropdownMenuIcon icon={<LuBraces />} />
+ <div className="flex flex-grow items-center gap-4 justify-between">
+ <span>BoM</span>
+ <Badge variant="outline" className="text-xs">
+ JSON
+ </Badge>
+ </div>
+ </a>
+ </DropdownMenuItem>
+ <DropdownMenuItem asChild>
+ <a href={jsonHref(true)} target="_blank" rel="noreferrer">
+ <DropdownMenuIcon icon={<LuBraces />} />
+ <div className="flex flex-grow items-center gap-4 justify-between">
+ <span>BoM + BoP</span>
+ <Badge variant="outline" className="text-xs">
+ JSON
+ </Badge>
+ </div>
+ </a>
+ </DropdownMenuItem>
+ </>
+ );
+}
+
+type BoMExplorerTreeProps = {
+ className?: string;
+ /**
+ * Render prop for rows that need variant extras. Defaults to a plain
+ * `<BoMExplorerRow />`.
+ */
+ children?: (params: { node: BoMNode; state: NodeState }) => ReactNode;
+};
+
+export function BoMExplorerTree({ className, children }: BoMExplorerTreeProps) {
+ const { tree, nodes, getNodeProps, getTreeProps, parentRef, virtualizer } =
+ useBoMExplorer();
+
+ return (
+ <div className={cn("flex flex-1 min-h-0 w-full", className)}>
+ <TreeView
+ parentRef={parentRef}
+ virtualizer={virtualizer}
+ autoFocus
+ tree={tree}
+ nodes={nodes}
+ getNodeProps={getNodeProps}
+ getTreeProps={getTreeProps}
+ parentClassName="h-full"
+ renderNode={({ node, state }) =>
+ children ? (
+ children({ node, state })
+ ) : (
+ <BoMExplorerRow node={node} state={state} />
+ )
+ }
+ />
+ </div>
+ );
+}
+
+type BoMExplorerRowProps = {
+ node: BoMNode;
+ state: NodeState;
+ /** Variant extras rendered in the row's trailing badge area. */
+ children?: ReactNode;
+};
+
+export function BoMExplorerRow({ node, state, children }: BoMExplorerRowProps) {
+ const {
+ bomIdMap,
+ openNodeId,
+ setOpenNodeId,
+ toggleExpandNode,
+ expandAllBelowDepth,
+ collapseAllBelowDepth,
+ getRootVersion,
+ onNodeClick
+ } = useBoMExplorer();
+
+ // Suppress the preview while the pointer is over the trailing badges, so
+ // their own tooltips are readable without the large preview card overlapping.
+ const [isBadgeHovered, setIsBadgeHovered] = useState(false);
+
+ const bomId = bomIdMap.get(node.id);
+
+ return (
+ <HoverCard
+ open={openNodeId === node.id && !isBadgeHovered}
+ onOpenChange={(nextOpen) => {
+ // Opening this node becomes the single open node (closing any other);
+ // closing only clears if this node is still the open one.
+ setOpenNodeId((current) =>
+ nextOpen ? node.id : current === node.id ? null : current
+ );
+ }}
+ openDelay={500}
+ closeDelay={150}
+ >
+ <HoverCardTrigger asChild>
+ <div
+ key={node.id}
+ className={cn(
+ "flex h-8 cursor-pointer items-center overflow-hidden rounded-sm pr-2 gap-1 group/node",
+ state.selected
+ ? "bg-muted hover:bg-accent"
+ : "bg-transparent hover:bg-accent",
+ node.data.isPickDescendant && "opacity-60"
+ )}
+ onClick={() => onNodeClick(node)}
+ >
+ <div className="flex h-8 items-center">
+ {Array.from({ length: node.level }).map((_, index) => (
+ <LevelLine key={index} isSelected={state.selected} />
+ ))}
+ <div
+ className={cn(
+ "flex h-8 w-4 items-center",
+ node.hasChildren && "hover:bg-accent"
+ )}
+ onClick={(e) => {
+ e.stopPropagation();
+ if (e.altKey) {
+ if (state.expanded) {
+ collapseAllBelowDepth(node.level);
+ } else {
+ expandAllBelowDepth(node.level);
+ }
+ } else {
+ toggleExpandNode(node.id);
+ }
+ }}
+ >
+ {node.hasChildren ? (
+ state.expanded ? (
+ <LuChevronDown className="h-4 w-4 text-gray-400 flex-shrink-0 ml-1" />
+ ) : (
+ <LuChevronRight className="h-4 w-4 text-gray-400 flex-shrink-0 ml-1" />
+ )
+ ) : (
+ <div className="h-8 w-4" />
+ )}
+ </div>
+ </div>
+
+ <div className="flex w-full min-w-0 items-center justify-between gap-2">
+ <div className="flex flex-1 min-w-0 items-center gap-2 overflow-hidden">
+ {bomId && (
+ <Badge variant="outline" className="flex-shrink-0">
+ {bomId}
+ </Badge>
+ )}
+ <BoMNodeText node={node} />
+ </div>
+ <div
+ className="flex flex-shrink-0 items-center gap-1"
+ onPointerEnter={() => setIsBadgeHovered(true)}
+ onPointerLeave={() => setIsBadgeHovered(false)}
+ >
+ {node.data.isRoot ? (
+ <Badge variant="outline" className="whitespace-nowrap">
+ V{getRootVersion(node)}
+ </Badge>
+ ) : (
+ <BoMNodeData node={node} />
+ )}
+ {children}
+ </div>
+ </div>
+ </div>
+ </HoverCardTrigger>
+ <HoverCardContent side="right">
+ <BoMNodePreview node={node} />
+ </HoverCardContent>
+ </HoverCard>
+ );
+}
+
+function getOnshapeState(node: BoMNode, hasOnshape: boolean) {
+ if (!hasOnshape) return null;
+ // @ts-expect-error -- externalId is untyped JSON
+ // biome-ignore lint/complexity/useLiteralKeys: untyped JSON access
+ return node.data.externalId?.["onshapeData"]?.["State"] ?? null;
+}
+
+function BoMNodeText({ node }: { node: BoMNode }) {
+ return (
+ <div className="flex min-w-0 items-center gap-1">
+ <span className="font-medium text-sm truncate">
+ {node.data.description || node.data.itemReadableId}
+ </span>
+ </div>
+ );
+}
+
+function BoMNodeData({ node }: { node: BoMNode }) {
+ const integrations = useIntegrations();
+ const onShapeState = getOnshapeState(node, integrations.has("onshape"));
+
+ return (
+ <HStack spacing={1}>
+ <Badge className="text-xs" variant="outline">
+ <MethodIcon
+ type={node.data.methodType}
+ isKit={node.data.kit ?? undefined}
+ className="mr-2"
+ />
+ {node.data.quantity}
+ </Badge>
+ {onShapeState && <OnshapeStatus status={onShapeState} />}
+ </HStack>
+ );
+}
+
+function BoMNodePreview({ node }: { node: BoMNode }) {
+ const { t } = useLingui();
+ const integrations = useIntegrations();
+ const onShapeState = getOnshapeState(node, integrations.has("onshape"));
+
+ return (
+ <VStack className="w-full text-sm">
+ <VStack spacing={1}>
+ <span className="text-xs text-muted-foreground font-medium">
+ <Trans>Item ID</Trans>
+ </span>
+ <HStack className="w-full justify-between">
+ <span>{node.data.itemReadableId}</span>
+ <HStack spacing={1}>
+ <Copy text={node.data.itemReadableId} tooltipClassName="z-[110]" />
+ <Link
+ to={getLinkToItemDetails(
+ node.data.itemType as "Part",
+ node.data.itemId
+ )}
+ target="_blank"
+ >
+ <IconButton
+ aria-label={t`View Item Master`}
+ size="sm"
+ variant="secondary"
+ icon={<LuExternalLink />}
+ />
+ </Link>
+ </HStack>
+ </HStack>
+ </VStack>
+ <VStack spacing={1}>
+ <span className="text-xs text-muted-foreground font-medium">
+ <Trans>Description</Trans>
+ </span>
+ <HStack className="w-full justify-between">
+ <span>{node.data.description}</span>
+ <Copy text={node.data.description} tooltipClassName="z-[110]" />
+ </HStack>
+ </VStack>
+ <VStack spacing={1}>
+ <span className="text-xs text-muted-foreground font-medium">
+ <Trans>Quantity</Trans>
+ </span>
+ <HStack className="w-full justify-between">
+ <span>
+ {node.data.quantity}
+ {node.data.unitOfMeasureCode
+ ? ` ${node.data.unitOfMeasureCode}`
+ : ""}
+ </span>
+ </HStack>
+ </VStack>
+ <VStack spacing={1}>
+ <span className="text-xs text-muted-foreground font-medium">
+ <Trans>Method</Trans>
+ </span>
+ <HStack className="w-full">
+ <MethodIcon type={node.data.methodType} />
+ <span>{node.data.methodType}</span>
+ </HStack>
+ </VStack>
+ <VStack spacing={1}>
+ <span className="text-xs text-muted-foreground font-medium">
+ <Trans>Item Type</Trans>
+ </span>
+ <HStack className="w-full">
+ <MethodItemTypeIcon type={node.data.itemType} />
+ <span>{node.data.itemType}</span>
+ </HStack>
+ </VStack>
+ {node.data.methodType === "Make to Order" &&
+ node.data.version != null && (
+ <VStack spacing={1}>
+ <span className="text-xs text-muted-foreground font-medium">
+ <Trans>Make Method Version</Trans>
+ </span>
+ <HStack className="w-full">
+ <Badge variant="outline">V{node.data.version}</Badge>
+ </HStack>
+ </VStack>
+ )}
+ {onShapeState && (
+ <VStack spacing={1}>
+ <span className="text-xs text-muted-foreground font-medium">
+ <Trans>Onshape Status</Trans>
+ </span>
+ <HStack className="w-full">
+ <OnshapeStatus status={onShapeState} />
+ <span>{onShapeState}</span>
+ </HStack>
+ </VStack>
+ )}
+ </VStack>
+ );
+}
diff --git a/apps/erp/app/components/BoMExplorer/index.ts b/apps/erp/app/components/BoMExplorer/index.ts
new file mode 100644
index 0000000000..7483dbcb9f
--- /dev/null
+++ b/apps/erp/app/components/BoMExplorer/index.ts
@@ -0,0 +1,10 @@
+export type { BoMExplorerNodeData } from "./BoMExplorer";
+export {
+ BoMExplorerActions,
+ BoMExplorerProvider,
+ BoMExplorerRow,
+ BoMExplorerSearch,
+ BoMExplorerTree,
+ BoMExportMenuItems,
+ useBoMExplorer
+} from "./BoMExplorer";
diff --git a/apps/erp/app/modules/items/ui/Item/BoMExplorer.tsx b/apps/erp/app/modules/items/ui/Item/BoMExplorer.tsx
index 2c041a1b68..15b457e49b 100644
--- a/apps/erp/app/modules/items/ui/Item/BoMExplorer.tsx
+++ b/apps/erp/app/modules/items/ui/Item/BoMExplorer.tsx
@@ -1,62 +1,39 @@
import {
- Badge,
- Copy,
- cn,
DropdownMenu,
DropdownMenuContent,
DropdownMenuIcon,
- DropdownMenuItem,
- DropdownMenuSeparator,
DropdownMenuSub,
DropdownMenuSubContent,
DropdownMenuSubTrigger,
DropdownMenuTrigger,
- HoverCard,
- HoverCardContent,
- HoverCardTrigger,
HStack,
IconButton,
- Input,
- InputGroup,
- InputLeftElement,
- useDisclosure,
- useOptimisticLocation,
VStack
} from "@carbon/react";
import { Trans, useLingui } from "@lingui/react/macro";
-import { useEffect, useMemo, useRef, useState } from "react";
+import { useEffect } from "react";
+import { LuDownload, LuEllipsisVertical } from "react-icons/lu";
+import { useParams, useSearchParams } from "react-router";
import {
- LuBraces,
- LuChevronDown,
- LuChevronRight,
- LuChevronsUpDown,
- LuDownload,
- LuEllipsisVertical,
- LuExternalLink,
- LuSearch,
- LuTable
-} from "react-icons/lu";
-import { Link, useNavigate, useParams, useSearchParams } from "react-router";
-import { MethodIcon, MethodItemTypeIcon } from "~/components";
-import { OnshapeStatus } from "~/components/Icons";
-import { ImportCSVModal } from "~/components/ImportCSVModal";
+ BoMExplorerActions,
+ BoMExplorerProvider,
+ BoMExplorerSearch,
+ BoMExplorerTree,
+ BoMExportMenuItems,
+ useBoMExplorer
+} from "~/components/BoMExplorer";
import { OnshapeSync } from "~/components/OnshapeSync";
import type { FlatTreeItem } from "~/components/TreeView";
-import { LevelLine, TreeView, useTree } from "~/components/TreeView";
import { useIntegrations } from "~/hooks/useIntegrations";
import type { ItemType } from "~/modules/shared";
-import { generateBomIds } from "~/utils/bom";
import { path } from "~/utils/path";
-import type { MakeMethod, Method, MethodOperation } from "../../types";
-import { getLinkToItemDetails } from "./ItemForm";
+import type { MakeMethod, Method } from "../../types";
type BoMExplorerProps = {
itemType: ItemType;
makeMethod: MakeMethod;
methods: FlatTreeItem<Method>[];
methodId?: string;
- operations?: MethodOperation[];
- selectedId?: string;
filterText?: string;
hideSearch?: boolean;
};
@@ -66,76 +43,72 @@ const BoMExplorer = ({
makeMethod,
methods,
methodId: methodIdProp,
- selectedId,
- filterText: filterTextProp,
+ filterText,
hideSearch
}: BoMExplorerProps) => {
- const [filterTextInternal, setFilterTextInternal] = useState("");
- const filterText = filterTextProp ?? filterTextInternal;
- const parentRef = useRef<HTMLDivElement>(null);
- const integrations = useIntegrations();
const params = useParams();
+ const { itemId } = params;
+ if (!itemId) throw new Error("itemId not found");
+ const methodId = methodIdProp ?? params.methodId;
+ if (!methodId) throw new Error("methodId not found");
+
const {
id: makeMethodId,
version: makeMethodVersion,
status: makeMethodStatus
} = makeMethod;
- const {
- nodes,
- getTreeProps,
- getNodeProps,
- toggleExpandNode,
- expandAllBelowDepth,
- collapseAllBelowDepth,
- deselectAllNodes,
- selectNode,
- virtualizer
- } = useTree({
- tree: methods,
- selectedId,
- // biome-ignore lint/suspicious/noEmptyBlockStatements: suppressed due to migration
- onSelectedIdChanged: () => {},
- estimatedRowHeight: () => 40,
- parentRef,
- filter: {
- value: { text: filterText },
- fn: (value, node) => {
- if (value.text === "") return true;
- if (
- node.data.description.toLowerCase().includes(value.text.toLowerCase())
- ) {
- return true;
- }
- return false;
- }
- },
- isEager: true
- });
-
- const allExpanded = useMemo(
- () => methods.every((m) => !m.hasChildren || nodes[m.id]?.expanded),
- [methods, nodes]
- );
+ const getNodePath = (node: FlatTreeItem<Method>) =>
+ node.data.isRoot
+ ? getRootLink(itemType, itemId, methodId)
+ : getMaterialLink(
+ itemType,
+ itemId,
+ methodId,
+ node.data.replenishmentSystem !== "Buy"
+ ? node.data.materialMakeMethodId
+ : node.data.makeMethodId
+ );
- // Generate hierarchical BOM IDs (1, 1.1, 1.1.1, etc.)
- const bomIds = useMemo(() => generateBomIds(methods), [methods]);
- const bomIdMap = useMemo(
- () => new Map(methods.map((node, index) => [node.id, bomIds[index]])),
- [methods, bomIds]
+ return (
+ <BoMExplorerProvider
+ tree={methods}
+ getNodePath={getNodePath}
+ getRootVersion={() => makeMethodVersion}
+ filterText={filterText}
+ >
+ <ItemBoMExplorerContent
+ methods={methods}
+ makeMethodId={makeMethodId}
+ makeMethodStatus={makeMethodStatus}
+ itemId={itemId}
+ hideSearch={hideSearch}
+ />
+ </BoMExplorerProvider>
);
+};
- const navigate = useNavigate();
- const { t } = useLingui();
- const location = useOptimisticLocation();
+export default BoMExplorer;
- const { itemId } = params;
- if (!itemId) throw new Error("itemId not found");
- const methodId = methodIdProp ?? params.methodId;
- if (!methodId) throw new Error("methodId not found");
+function ItemBoMExplorerContent({
+ methods,
+ makeMethodId,
+ makeMethodStatus,
+ itemId,
+ hideSearch
+}: {
+ methods: FlatTreeItem<Method>[];
+ makeMethodId: string;
+ makeMethodStatus: MakeMethod["status"];
+ itemId: string;
+ hideSearch?: boolean;
+}) {
+ const integrations = useIntegrations();
+ const params = useParams();
+ const { selectNode, deselectAllNodes } = useBoMExplorer();
- const [searchParams, setSearchParams] = useSearchParams();
+ const [searchParams] = useSearchParams();
const selectedMaterialId = searchParams.get("materialId");
// biome-ignore lint/correctness/useExhaustiveDependencies: suppressed due to migration
useEffect(() => {
@@ -157,272 +130,44 @@ const BoMExplorer = ({
}
}, [selectedMaterialId, params.methodId]);
- const importBomDisclosure = useDisclosure();
-
return (
- <>
- <VStack className="h-full">
- {!hideSearch && (
- <HStack className="w-full justify-between flex-shrink-0">
- <InputGroup size="sm" className="flex flex-grow">
- <InputLeftElement>
- <LuSearch className="h-4 w-4" />
- </InputLeftElement>
- <Input
- placeholder={t`Search...`}
- value={filterText}
- onChange={(e) => setFilterTextInternal(e.target.value)}
- />
- </InputGroup>
-
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <IconButton
- aria-label={t`Actions`}
- variant="secondary"
- size="sm"
- icon={<LuEllipsisVertical />}
+ <VStack className="h-full">
+ {!hideSearch && (
+ <HStack className="w-full justify-between flex-shrink-0">
+ <BoMExplorerSearch />
+ <BoMExplorerActions>
+ <DropdownMenuSub>
+ <DropdownMenuSubTrigger>
+ <DropdownMenuIcon icon={<LuDownload />} />
+ <Trans>Export</Trans>
+ </DropdownMenuSubTrigger>
+ <DropdownMenuSubContent>
+ <BoMExportMenuItems
+ csvHref={(withOperations) =>
+ path.to.api.billOfMaterialsCsv(makeMethodId, withOperations)
+ }
+ jsonHref={(withOperations) =>
+ path.to.api.billOfMaterials(makeMethodId, withOperations)
+ }
/>
- </DropdownMenuTrigger>
- <DropdownMenuContent align="end">
- <DropdownMenuItem
- onClick={() => {
- if (allExpanded) {
- collapseAllBelowDepth(1);
- } else {
- expandAllBelowDepth(0);
- }
- }}
- >
- <DropdownMenuIcon icon={<LuChevronsUpDown />} />
- {allExpanded ? (
- <Trans>Collapse all</Trans>
- ) : (
- <Trans>Expand all</Trans>
- )}
- </DropdownMenuItem>
- <DropdownMenuSeparator />
- <DropdownMenuSub>
- <DropdownMenuSubTrigger>
- <DropdownMenuIcon icon={<LuDownload />} />
- <Trans>Export</Trans>
- </DropdownMenuSubTrigger>
- <DropdownMenuSubContent>
- <DropdownMenuItem asChild>
- <a
- href={path.to.api.billOfMaterialsCsv(
- makeMethodId,
- false
- )}
- target="_blank"
- rel="noreferrer"
- >
- <DropdownMenuIcon icon={<LuTable />} />
- <div className="flex flex-grow items-center gap-4 justify-between">
- <span>BoM</span>
- <Badge variant="green" className="text-xs">
- CSV
- </Badge>
- </div>
- </a>
- </DropdownMenuItem>
- <DropdownMenuItem asChild>
- <a
- href={path.to.api.billOfMaterialsCsv(
- makeMethodId,
- true
- )}
- target="_blank"
- rel="noreferrer"
- >
- <DropdownMenuIcon icon={<LuTable />} />
- <div className="flex flex-grow items-center gap-4 justify-between">
- <span>BoM + BoP</span>
- <Badge variant="green" className="text-xs">
- CSV
- </Badge>
- </div>
- </a>
- </DropdownMenuItem>
- <DropdownMenuItem asChild>
- <a
- href={path.to.api.billOfMaterials(makeMethodId, false)}
- target="_blank"
- rel="noreferrer"
- >
- <DropdownMenuIcon icon={<LuBraces />} />
- <div className="flex flex-grow items-center gap-4 justify-between">
- <span>BoM</span>
- <Badge variant="outline" className="text-xs">
- JSON
- </Badge>
- </div>
- </a>
- </DropdownMenuItem>
- <DropdownMenuItem asChild>
- <a
- href={path.to.api.billOfMaterials(makeMethodId, true)}
- target="_blank"
- rel="noreferrer"
- >
- <DropdownMenuIcon icon={<LuBraces />} />
- <div className="flex flex-grow items-center gap-4 justify-between">
- <span>BoM + BoP</span>
- <Badge variant="outline" className="text-xs">
- JSON
- </Badge>
- </div>
- </a>
- </DropdownMenuItem>
- </DropdownMenuSubContent>
- </DropdownMenuSub>
- {/* <DropdownMenuItem onClick={importBomDisclosure.onOpen}>
- <DropdownMenuIcon icon={<LuUpload />} />
- Import
- </DropdownMenuItem> */}
- </DropdownMenuContent>
- </DropdownMenu>
- </HStack>
- )}
- {integrations.has("onshape") && (
- <div className="flex flex-shrink-0 w-full">
- <OnshapeSync
- makeMethodId={makeMethodId}
- itemId={itemId}
- isDisabled={makeMethodStatus !== "Draft"}
- />
- </div>
- )}
- <div className="flex flex-1 min-h-0 w-full">
- <TreeView
- parentRef={parentRef}
- virtualizer={virtualizer}
- autoFocus
- tree={methods}
- nodes={nodes}
- getNodeProps={getNodeProps}
- getTreeProps={getTreeProps}
- parentClassName="h-full"
- renderNode={({ node, state }) => {
- return (
- <HoverCard openDelay={500} closeDelay={150}>
- <HoverCardTrigger asChild>
- <div
- key={node.id}
- className={cn(
- "flex h-8 cursor-pointer items-center overflow-hidden rounded-sm pr-3 gap-1 group/node",
- state.selected
- ? "bg-muted hover:bg-accent"
- : "bg-transparent hover:bg-accent",
- node.data.isPickDescendant && "opacity-60"
- )}
- onClick={() => {
- selectNode(node.id, false);
-
- const nodePath = node.data.isRoot
- ? getRootLink(itemType, itemId, methodId)
- : getMaterialLink(
- itemType,
- itemId,
- methodId,
- node.data.replenishmentSystem !== "Buy"
- ? node.data.materialMakeMethodId
- : node.data.makeMethodId,
- node
- );
-
- const separator = nodePath.includes("?") ? "&" : "?";
- const fullPath = `${nodePath}${separator}materialId=${node.data.methodMaterialId}`;
- const nodePathname = nodePath.split("?")[0];
-
- if (location.pathname !== nodePathname) {
- navigate(fullPath, { replace: true });
- } else {
- setSearchParams((prev) => {
- prev.set("materialId", node.data.methodMaterialId);
- return prev;
- });
- }
- }}
- >
- <div className="flex h-8 items-center">
- {Array.from({ length: node.level }).map((_, index) => (
- <LevelLine key={index} isSelected={state.selected} />
- ))}
- <div
- className={cn(
- "flex h-8 w-4 items-center",
- node.hasChildren && "hover:bg-accent"
- )}
- onClick={(e) => {
- e.stopPropagation();
- if (e.altKey) {
- if (state.expanded) {
- collapseAllBelowDepth(node.level);
- } else {
- expandAllBelowDepth(node.level);
- }
- } else {
- toggleExpandNode(node.id);
- }
- }}
- >
- {node.hasChildren ? (
- state.expanded ? (
- <LuChevronDown className="h-4 w-4 text-gray-400 flex-shrink-0 ml-1" />
- ) : (
- <LuChevronRight className="h-4 w-4 text-gray-400 flex-shrink-0 ml-1" />
- )
- ) : (
- <div className="h-8 w-4" />
- )}
- </div>
- </div>
-
- <div className="flex w-full min-w-0 items-center justify-between gap-2">
- <div className="flex flex-1 min-w-0 items-center gap-2 overflow-hidden">
- {bomIdMap.get(node.id) && (
- <Badge variant="outline" className="flex-shrink-0">
- {bomIdMap.get(node.id)}
- </Badge>
- )}
- <NodeText node={node} />
- </div>
- <div className="flex flex-shrink-0 items-center gap-1">
- {node.data.isRoot ? (
- <Badge
- variant="outline"
- className="whitespace-nowrap"
- >
- V{makeMethodVersion}
- </Badge>
- ) : (
- <NodeData node={node} />
- )}
- </div>
- </div>
- </div>
- </HoverCardTrigger>
- <HoverCardContent side="right">
- <NodePreview node={node} />
- </HoverCardContent>
- </HoverCard>
- );
- }}
+ </DropdownMenuSubContent>
+ </DropdownMenuSub>
+ </BoMExplorerActions>
+ </HStack>
+ )}
+ {integrations.has("onshape") && (
+ <div className="flex flex-shrink-0 w-full">
+ <OnshapeSync
+ makeMethodId={makeMethodId}
+ itemId={itemId}
+ isDisabled={makeMethodStatus !== "Draft"}
/>
</div>
- </VStack>
- {importBomDisclosure.isOpen && (
- <ImportCSVModal
- table={"bom"}
- onClose={() => importBomDisclosure.onClose()}
- />
)}
- </>
+ <BoMExplorerTree />
+ </VStack>
);
-};
-
-export default BoMExplorer;
+}
export function BoMActions({ makeMethodId }: { makeMethodId: string }) {
const { t } = useLingui();
@@ -443,66 +188,14 @@ export function BoMActions({ makeMethodId }: { makeMethodId: string }) {
<Trans>Export</Trans>
</DropdownMenuSubTrigger>
<DropdownMenuSubContent>
- <DropdownMenuItem asChild>
- <a
- href={path.to.api.billOfMaterialsCsv(makeMethodId, false)}
- target="_blank"
- rel="noreferrer"
- >
- <DropdownMenuIcon icon={<LuTable />} />
- <div className="flex flex-grow items-center gap-4 justify-between">
- <span>BoM</span>
- <Badge variant="green" className="text-xs">
- CSV
- </Badge>
- </div>
- </a>
- </DropdownMenuItem>
- <DropdownMenuItem asChild>
- <a
- href={path.to.api.billOfMaterialsCsv(makeMethodId, true)}
- target="_blank"
- rel="noreferrer"
- >
- <DropdownMenuIcon icon={<LuTable />} />
- <div className="flex flex-grow items-center gap-4 justify-between">
- <span>BoM + BoP</span>
- <Badge variant="green" className="text-xs">
- CSV
- </Badge>
- </div>
- </a>
- </DropdownMenuItem>
- <DropdownMenuItem asChild>
- <a
- href={path.to.api.billOfMaterials(makeMethodId, false)}
- target="_blank"
- rel="noreferrer"
- >
- <DropdownMenuIcon icon={<LuBraces />} />
- <div className="flex flex-grow items-center gap-4 justify-between">
- <span>BoM</span>
- <Badge variant="outline" className="text-xs">
- JSON
- </Badge>
- </div>
- </a>
- </DropdownMenuItem>
- <DropdownMenuItem asChild>
- <a
- href={path.to.api.billOfMaterials(makeMethodId, true)}
- target="_blank"
- rel="noreferrer"
- >
- <DropdownMenuIcon icon={<LuBraces />} />
- <div className="flex flex-grow items-center gap-4 justify-between">
- <span>BoM + BoP</span>
- <Badge variant="outline" className="text-xs">
- JSON
- </Badge>
- </div>
- </a>
- </DropdownMenuItem>
+ <BoMExportMenuItems
+ csvHref={(withOperations) =>
+ path.to.api.billOfMaterialsCsv(makeMethodId, withOperations)
+ }
+ jsonHref={(withOperations) =>
+ path.to.api.billOfMaterials(makeMethodId, withOperations)
+ }
+ />
</DropdownMenuSubContent>
</DropdownMenuSub>
</DropdownMenuContent>
@@ -510,139 +203,6 @@ export function BoMActions({ makeMethodId }: { makeMethodId: string }) {
);
}
-function NodeText({ node }: { node: FlatTreeItem<Method> }) {
- return (
- <div className="flex min-w-0 items-start gap-1">
- <span className="text-sm truncate font-medium">
- {node.data.description || node.data.itemReadableId}
- </span>
- </div>
- );
-}
-
-function NodeData({ node }: { node: FlatTreeItem<Method> }) {
- const integrations = useIntegrations();
- const onShapeState = integrations.has("onshape")
- ? // @ts-expect-error
- // biome-ignore lint/complexity/useLiteralKeys: suppressed due to migration
- node.data.externalId?.["onshapeData"]?.["State"]
- : null;
-
- return (
- <HStack spacing={1}>
- <Badge className="text-xs" variant="outline">
- <MethodIcon
- type={
- // node.data.isRoot ? "Method" :
- node.data.methodType
- }
- isKit={node.data.kit}
- className="mr-2"
- />
- {node.data.quantity}
- </Badge>
- {onShapeState && <OnshapeStatus status={onShapeState} />}
- </HStack>
- );
-}
-
-function NodePreview({ node }: { node: FlatTreeItem<Method> }) {
- const { t } = useLingui();
- const integrations = useIntegrations();
- const onShapeState = integrations.has("onshape")
- ? // @ts-expect-error
- // biome-ignore lint/complexity/useLiteralKeys: suppressed due to migration
- node.data.externalId?.["onshapeData"]?.["State"]
- : null;
-
- return (
- <VStack className="w-full text-sm">
- <VStack spacing={1}>
- <span className="text-xs text-muted-foreground font-medium">
- <Trans>Item ID</Trans>
- </span>
- <HStack className="w-full justify-between">
- <span>{node.data.itemReadableId}</span>
- <HStack spacing={1}>
- <Copy text={node.data.itemReadableId} />
- <Link
- to={getLinkToItemDetails(
- node.data.itemType as "Part",
- node.data.itemId
- )}
- >
- <IconButton
- aria-label={t`View Item Master`}
- size="sm"
- variant="secondary"
- icon={<LuExternalLink />}
- />
- </Link>
- </HStack>
- </HStack>
- </VStack>
- <VStack spacing={1}>
- <span className="text-xs text-muted-foreground font-medium">
- <Trans>Description</Trans>
- </span>
- <HStack className="w-full justify-between">
- <span>{node.data.description}</span>
- <Copy text={node.data.description} />
- </HStack>
- </VStack>
- <VStack spacing={1}>
- <span className="text-xs text-muted-foreground font-medium">
- <Trans>Quantity</Trans>
- </span>
- <HStack className="w-full justify-between">
- <span>
- {node.data.quantity} {node.data.unitOfMeasureCode}
- </span>
- </HStack>
- </VStack>
- <VStack spacing={1}>
- <span className="text-xs text-muted-foreground font-medium">
- <Trans>Method</Trans>
- </span>
- <HStack className="w-full">
- <MethodIcon type={node.data.methodType} />
- <span>{node.data.methodType}</span>
- </HStack>
- </VStack>
- <VStack spacing={1}>
- <span className="text-xs text-muted-foreground font-medium">
- <Trans>Item Type</Trans>
- </span>
- <HStack className="w-full">
- <MethodItemTypeIcon type={node.data.itemType} />
- <span>{node.data.itemType}</span>
- </HStack>
- </VStack>
- {node.data.methodType === "Make to Order" && node.data.version && (
- <VStack spacing={1}>
- <span className="text-xs text-muted-foreground font-medium">
- <Trans>Make Method Version</Trans>
- </span>
- <HStack className="w-full">
- <Badge variant="outline">V{node.data.version}</Badge>
- </HStack>
- </VStack>
- )}
- {onShapeState && (
- <VStack spacing={1}>
- <span className="text-xs text-muted-foreground font-medium">
- <Trans>Onshape Status</Trans>
- </span>
- <HStack className="w-full">
- <OnshapeStatus status={onShapeState} />
- <span>{onShapeState}</span>
- </HStack>
- </VStack>
- )}
- </VStack>
- );
-}
-
function getRootLink(itemType: ItemType, itemId: string, methodId: string) {
switch (itemType) {
case "Part":
@@ -660,8 +220,7 @@ function getMaterialLink(
itemType: ItemType,
itemId: string,
methodId: string,
- makeMethodId: string,
- node: FlatTreeItem<Method>
+ makeMethodId: string
) {
switch (itemType) {
case "Part":
diff --git a/apps/erp/app/modules/production/ui/Jobs/JobBoMExplorer.tsx b/apps/erp/app/modules/production/ui/Jobs/JobBoMExplorer.tsx
index bf2cbb09f6..eea2983669 100644
--- a/apps/erp/app/modules/production/ui/Jobs/JobBoMExplorer.tsx
+++ b/apps/erp/app/modules/production/ui/Jobs/JobBoMExplorer.tsx
@@ -1,60 +1,18 @@
+import { HStack, Spinner, VStack } from "@carbon/react";
+import { createContext, useContext, useEffect, useState } from "react";
+import { useFetchers, useParams, useSearchParams } from "react-router";
+import type { BoMExplorerNodeData } from "~/components/BoMExplorer";
import {
- Badge,
- Copy,
- cn,
- DropdownMenu,
- DropdownMenuContent,
- DropdownMenuIcon,
- DropdownMenuItem,
- DropdownMenuSeparator,
- DropdownMenuTrigger,
- HoverCard,
- HoverCardContent,
- HoverCardTrigger,
- HStack,
- IconButton,
- Input,
- InputGroup,
- InputLeftElement,
- Spinner,
- VStack
-} from "@carbon/react";
-import { Trans, useLingui } from "@lingui/react/macro";
-import {
- createContext,
- type Dispatch,
- type SetStateAction,
- useContext,
- useEffect,
- useMemo,
- useRef,
- useState
-} from "react";
-import {
- LuBraces,
- LuChevronDown,
- LuChevronRight,
- LuChevronsUpDown,
- LuEllipsisVertical,
- LuExternalLink,
- LuSearch,
- LuTable
-} from "react-icons/lu";
-import {
- Link,
- useFetchers,
- useNavigate,
- useParams,
- useSearchParams
-} from "react-router";
-import { MethodIcon, MethodItemTypeIcon } from "~/components";
-import { OnshapeStatus } from "~/components/Icons";
+ BoMExplorerActions,
+ BoMExplorerProvider,
+ BoMExplorerRow,
+ BoMExplorerSearch,
+ BoMExplorerTree,
+ BoMExportMenuItems,
+ useBoMExplorer
+} from "~/components/BoMExplorer";
import type { FlatTree, FlatTreeItem } from "~/components/TreeView";
-import { LevelLine, TreeView, useTree } from "~/components/TreeView";
import { useOptimisticLocation } from "~/hooks";
-import { useIntegrations } from "~/hooks/useIntegrations";
-import { getLinkToItemDetails } from "~/modules/items/ui/Item/ItemForm";
-import { generateBomIds } from "~/utils/bom";
import { path } from "~/utils/path";
import type { JobMethod } from "../../production.service";
import type { ItemOrderStatus } from "../../types";
@@ -71,16 +29,6 @@ type JobBoMExplorerProps = {
};
const JobBoMExplorer = ({ method, orderStatus }: JobBoMExplorerProps) => {
- const parentRef = useRef<HTMLDivElement>(null);
- const navigate = useNavigate();
- const { t } = useLingui();
- const location = useOptimisticLocation();
- const [filterText, setFilterText] = useState("");
- // Single shared "which node's preview is open" so only one hover card shows at
- // a time (opening one row closes the others).
- const [openNodeId, setOpenNodeId] = useState<string | null>(null);
- const { jobId, methodId } = useParams();
-
const [orderStatusData, setOrderStatusData] =
useState<JobOrderStatusData | null>(null);
@@ -103,58 +51,29 @@ const JobBoMExplorer = ({ method, orderStatus }: JobBoMExplorerProps) => {
};
}, [orderStatus]);
- const fetchers = useFetchers();
- const getMethodFetcher = fetchers.find(
- (f) => f.formAction === path.to.jobMethodGet
+ return (
+ <OrderStatusContext.Provider value={orderStatusData ?? {}}>
+ <BoMExplorerProvider tree={method} getNodePath={getNodePath}>
+ <JobBoMExplorerContent method={method} />
+ </BoMExplorerProvider>
+ </OrderStatusContext.Provider>
);
+};
- const isLoading = getMethodFetcher?.state === "loading";
-
- // Generate hierarchical BOM IDs (1, 1.1, 1.1.1, etc.)
- const bomIds = useMemo(() => generateBomIds(method), [method]);
-
- const bomIdMap = useMemo(
- () => new Map(method.map((node, index) => [node.id, bomIds[index]])),
- [method, bomIds]
- );
+export default JobBoMExplorer;
- const {
- nodes,
- getTreeProps,
- getNodeProps,
- toggleExpandNode,
- expandAllBelowDepth,
- selectNode,
- collapseAllBelowDepth,
- deselectAllNodes,
- virtualizer
- } = useTree({
- tree: method,
- // biome-ignore lint/suspicious/noEmptyBlockStatements: suppressed due to migration
- onSelectedIdChanged: () => {},
- estimatedRowHeight: () => 32,
- parentRef,
- filter: {
- value: { text: filterText },
- fn: (value, node) => {
- if (value.text === "") return true;
- if (
- node.data.description.toLowerCase().includes(value.text.toLowerCase())
- ) {
- return true;
- }
- return false;
- }
- },
- isEager: true
- });
+function JobBoMExplorerContent({ method }: { method: FlatTree<JobMethod> }) {
+ const location = useOptimisticLocation();
+ const { jobId, methodId } = useParams();
+ const { selectNode, deselectAllNodes } = useBoMExplorer();
- const allExpanded = useMemo(
- () => method.every((m) => !m.hasChildren || nodes[m.id]?.expanded),
- [method, nodes]
+ const fetchers = useFetchers();
+ const getMethodFetcher = fetchers.find(
+ (f) => f.formAction === path.to.jobMethodGet
);
+ const isLoading = getMethodFetcher?.state === "loading";
- const [searchParams, setSearchParams] = useSearchParams();
+ const [searchParams] = useSearchParams();
const selectedMaterialId = searchParams.get("materialId");
const isDetailsRoute =
jobId && location.pathname === path.to.jobDetails(jobId);
@@ -191,430 +110,58 @@ const JobBoMExplorer = ({ method, orderStatus }: JobBoMExplorerProps) => {
}, [selectedMaterialId, methodId, location.pathname, jobId]);
return (
- <OrderStatusContext.Provider value={orderStatusData ?? {}}>
- <VStack className="flex-1 h-full w-full">
- {isLoading ? (
- <div className="flex items-center justify-center py-8 w-full">
- <Spinner className="w-4 h-4" />
- </div>
- ) : (
- <>
- <HStack className="w-full flex-shrink-0">
- <InputGroup size="sm" className="flex flex-grow">
- <InputLeftElement>
- <LuSearch className="h-4 w-4" />
- </InputLeftElement>
- <Input
- placeholder={t`Search...`}
- value={filterText}
- onChange={(e) => setFilterText(e.target.value)}
+ <VStack className="flex-1 h-full w-full">
+ {isLoading ? (
+ <div className="flex items-center justify-center py-8 w-full">
+ <Spinner className="w-4 h-4" />
+ </div>
+ ) : (
+ <>
+ <HStack className="w-full flex-shrink-0">
+ <BoMExplorerSearch />
+ {jobId && (
+ <BoMExplorerActions triggerVariant="ghost">
+ <BoMExportMenuItems
+ csvHref={(withOperations) =>
+ path.to.api.jobBillOfMaterialsCsv(jobId, withOperations)
+ }
+ jsonHref={(withOperations) =>
+ path.to.api.jobBillOfMaterials(jobId, withOperations)
+ }
/>
- </InputGroup>
- {jobId && (
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <IconButton
- aria-label={t`Actions`}
- variant="ghost"
- size="sm"
- icon={<LuEllipsisVertical />}
- />
- </DropdownMenuTrigger>
- <DropdownMenuContent align="end">
- <DropdownMenuItem
- onClick={() => {
- if (allExpanded) {
- collapseAllBelowDepth(1);
- } else {
- expandAllBelowDepth(0);
- }
- }}
- >
- <DropdownMenuIcon icon={<LuChevronsUpDown />} />
- {allExpanded ? (
- <Trans>Collapse all</Trans>
- ) : (
- <Trans>Expand all</Trans>
- )}
- </DropdownMenuItem>
- <DropdownMenuSeparator />
- <DropdownMenuItem asChild>
- <a
- href={path.to.api.jobBillOfMaterialsCsv(jobId, false)}
- target="_blank"
- rel="noreferrer"
- >
- <DropdownMenuIcon icon={<LuTable />} />
- <div className="flex flex-grow items-center gap-4 justify-between">
- <span>BoM</span>
- <Badge variant="green" className="text-xs">
- CSV
- </Badge>
- </div>
- </a>
- </DropdownMenuItem>
- <DropdownMenuItem asChild>
- <a
- href={path.to.api.jobBillOfMaterialsCsv(jobId, true)}
- target="_blank"
- rel="noreferrer"
- >
- <DropdownMenuIcon icon={<LuTable />} />
- <div className="flex flex-grow items-center gap-4 justify-between">
- <span>BoM + BoP</span>
- <Badge variant="green" className="text-xs">
- CSV
- </Badge>
- </div>
- </a>
- </DropdownMenuItem>
- <DropdownMenuItem asChild>
- <a
- href={path.to.api.jobBillOfMaterials(jobId, false)}
- target="_blank"
- rel="noreferrer"
- >
- <DropdownMenuIcon icon={<LuBraces />} />
- <div className="flex flex-grow items-center gap-4 justify-between">
- <span>BoM</span>
- <Badge variant="outline" className="text-xs">
- JSON
- </Badge>
- </div>
- </a>
- </DropdownMenuItem>
- <DropdownMenuItem asChild>
- <a
- href={path.to.api.jobBillOfMaterials(jobId, true)}
- target="_blank"
- rel="noreferrer"
- >
- <DropdownMenuIcon icon={<LuBraces />} />
- <div className="flex flex-grow items-center gap-4 justify-between">
- <span>BoM + BoP</span>
- <Badge variant="outline" className="text-xs">
- JSON
- </Badge>
- </div>
- </a>
- </DropdownMenuItem>
- </DropdownMenuContent>
- </DropdownMenu>
- )}
- </HStack>
- <div className="flex flex-1 min-h-0 w-full">
- <TreeView
- parentRef={parentRef}
- virtualizer={virtualizer}
- autoFocus
- tree={method}
- nodes={nodes}
- getNodeProps={getNodeProps}
- getTreeProps={getTreeProps}
- renderNode={({ node, state }) => (
- <JobBoMTreeNode
- node={node}
- state={state}
- bomId={bomIdMap.get(node.id)}
- openNodeId={openNodeId}
- setOpenNodeId={setOpenNodeId}
- selectNode={selectNode}
- toggleExpandNode={toggleExpandNode}
- collapseAllBelowDepth={collapseAllBelowDepth}
- expandAllBelowDepth={expandAllBelowDepth}
- navigate={navigate}
- setSearchParams={setSearchParams}
- location={location}
- />
- )}
- />
- </div>
- </>
- )}
- </VStack>
- </OrderStatusContext.Provider>
+ </BoMExplorerActions>
+ )}
+ </HStack>
+ <BoMExplorerTree>
+ {({ node, state }) => (
+ <BoMExplorerRow node={node} state={state}>
+ <JobNodeOrderStatus node={node} />
+ </BoMExplorerRow>
+ )}
+ </BoMExplorerTree>
+ </>
+ )}
+ </VStack>
);
-};
-
-export default JobBoMExplorer;
+}
-function JobBoMTreeNode({
- node,
- state,
- bomId,
- openNodeId,
- setOpenNodeId,
- selectNode,
- toggleExpandNode,
- collapseAllBelowDepth,
- expandAllBelowDepth,
- navigate,
- setSearchParams,
- location
+function JobNodeOrderStatus({
+ node
}: {
- node: FlatTreeItem<JobMethod>;
- state: { selected: boolean; expanded: boolean };
- bomId: string | undefined;
- openNodeId: string | null;
- setOpenNodeId: Dispatch<SetStateAction<string | null>>;
- selectNode: (id: string, scrollIntoView?: boolean) => void;
- toggleExpandNode: (id: string) => void;
- collapseAllBelowDepth: (depth: number) => void;
- expandAllBelowDepth: (depth: number) => void;
- navigate: ReturnType<typeof useNavigate>;
- setSearchParams: ReturnType<typeof useSearchParams>[1];
- location: { pathname: string };
+ node: FlatTreeItem<BoMExplorerNodeData>;
}) {
- // Suppress the preview while the pointer is over the status badge, so its
- // own tooltip is readable without the large preview card overlapping it.
- const [isBadgeHovered, setIsBadgeHovered] = useState(false);
-
- return (
- <HoverCard
- open={openNodeId === node.id && !isBadgeHovered}
- onOpenChange={(nextOpen) => {
- // Opening this node becomes the single open node (closing any other);
- // closing only clears if this node is still the open one.
- setOpenNodeId((current) =>
- nextOpen ? node.id : current === node.id ? null : current
- );
- }}
- openDelay={500}
- closeDelay={150}
- >
- <HoverCardTrigger asChild>
- <div
- key={node.id}
- className={cn(
- "flex h-8 cursor-pointer items-center overflow-hidden rounded-sm pr-2 gap-1",
- state.selected
- ? "bg-muted hover:bg-accent"
- : "bg-transparent hover:bg-accent"
- )}
- onClick={() => {
- selectNode(node.id, false);
- const nodePath = getNodePath(node);
-
- if (location.pathname !== nodePath) {
- navigate(`${nodePath}?materialId=${node.data.methodMaterialId}`, {
- replace: true
- });
- } else {
- setSearchParams({
- materialId: node.data.methodMaterialId
- });
- }
- }}
- >
- <div className="flex h-8 items-center">
- {Array.from({ length: node.level }).map((_, index) => (
- <LevelLine
- key={index}
- isSelected={getNodePath(node) === location.pathname}
- />
- ))}
- <div
- className={cn(
- "flex h-8 w-4 items-center",
- node.hasChildren && "hover:bg-accent"
- )}
- onClick={(e) => {
- e.stopPropagation();
- if (e.altKey) {
- if (state.expanded) {
- collapseAllBelowDepth(node.level);
- } else {
- expandAllBelowDepth(node.level);
- }
- } else {
- toggleExpandNode(node.id);
- }
- }}
- >
- {node.hasChildren ? (
- state.expanded ? (
- <LuChevronDown className="h-4 w-4 text-gray-400 flex-shrink-0 ml-1" />
- ) : (
- <LuChevronRight className="h-4 w-4 text-gray-400 flex-shrink-0 ml-1" />
- )
- ) : (
- <div className="h-8 w-4" />
- )}
- </div>
- </div>
-
- <div className="flex w-full min-w-0 items-center justify-between gap-2">
- <div className="flex flex-1 min-w-0 items-center gap-2 overflow-hidden">
- {bomId && (
- <Badge variant="outline" className="flex-shrink-0">
- {bomId}
- </Badge>
- )}
- <NodeText node={node} />
- </div>
- <div
- className="flex flex-shrink-0 items-center gap-1"
- onPointerEnter={() => setIsBadgeHovered(true)}
- onPointerLeave={() => setIsBadgeHovered(false)}
- >
- {node.data.isRoot ? (
- <Badge variant="outline">V{node.data.version}</Badge>
- ) : (
- <NodeData node={node} />
- )}
- </div>
- </div>
- </div>
- </HoverCardTrigger>
- <HoverCardContent side="right">
- <NodePreview node={node} />
- </HoverCardContent>
- </HoverCard>
- );
-}
-
-function NodeText({ node }: { node: FlatTreeItem<JobMethod> }) {
- return (
- <div className="flex min-w-0 items-center gap-1">
- <span className="font-medium text-sm truncate">
- {node.data.description || node.data.itemReadableId}
- </span>
- </div>
- );
-}
-
-function NodeData({ node }: { node: FlatTreeItem<JobMethod> }) {
- const integrations = useIntegrations();
- const onShapeState = integrations.has("onshape")
- ? // @ts-expect-error
- // biome-ignore lint/complexity/useLiteralKeys: suppressed due to migration
- node.data.externalId?.["onshapeData"]?.["State"]
- : null;
-
const orderStatusByMaterialId = useContext(OrderStatusContext);
+
// Show the procurement badge for any material that has order status —
// purchased, pulled from inventory, or a buy-and-make part. Make to Order
// materials are manufactured, not procured, so they never show a status icon.
- const orderStatus =
- node.data.methodType !== "Make to Order" && node.data.methodMaterialId
- ? orderStatusByMaterialId[node.data.methodMaterialId]
- : undefined;
-
- return (
- <HStack spacing={1}>
- <Badge className="text-xs" variant="outline">
- <MethodIcon
- type={
- // node.data.isRoot ? "Method" :
- node.data.methodType
- }
- isKit={node.data.kit}
- className="mr-2"
- />
- {node.data.quantity}
- </Badge>
- {onShapeState && <OnshapeStatus status={onShapeState} />}
- {node.data.methodType !== "Make to Order" && (
- <JobOrderStatusBadge status={orderStatus} />
- )}
- </HStack>
- );
-}
+ if (node.data.isRoot || node.data.methodType === "Make to Order") return null;
-function NodePreview({ node }: { node: FlatTreeItem<JobMethod> }) {
- const { t } = useLingui();
- const integrations = useIntegrations();
- const onShapeState = integrations.has("onshape")
- ? // @ts-expect-error
- // biome-ignore lint/complexity/useLiteralKeys: suppressed due to migration
- node.data.externalId?.["onshapeData"]?.["State"]
- : null;
+ const orderStatus = node.data.methodMaterialId
+ ? orderStatusByMaterialId[node.data.methodMaterialId]
+ : undefined;
- return (
- <VStack className="w-full text-sm">
- <VStack spacing={1}>
- <span className="text-xs text-muted-foreground font-medium">
- <Trans>Item ID</Trans>
- </span>
- <HStack className="w-full justify-between">
- <span>{node.data.itemReadableId}</span>
- <HStack spacing={1}>
- <Copy text={node.data.itemReadableId} tooltipClassName="z-[110]" />
- <Link
- to={getLinkToItemDetails(
- node.data.itemType as "Part",
- node.data.itemId
- )}
- target="_blank"
- >
- <IconButton
- aria-label={t`View Item Master`}
- size="sm"
- variant="secondary"
- icon={<LuExternalLink />}
- />
- </Link>
- </HStack>
- </HStack>
- </VStack>
- <VStack spacing={1}>
- <span className="text-xs text-muted-foreground font-medium">
- <Trans>Description</Trans>
- </span>
- <HStack className="w-full justify-between">
- <span>{node.data.description}</span>
- <Copy text={node.data.description} tooltipClassName="z-[110]" />
- </HStack>
- </VStack>
- <VStack spacing={1}>
- <span className="text-xs text-muted-foreground font-medium">
- <Trans>Quantity</Trans>
- </span>
- <HStack className="w-full justify-between">
- <span>{node.data.quantity}</span>
- </HStack>
- </VStack>
- <VStack spacing={1}>
- <span className="text-xs text-muted-foreground font-medium">
- <Trans>Method</Trans>
- </span>
- <HStack className="w-full">
- <MethodIcon type={node.data.methodType} />
- <span>{node.data.methodType}</span>
- </HStack>
- </VStack>
- <VStack spacing={1}>
- <span className="text-xs text-muted-foreground font-medium">
- <Trans>Item Type</Trans>
- </span>
- <HStack className="w-full">
- <MethodItemTypeIcon type={node.data.itemType} />
- <span>{node.data.itemType}</span>
- </HStack>
- </VStack>
- {node.data.methodType === "Make to Order" && (
- <VStack spacing={1}>
- <span className="text-xs text-muted-foreground font-medium">
- <Trans>Make Method Version</Trans>
- </span>
- <HStack className="w-full">
- <Badge variant="outline">V{node.data.version}</Badge>
- </HStack>
- </VStack>
- )}
- {onShapeState && (
- <VStack spacing={1}>
- <span className="text-xs text-muted-foreground font-medium">
- <Trans>Onshape Status</Trans>
- </span>
- <HStack className="w-full">
- <OnshapeStatus status={onShapeState} />
- <span>{onShapeState}</span>
- </HStack>
- </VStack>
- )}
- </VStack>
- );
+ return <JobOrderStatusBadge status={orderStatus} />;
}
function getNodePath(node: FlatTreeItem<JobMethod>) {
diff --git a/apps/erp/app/modules/sales/ui/Quotes/QuoteBoMExplorer.tsx b/apps/erp/app/modules/sales/ui/Quotes/QuoteBoMExplorer.tsx
index b8f1386314..d9d2819284 100644
--- a/apps/erp/app/modules/sales/ui/Quotes/QuoteBoMExplorer.tsx
+++ b/apps/erp/app/modules/sales/ui/Quotes/QuoteBoMExplorer.tsx
@@ -1,42 +1,14 @@
+import { HStack, Spinner, VStack } from "@carbon/react";
+import { useEffect } from "react";
+import { useFetchers, useParams, useSearchParams } from "react-router";
import {
- Badge,
- Copy,
- cn,
- HoverCard,
- HoverCardContent,
- HoverCardTrigger,
- HStack,
- IconButton,
- Input,
- InputGroup,
- InputLeftElement,
- Spinner,
- VStack
-} from "@carbon/react";
-import { useLingui } from "@lingui/react/macro";
-
-import { useEffect, useMemo, useRef, useState } from "react";
-import {
- LuChevronDown,
- LuChevronRight,
- LuExternalLink,
- LuSearch
-} from "react-icons/lu";
-import {
- Link,
- useFetchers,
- useNavigate,
- useParams,
- useSearchParams
-} from "react-router";
-import { MethodIcon, MethodItemTypeIcon } from "~/components";
-import { OnshapeStatus } from "~/components/Icons";
+ BoMExplorerProvider,
+ BoMExplorerSearch,
+ BoMExplorerTree,
+ useBoMExplorer
+} from "~/components/BoMExplorer";
import type { FlatTree, FlatTreeItem } from "~/components/TreeView";
-import { LevelLine, TreeView, useTree } from "~/components/TreeView";
import { useOptimisticLocation } from "~/hooks";
-import { useIntegrations } from "~/hooks/useIntegrations";
-import { getLinkToItemDetails } from "~/modules/items/ui/Item/ItemForm";
-import { generateBomIds } from "~/utils/bom";
import { path } from "~/utils/path";
import type { QuoteMethod } from "../../types";
@@ -51,65 +23,45 @@ const QuoteBoMExplorer = ({
isSearchExpanded = false,
isAllExpanded = false
}: QuoteBoMExplorerProps) => {
- const { t } = useLingui();
- const parentRef = useRef<HTMLDivElement>(null);
- const navigate = useNavigate();
+ return (
+ <BoMExplorerProvider tree={methods} getNodePath={getNodePath}>
+ <QuoteBoMExplorerContent
+ methods={methods}
+ isSearchExpanded={isSearchExpanded}
+ isAllExpanded={isAllExpanded}
+ />
+ </BoMExplorerProvider>
+ );
+};
+
+export default QuoteBoMExplorer;
+
+function QuoteBoMExplorerContent({
+ methods,
+ isSearchExpanded,
+ isAllExpanded
+}: {
+ methods: FlatTree<QuoteMethod>;
+ isSearchExpanded: boolean;
+ isAllExpanded: boolean;
+}) {
const location = useOptimisticLocation();
+ const {
+ selectNode,
+ deselectAllNodes,
+ expandAllBelowDepth,
+ collapseAllBelowDepth
+ } = useBoMExplorer();
const fetchers = useFetchers();
const getMethodFetcher = fetchers.find(
(f) => f.formAction === path.to.quoteMethodGet
);
-
- const [filterText, setFilterText] = useState("");
-
const isLoading =
getMethodFetcher?.state === "loading" &&
getMethodFetcher.formData?.get("quoteLineId") ===
methods?.[0].data.quoteLineId;
- // Generate hierarchical BOM IDs (1, 1.1, 1.1.1, etc.)
- const bomIds = useMemo(() => generateBomIds(methods), [methods]);
- const bomIdMap = useMemo(
- () => new Map(methods.map((node, index) => [node.id, bomIds[index]])),
- [methods, bomIds]
- );
-
- const {
- nodes,
- getTreeProps,
- getNodeProps,
- // toggleNodeSelection,
- toggleExpandNode,
- expandAllBelowDepth,
- // toggleExpandLevel,
- collapseAllBelowDepth,
- deselectAllNodes,
- selectNode,
- virtualizer
- } = useTree({
- tree: methods,
- // selectedId,
- // collapsedIds,
- // biome-ignore lint/suspicious/noEmptyBlockStatements: suppressed due to migration
- onSelectedIdChanged: () => {},
- estimatedRowHeight: () => 32,
- parentRef,
- filter: {
- value: { text: filterText },
- fn: (value, node) => {
- if (value.text === "") return true;
- if (
- node.data.description.toLowerCase().includes(value.text.toLowerCase())
- ) {
- return true;
- }
- return false;
- }
- },
- isEager: true
- });
-
// biome-ignore lint/correctness/useExhaustiveDependencies: only react to isAllExpanded changes
useEffect(() => {
if (isAllExpanded) {
@@ -120,7 +72,7 @@ const QuoteBoMExplorer = ({
}, [isAllExpanded]);
const params = useParams();
- const [searchParams, setSearchParams] = useSearchParams();
+ const [searchParams] = useSearchParams();
const selectedMaterialId = searchParams.get("materialId");
const explorerLineId = methods[0]?.data.quoteLineId;
@@ -173,258 +125,14 @@ const QuoteBoMExplorer = ({
<>
{isSearchExpanded && (
<HStack className="w-full">
- <InputGroup size="sm" className="flex flex-grow">
- <InputLeftElement>
- <LuSearch className="h-4 w-4" />
- </InputLeftElement>
- <Input
- placeholder={t`Search...`}
- value={filterText}
- onChange={(e) => setFilterText(e.target.value)}
- />
- </InputGroup>
+ <BoMExplorerSearch />
</HStack>
)}
- <TreeView
- parentRef={parentRef}
- virtualizer={virtualizer}
- autoFocus
- tree={methods}
- nodes={nodes}
- getNodeProps={getNodeProps}
- getTreeProps={getTreeProps}
- renderNode={({ node, state }) => (
- <HoverCard openDelay={500} closeDelay={0}>
- <HoverCardTrigger asChild>
- <div
- key={node.id}
- className={cn(
- "flex h-8 cursor-pointer items-center overflow-hidden rounded-sm pr-2 gap-1 group/node",
- state.selected
- ? "bg-muted hover:bg-accent"
- : "bg-transparent hover:bg-accent"
- )}
- onClick={(e) => {
- selectNode(node.id);
-
- if (location.pathname !== getNodePath(node)) {
- navigate(
- `${getNodePath(node)}?materialId=${node.data.methodMaterialId}`,
- { replace: true }
- );
- } else {
- setSearchParams({
- materialId: node.data.methodMaterialId
- });
- }
- }}
- >
- <div className="flex h-8 items-center">
- {Array.from({ length: node.level }).map((_, index) => (
- <LevelLine
- key={index}
- isSelected={getNodePath(node) === location.pathname}
- />
- ))}
- <div
- className={cn(
- "flex h-8 w-4 items-center",
- node.hasChildren && "hover:bg-accent"
- )}
- onClick={(e) => {
- e.stopPropagation();
- if (e.altKey) {
- if (state.expanded) {
- collapseAllBelowDepth(node.level);
- } else {
- expandAllBelowDepth(node.level);
- }
- } else {
- toggleExpandNode(node.id);
- }
- }}
- >
- {node.hasChildren ? (
- state.expanded ? (
- <LuChevronDown className="h-4 w-4 text-gray-400 flex-shrink-0 ml-1" />
- ) : (
- <LuChevronRight className="h-4 w-4 text-gray-400 flex-shrink-0 ml-1" />
- )
- ) : (
- <div className="h-8 w-4" />
- )}
- </div>
- </div>
-
- <div className="flex w-full items-center justify-between gap-2">
- <div className="flex items-center gap-2 overflow-x-hidden">
- {bomIdMap.get(node.id) && (
- <Badge variant="outline" className="flex-shrink-0">
- {bomIdMap.get(node.id)}
- </Badge>
- )}
- <NodeText node={node} />
- </div>
- <div className="flex items-center gap-1">
- {node.data.isRoot ? (
- <Badge variant="outline">V{node.data.version}</Badge>
- ) : (
- <NodeData node={node} />
- )}
- </div>
- </div>
- </div>
- </HoverCardTrigger>
- <HoverCardContent side="right" className="pointer-events-none">
- <NodePreview node={node} />
- </HoverCardContent>
- </HoverCard>
- )}
- />
+ <BoMExplorerTree />
</>
)}
</VStack>
);
-};
-
-export default QuoteBoMExplorer;
-
-function NodeText({
- node,
- bomId
-}: {
- node: FlatTreeItem<QuoteMethod>;
- bomId?: string;
-}) {
- return (
- <div className="flex items-center gap-1">
- <span className="font-medium text-sm truncate">
- {node.data.description || node.data.itemReadableId}
- </span>
- </div>
- );
-}
-
-function NodeData({ node }: { node: FlatTreeItem<QuoteMethod> }) {
- const integrations = useIntegrations();
- const onShapeState = integrations.has("onshape")
- ? // @ts-expect-error
- // biome-ignore lint/complexity/useLiteralKeys: suppressed due to migration
- node.data.externalId?.["onshapeData"]?.["State"]
- : null;
-
- return (
- <HStack spacing={1}>
- <Badge className="text-xs" variant="outline">
- <MethodIcon
- type={
- // node.data.isRoot ? "Method" :
- node.data.methodType
- }
- isKit={node.data.kit}
- className="mr-2"
- />
- {node.data.quantity}
- </Badge>
-
- {onShapeState && <OnshapeStatus status={onShapeState} />}
- </HStack>
- );
-}
-
-function NodePreview({ node }: { node: FlatTreeItem<QuoteMethod> }) {
- const { t } = useLingui();
- const integrations = useIntegrations();
- const onShapeState = integrations.has("onshape")
- ? // @ts-expect-error
- // biome-ignore lint/complexity/useLiteralKeys: suppressed due to migration
- node.data.externalId?.["onshapeData"]?.["State"]
- : null;
-
- return (
- <VStack className="w-full text-sm">
- <VStack spacing={1}>
- <span className="text-xs text-muted-foreground font-medium">
- Item ID
- </span>
- <HStack className="w-full justify-between">
- <span>{node.data.itemReadableId}</span>
- <HStack spacing={1}>
- <Copy text={node.data.itemReadableId} />
- <Link
- to={getLinkToItemDetails(
- node.data.itemType as "Part",
- node.data.itemId
- )}
- >
- <IconButton
- aria-label={t`View Item Master`}
- size="sm"
- variant="secondary"
- icon={<LuExternalLink />}
- />
- </Link>
- </HStack>
- </HStack>
- </VStack>
- <VStack spacing={1}>
- <span className="text-xs text-muted-foreground font-medium">
- Description
- </span>
- <HStack className="w-full justify-between">
- <span>{node.data.description}</span>
- <Copy text={node.data.description} />
- </HStack>
- </VStack>
- <VStack spacing={1}>
- <span className="text-xs text-muted-foreground font-medium">
- Quantity
- </span>
- <HStack className="w-full justify-between">
- <span>{node.data.quantity}</span>
- </HStack>
- </VStack>
- <VStack spacing={1}>
- <span className="text-xs text-muted-foreground font-medium">
- Method
- </span>
- <HStack className="w-full">
- <MethodIcon type={node.data.methodType} />
- <span>{node.data.methodType}</span>
- </HStack>
- </VStack>
- <VStack spacing={1}>
- <span className="text-xs text-muted-foreground font-medium">
- Item Type
- </span>
- <HStack className="w-full">
- <MethodItemTypeIcon type={node.data.itemType} />
- <span>{node.data.itemType}</span>
- </HStack>
- </VStack>
- {node.data.methodType === "Make to Order" && (
- <VStack spacing={1}>
- <span className="text-xs text-muted-foreground font-medium">
- Make Method Version
- </span>
- <HStack className="w-full">
- <Badge variant="outline">V{node.data.version}</Badge>
- </HStack>
- </VStack>
- )}
- {onShapeState && (
- <VStack spacing={1}>
- <span className="text-xs text-muted-foreground font-medium">
- Onshape Status
- </span>
- <HStack className="w-full">
- <OnshapeStatus status={onShapeState} />
- <span>{onShapeState}</span>
- </HStack>
- </VStack>
- )}
- </VStack>
- );
}
function getNodePath(node: FlatTreeItem<QuoteMethod>) {
diff --git a/apps/erp/app/utils/bom.ts b/apps/erp/app/utils/bom.ts
index 0facab1e63..47899c4f93 100644
--- a/apps/erp/app/utils/bom.ts
+++ b/apps/erp/app/utils/bom.ts
@@ -241,12 +241,7 @@ export const calculateTotalQuantity = (
return quantity;
};
-export const generateBomIds = (
- nodes:
- | FlatTreeItem<QuoteMethod>[]
- | FlatTreeItem<Method>[]
- | FlatTreeItem<JobMethod>[]
-): string[] => {
+export const generateBomIds = (nodes: FlatTreeItem<unknown>[]): string[] => {
const ids = new Array(nodes.length);
const levelCounters = new Map<number, number>();