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: add search to BoM explorers

Brad Barbina64e2202b9ac
diff --git a/apps/erp/app/modules/production/ui/Jobs/JobBoMExplorer.tsx b/apps/erp/app/modules/production/ui/Jobs/JobBoMExplorer.tsx
index f4bfed46e1..c9c4952489 100644
--- a/apps/erp/app/modules/production/ui/Jobs/JobBoMExplorer.tsx
+++ b/apps/erp/app/modules/production/ui/Jobs/JobBoMExplorer.tsx
@@ -1,7 +1,16 @@
-import { Badge, HStack, Spinner, VStack, cn } from "@carbon/react";
+import {
+ Badge,
+ HStack,
+ Input,
+ InputGroup,
+ InputLeftElement,
+ Spinner,
+ VStack,
+ cn,
+} from "@carbon/react";
import { useFetchers, useNavigate } from "@remix-run/react";
-import { useRef } from "react";
-import { LuChevronDown, LuChevronUp } from "react-icons/lu";
+import { useRef, useState } from "react";
+import { LuChevronDown, LuChevronUp, LuSearch } from "react-icons/lu";
import { MethodIcon, MethodItemTypeIcon } from "~/components";
import type { FlatTree, FlatTreeItem } from "~/components/TreeView";
import { LevelLine, TreeView, useTree } from "~/components/TreeView";
@@ -17,6 +26,7 @@ const JobBoMExplorer = ({ method }: JobBoMExplorerProps) => {
const parentRef = useRef<HTMLDivElement>(null);
const navigate = useNavigate();
const location = useOptimisticLocation();
+ const [filterText, setFilterText] = useState("");
const fetchers = useFetchers();
const getMethodFetcher = fetchers.find(
@@ -43,6 +53,20 @@ const JobBoMExplorer = ({ method }: JobBoMExplorerProps) => {
onSelectedIdChanged: () => {},
estimatedRowHeight: () => 32,
parentRef,
+ filter: {
+ value: { text: filterText },
+ fn: (value, node) => {
+ if (value.text === "") return true;
+ if (
+ node.data.itemReadableId
+ .toLowerCase()
+ .includes(value.text.toLowerCase())
+ ) {
+ return true;
+ }
+ return false;
+ },
+ },
isEager: true,
});
@@ -53,90 +77,104 @@ const JobBoMExplorer = ({ method }: JobBoMExplorerProps) => {
<Spinner className="w-4 h-4" />
</div>
) : (
- <TreeView
- parentRef={parentRef}
- virtualizer={virtualizer}
- autoFocus
- tree={method}
- nodes={nodes}
- getNodeProps={getNodeProps}
- getTreeProps={getTreeProps}
- renderNode={({ node, state }) => (
- <div
- key={node.id}
- className={cn(
- "flex h-8 cursor-pointer items-center overflow-hidden rounded-sm pr-2 gap-1",
- getNodePath(node) === location.pathname
- ? "bg-muted hover:bg-muted/90"
- : "bg-transparent hover:bg-muted/90"
- )}
- onClick={(e) => {
- e.stopPropagation();
- navigate(getNodePath(node));
- }}
- >
- <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);
+ <>
+ <HStack className="w-full">
+ <InputGroup size="sm" className="flex flex-grow">
+ <InputLeftElement>
+ <LuSearch className="h-4 w-4" />
+ </InputLeftElement>
+ <Input
+ placeholder="Search..."
+ value={filterText}
+ onChange={(e) => setFilterText(e.target.value)}
+ />
+ </InputGroup>
+ </HStack>
+ <TreeView
+ parentRef={parentRef}
+ virtualizer={virtualizer}
+ autoFocus
+ tree={method}
+ nodes={nodes}
+ getNodeProps={getNodeProps}
+ getTreeProps={getTreeProps}
+ renderNode={({ node, state }) => (
+ <div
+ key={node.id}
+ className={cn(
+ "flex h-8 cursor-pointer items-center overflow-hidden rounded-sm pr-2 gap-1",
+ getNodePath(node) === location.pathname
+ ? "bg-muted hover:bg-muted/90"
+ : "bg-transparent hover:bg-muted/90"
+ )}
+ onClick={(e) => {
+ e.stopPropagation();
+ navigate(getNodePath(node));
+ }}
+ >
+ <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 {
- expandAllBelowDepth(node.level);
+ toggleExpandNode(node.id);
}
- } else {
- toggleExpandNode(node.id);
- }
- scrollToNode(node.id);
- }}
- >
- {node.hasChildren ? (
- state.expanded ? (
- <LuChevronDown className="h-4 w-4 text-gray-400 flex-shrink-0 ml-1" />
+ scrollToNode(node.id);
+ }}
+ >
+ {node.hasChildren ? (
+ state.expanded ? (
+ <LuChevronDown className="h-4 w-4 text-gray-400 flex-shrink-0 ml-1" />
+ ) : (
+ <LuChevronUp className="h-4 w-4 text-gray-400 flex-shrink-0 ml-1" />
+ )
) : (
- <LuChevronUp className="h-4 w-4 text-gray-400 flex-shrink-0 ml-1" />
- )
- ) : (
- <div className="h-8 w-4" />
- )}
+ <div className="h-8 w-4" />
+ )}
+ </div>
</div>
- </div>
- <div className="flex w-full items-center justify-between gap-2">
- <div className="flex items-center gap-2 overflow-x-hidden">
- <MethodIcon
- type={
- // node.data.isRoot ? "Method" :
- node.data.methodType
- }
- className="h-4 min-h-4 w-4 min-w-4 flex-shrink-0"
- />
- <NodeText node={node} />
- </div>
- <div className="flex items-center gap-1">
- {node.data.isRoot ? (
- <Badge variant="outline" className="text-xs">
- Method
- </Badge>
- ) : (
- <NodeData node={node} />
- )}
+ <div className="flex w-full items-center justify-between gap-2">
+ <div className="flex items-center gap-2 overflow-x-hidden">
+ <MethodIcon
+ type={
+ // node.data.isRoot ? "Method" :
+ node.data.methodType
+ }
+ className="h-4 min-h-4 w-4 min-w-4 flex-shrink-0"
+ />
+ <NodeText node={node} />
+ </div>
+ <div className="flex items-center gap-1">
+ {node.data.isRoot ? (
+ <Badge variant="outline" className="text-xs">
+ Method
+ </Badge>
+ ) : (
+ <NodeData node={node} />
+ )}
+ </div>
</div>
</div>
- </div>
- )}
- />
+ )}
+ />
+ </>
)}
</VStack>
);
diff --git a/apps/erp/app/modules/sales/ui/Quotes/QuoteBoMExplorer.tsx b/apps/erp/app/modules/sales/ui/Quotes/QuoteBoMExplorer.tsx
index 6e365241d5..fd1b38335a 100644
--- a/apps/erp/app/modules/sales/ui/Quotes/QuoteBoMExplorer.tsx
+++ b/apps/erp/app/modules/sales/ui/Quotes/QuoteBoMExplorer.tsx
@@ -1,7 +1,16 @@
-import { Badge, HStack, Spinner, VStack, cn } from "@carbon/react";
+import {
+ Badge,
+ HStack,
+ Input,
+ InputGroup,
+ InputLeftElement,
+ Spinner,
+ VStack,
+ cn,
+} from "@carbon/react";
import { useFetchers, useNavigate } from "@remix-run/react";
-import { useRef } from "react";
-import { LuChevronDown, LuChevronUp } from "react-icons/lu";
+import { useRef, useState } from "react";
+import { LuChevronDown, LuChevronUp, LuSearch } from "react-icons/lu";
import { MethodIcon, MethodItemTypeIcon } from "~/components";
import type { FlatTree, FlatTreeItem } from "~/components/TreeView";
import { LevelLine, TreeView, useTree } from "~/components/TreeView";
@@ -23,6 +32,8 @@ const QuoteBoMExplorer = ({ methods }: QuoteBoMExplorerProps) => {
(f) => f.formAction === path.to.quoteMethodGet
);
+ const [filterText, setFilterText] = useState("");
+
const isLoading =
getMethodFetcher?.state === "loading" &&
getMethodFetcher.formData?.get("quoteLineId") ===
@@ -46,6 +57,20 @@ const QuoteBoMExplorer = ({ methods }: QuoteBoMExplorerProps) => {
onSelectedIdChanged: () => {},
estimatedRowHeight: () => 32,
parentRef,
+ filter: {
+ value: { text: filterText },
+ fn: (value, node) => {
+ if (value.text === "") return true;
+ if (
+ node.data.itemReadableId
+ .toLowerCase()
+ .includes(value.text.toLowerCase())
+ ) {
+ return true;
+ }
+ return false;
+ },
+ },
isEager: true,
});
@@ -56,90 +81,104 @@ const QuoteBoMExplorer = ({ methods }: QuoteBoMExplorerProps) => {
<Spinner className="w-4 h-4" />
</div>
) : (
- <TreeView
- parentRef={parentRef}
- virtualizer={virtualizer}
- autoFocus
- tree={methods}
- nodes={nodes}
- getNodeProps={getNodeProps}
- getTreeProps={getTreeProps}
- renderNode={({ node, state }) => (
- <div
- key={node.id}
- className={cn(
- "flex h-8 cursor-pointer items-center overflow-hidden rounded-sm pr-2 gap-1",
- getNodePath(node) === location.pathname
- ? "bg-muted hover:bg-muted/90"
- : "bg-transparent hover:bg-muted/90"
- )}
- onClick={(e) => {
- e.stopPropagation();
- navigate(getNodePath(node));
- }}
- >
- <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);
+ <>
+ <HStack className="w-full">
+ <InputGroup size="sm" className="flex flex-grow">
+ <InputLeftElement>
+ <LuSearch className="h-4 w-4" />
+ </InputLeftElement>
+ <Input
+ placeholder="Search..."
+ value={filterText}
+ onChange={(e) => setFilterText(e.target.value)}
+ />
+ </InputGroup>
+ </HStack>
+ <TreeView
+ parentRef={parentRef}
+ virtualizer={virtualizer}
+ autoFocus
+ tree={methods}
+ nodes={nodes}
+ getNodeProps={getNodeProps}
+ getTreeProps={getTreeProps}
+ renderNode={({ node, state }) => (
+ <div
+ key={node.id}
+ className={cn(
+ "flex h-8 cursor-pointer items-center overflow-hidden rounded-sm pr-2 gap-1",
+ getNodePath(node) === location.pathname
+ ? "bg-muted hover:bg-muted/90"
+ : "bg-transparent hover:bg-muted/90"
+ )}
+ onClick={(e) => {
+ e.stopPropagation();
+ navigate(getNodePath(node));
+ }}
+ >
+ <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 {
- expandAllBelowDepth(node.level);
+ toggleExpandNode(node.id);
}
- } else {
- toggleExpandNode(node.id);
- }
- scrollToNode(node.id);
- }}
- >
- {node.hasChildren ? (
- state.expanded ? (
- <LuChevronDown className="h-4 w-4 text-gray-400 flex-shrink-0 ml-1" />
+ scrollToNode(node.id);
+ }}
+ >
+ {node.hasChildren ? (
+ state.expanded ? (
+ <LuChevronDown className="h-4 w-4 text-gray-400 flex-shrink-0 ml-1" />
+ ) : (
+ <LuChevronUp className="h-4 w-4 text-gray-400 flex-shrink-0 ml-1" />
+ )
) : (
- <LuChevronUp className="h-4 w-4 text-gray-400 flex-shrink-0 ml-1" />
- )
- ) : (
- <div className="h-8 w-4" />
- )}
+ <div className="h-8 w-4" />
+ )}
+ </div>
</div>
- </div>
- <div className="flex w-full items-center justify-between gap-2">
- <div className="flex items-center gap-2 overflow-x-hidden">
- <MethodIcon
- type={
- // node.data.isRoot ? "Method" :
- node.data.methodType
- }
- className="h-4 min-h-4 w-4 min-w-4 flex-shrink-0"
- />
- <NodeText node={node} />
- </div>
- <div className="flex items-center gap-1">
- {node.data.isRoot ? (
- <Badge variant="outline" className="text-xs">
- Method
- </Badge>
- ) : (
- <NodeData node={node} />
- )}
+ <div className="flex w-full items-center justify-between gap-2">
+ <div className="flex items-center gap-2 overflow-x-hidden">
+ <MethodIcon
+ type={
+ // node.data.isRoot ? "Method" :
+ node.data.methodType
+ }
+ className="h-4 min-h-4 w-4 min-w-4 flex-shrink-0"
+ />
+ <NodeText node={node} />
+ </div>
+ <div className="flex items-center gap-1">
+ {node.data.isRoot ? (
+ <Badge variant="outline" className="text-xs">
+ Method
+ </Badge>
+ ) : (
+ <NodeData node={node} />
+ )}
+ </div>
</div>
</div>
- </div>
- )}
- />
+ )}
+ />
+ </>
)}
</VStack>
);