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(search): add non-conformances (Issues) to global search UI (#1350)
Sankalp Thakur890437c10ab4
diff --git a/apps/erp/app/components/Layout/Topbar/Search.tsx b/apps/erp/app/components/Layout/Topbar/Search.tsxindex 93235a536b..65e4f8329f 100644--- a/apps/erp/app/components/Layout/Topbar/Search.tsx+++ b/apps/erp/app/components/Layout/Topbar/Search.tsx@@ -6,6 +6,7 @@ import {CommandItem,CommandList,CommandSeparator,+ cn,Modal,ModalContent,useDebounce,@@ -14,15 +15,13 @@ import {import { Trans, useLingui } from "@lingui/react/macro";import idb from "localforage";import { nanoid } from "nanoid";-import { useEffect, useState } from "react";+import { useEffect, useRef, useState } from "react";import {LuChevronRight,LuCirclePlay,LuClock,- LuDraftingCompass,LuFileCheck,LuPackageSearch,- LuShieldX,LuShoppingCart,LuSquareUser,LuUser,@@ -37,6 +36,10 @@ import {import { RxMagnifyingGlass } from "react-icons/rx";import { useFetcher, useNavigate } from "react-router";import { MethodItemTypeIcon } from "~/components/Icons";+import { getEntityTypeConfig } from "~/components/Layout/Topbar/Search/config";+import { SearchEmptyState } from "~/components/Layout/Topbar/Search/SearchEmptyState";+import { SearchFilterChips } from "~/components/Layout/Topbar/Search/SearchFilterChips";+import type { EntityTypeFilter } from "~/components/Layout/Topbar/Search/types";import { useModules, useUser } from "~/hooks";import useAccountSubmodules from "~/modules/account/ui/useAccountSubmodules";import useAccountingSubmodules from "~/modules/accounting/ui/useAccountingSubmodules";@@ -54,9 +57,7 @@ import useSettingsSubmodules from "~/modules/settings/ui/useSettingsSubmodules";import useUsersSubmodules from "~/modules/users/ui/useUsersSubmodules";import type { SearchResponse } from "~/routes/api+/search";import { useUIStore } from "~/stores/ui";-import type { Authenticated, Route } from "~/types";-import { SearchEmptyState } from "./Search/SearchEmptyState";type RecentSearch = Route & {entityType?: string;@@ -78,10 +79,24 @@ export const SearchModal = () => {const storageKey = `recentSearches_${company.id}`;const [input, setInput] = useState("");+ const [typeFilter, setTypeFilter] = useState<EntityTypeFilter>("all");+ const typeFilterRef = useRef<EntityTypeFilter>(typeFilter);+ typeFilterRef.current = typeFilter;const [isDebouncing, setIsDebouncing] = useState(false);++ const buildSearchUrl = (q: string, type: EntityTypeFilter) => {+ const params = new URLSearchParams({ q });+ if (type !== "all") {+ params.set("type", type);+ }+ return `/api/search?${params.toString()}`;+ };++ // Always read the latest type filter so a pending debounce after chip change+ // does not re-fetch with a stale type.const debounceSearch = useDebounce((q: string) => {if (q && q.length >= 2) {- fetcher.load(`/api/search?q=${encodeURIComponent(q)}`);+ fetcher.load(buildSearchUrl(q, typeFilterRef.current));}setIsDebouncing(false);}, 500);@@ -89,6 +104,8 @@ export const SearchModal = () => {useEffect(() => {if (isSearchModalOpen) {setInput("");+ setTypeFilter("all");+ typeFilterRef.current = "all";}}, [isSearchModalOpen]);@@ -119,21 +136,32 @@ export const SearchModal = () => {const recentPaths = new Set(recentResults.map((r) => r.to));const searchResults = input.length >= 2 ? (fetcher.data?.results ?? []) : [];const loading = fetcher.state === "loading";+ const isEntityTypeFiltered = typeFilter !== "all";++ // When a type chip is active, only show recents that match that entity type+ const visibleRecentResults = isEntityTypeFiltered+ ? recentResults.filter((r) => r.entityType === typeFilter)+ : recentResults;- // Filter static results based on input for empty state detection+ // Filter static results based on input for empty state detection.+ // Module nav is hidden when filtering by entity type (entity results only).const normalizedInput = input.toLowerCase().trim();const hasMatchingStaticResults =- normalizedInput.length === 0 ||- Object.entries(staticResults).some(([module, submodules]) =>- submodules.some(- (s) =>- !recentPaths.has(s.to) &&- `${module} ${s.name}`.toLowerCase().includes(normalizedInput)- )- );+ !isEntityTypeFiltered &&+ (normalizedInput.length === 0 ||+ Object.entries(staticResults).some(([module, submodules]) =>+ submodules.some(+ (s) =>+ !recentPaths.has(s.to) &&+ `${module} ${s.name}`.toLowerCase().includes(normalizedInput)+ )+ ));const hasMatchingRecentResults =- normalizedInput.length === 0 ||- recentResults.some((r) => r.name.toLowerCase().includes(normalizedInput));+ visibleRecentResults.length > 0 &&+ (normalizedInput.length === 0 ||+ visibleRecentResults.some((r) =>+ r.name.toLowerCase().includes(normalizedInput)+ ));const hasAnyResults =searchResults.length > 0 ||@@ -148,6 +176,16 @@ export const SearchModal = () => {debounceSearch(value);};+ const onTypeFilterChange = (filter: EntityTypeFilter) => {+ setTypeFilter(filter);+ typeFilterRef.current = filter;+ // Re-fetch immediately so chip selection feels responsive+ if (input && input.length >= 2) {+ setIsDebouncing(false);+ fetcher.load(buildSearchUrl(input, filter));+ }+ };+const onSelect = async (route: Route,entityType?: string,@@ -183,6 +221,8 @@ export const SearchModal = () => {open={isSearchModalOpen}onOpenChange={(open) => {setInput("");+ setTypeFilter("all");+ typeFilterRef.current = "all";if (!open) closeSearchModal();}}>@@ -200,6 +240,11 @@ export const SearchModal = () => {className="h-14 text-base"/>+ <SearchFilterChips+ selectedFilter={typeFilter}+ onFilterChange={onTypeFilterChange}+ />+{/* Results */}<CommandList className="flex-1 max-h-none overflow-y-auto px-2 py-2">{loading || isDebouncing ? (@@ -209,7 +254,7 @@ export const SearchModal = () => {) : (<>{/* Recent Searches */}- {recentResults.length > 0 && (+ {visibleRecentResults.length > 0 && (<><CommandGroupheading={@@ -220,7 +265,7 @@ export const SearchModal = () => {}key="recent">- {recentResults.map((result, index) => {+ {visibleRecentResults.map((result, index) => {const ModuleIcon = result.module? getModuleIcon(result.module): undefined;@@ -238,7 +283,7 @@ export const SearchModal = () => {value={`:${result.to}`}className="flex items-center gap-3 px-3 py-2.5 rounded-lg group">- <div className="flex-shrink-0 w-8 h-8 rounded-lg bg-muted flex items-center justify-center">+ <ResultIconContainer entityType={result.entityType}>{result.entityType ? (<ResultIcon entityType={result.entityType} />) : ModuleIcon ? (@@ -246,7 +291,7 @@ export const SearchModal = () => {) : (<RxMagnifyingGlass className="w-4 h-4 text-muted-foreground" />)}- </div>+ </ResultIconContainer><VStack spacing={0} className="flex-1 min-w-0"><span className="font-medium truncate">{result.name}@@ -299,9 +344,9 @@ export const SearchModal = () => {}className="flex items-center gap-3 px-3 py-3 rounded-lg group">- <div className="flex-shrink-0 w-8 h-8 rounded-lg bg-muted flex items-center justify-center">+ <ResultIconContainer entityType={result.entityType}><ResultIcon entityType={result.entityType} />- </div>+ </ResultIconContainer><VStack spacing={0} className="flex-1 min-w-0"><span className="font-medium text-foreground truncate">{result.title}@@ -318,52 +363,54 @@ export const SearchModal = () => {</CommandGroup>)}- {/* Module Navigation */}- {Object.entries(staticResults).map(([module, submodules]) => {- const filteredSubmodules = submodules.filter(- (s) => !recentPaths.has(s.to)- );- if (filteredSubmodules.length === 0) return null;- return (- <div key={`static-${module}`}>- <CommandGroup- heading={- <span className="text-xs font-semibold uppercase tracking-wider text-muted-foreground">- {module}- </span>- }- >- {filteredSubmodules.map((submodule, index) => {- const hasIconElement =- "iconElement" in submodule && submodule.iconElement;- return (- <CommandItem- key={`${submodule.to}-${submodule.name}-${index}`}- onSelect={() =>- onSelect(submodule, undefined, module)- }- value={`${module} ${submodule.name}`}- className="flex items-center gap-3 px-3 py-2 rounded-lg group"- >- <div className="flex-shrink-0 w-7 h-7 rounded-md bg-muted/50 flex items-center justify-center text-muted-foreground [&>svg]:w-4 [&>svg]:h-4">- {hasIconElement ? (- submodule.iconElement- ) : submodule.icon ? (- <submodule.icon className="w-4 h-4" />- ) : null}- </div>- <span className="flex-1 text-sm">- {submodule.name}- </span>- <LuChevronRight className="w-4 h-4 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity" />- </CommandItem>- );- })}- </CommandGroup>- <CommandSeparator className="my-2" />- </div>- );- })}+ {/* Module Navigation (hidden when filtering by entity type) */}+ {!isEntityTypeFiltered &&+ Object.entries(staticResults).map(([module, submodules]) => {+ const filteredSubmodules = submodules.filter(+ (s) => !recentPaths.has(s.to)+ );+ if (filteredSubmodules.length === 0) return null;+ return (+ <div key={`static-${module}`}>+ <CommandGroup+ heading={+ <span className="text-xs font-semibold uppercase tracking-wider text-muted-foreground">+ {module}+ </span>+ }+ >+ {filteredSubmodules.map((submodule, index) => {+ const hasIconElement =+ "iconElement" in submodule &&+ submodule.iconElement;+ return (+ <CommandItem+ key={`${submodule.to}-${submodule.name}-${index}`}+ onSelect={() =>+ onSelect(submodule, undefined, module)+ }+ value={`${module} ${submodule.name}`}+ className="flex items-center gap-3 px-3 py-2 rounded-lg group"+ >+ <div className="flex-shrink-0 w-7 h-7 rounded-md bg-muted/50 flex items-center justify-center text-muted-foreground [&>svg]:w-4 [&>svg]:h-4">+ {hasIconElement ? (+ submodule.iconElement+ ) : submodule.icon ? (+ <submodule.icon className="w-4 h-4" />+ ) : null}+ </div>+ <span className="flex-1 text-sm">+ {submodule.name}+ </span>+ <LuChevronRight className="w-4 h-4 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity" />+ </CommandItem>+ );+ })}+ </CommandGroup>+ <CommandSeparator className="my-2" />+ </div>+ );+ })}</>)}</CommandList>@@ -397,19 +444,46 @@ export const SearchModal = () => {);};+function ResultIconContainer({+ entityType,+ children+}: {+ entityType?: string;+ children: React.ReactNode;+}) {+ const config = entityType ? getEntityTypeConfig(entityType) : null;+ const hasTint = Boolean(config?.bgColor);++ return (+ <div+ className={cn(+ "flex-shrink-0 w-8 h-8 rounded-lg flex items-center justify-center",+ hasTint ? config?.bgColor : "bg-muted"+ )}+ >+ {children}+ </div>+ );+}+function ResultIcon({ entityType }: { entityType: string }) {- const iconClass = "w-4 h-4 text-muted-foreground";+ const config = getEntityTypeConfig(entityType);+ const iconClass = cn("w-4 h-4", config.textColor || "text-muted-foreground");++ // Prefer shared entity config icons (issue → LuOctagonAlert, gauge → LuGauge)+ if (config.icon) {+ const Icon = config.icon;+ return <Icon className={iconClass} />;+ }++ // Fallbacks for types without a config iconswitch (entityType) {case "customer":return <LuSquareUser className={iconClass} />;case "employee":return <LuUser className={iconClass} />;- case "gauge":- return <LuDraftingCompass className={iconClass} />;case "job":return <LuCirclePlay className={iconClass} />;- case "issue":- return <LuShieldX className={iconClass} />;case "item":return <MethodItemTypeIcon type="Part" className={iconClass} />;case "purchaseOrder":diff --git a/apps/erp/app/components/Layout/Topbar/Search/SearchFilterChips.tsx b/apps/erp/app/components/Layout/Topbar/Search/SearchFilterChips.tsxnew file mode 100644index 0000000000..5f3118c47a--- /dev/null+++ b/apps/erp/app/components/Layout/Topbar/Search/SearchFilterChips.tsx@@ -0,0 +1,69 @@+import { cn } from "@carbon/react";+import { Trans } from "@lingui/react/macro";+import {+ entityTypeConfig,+ getEntityTypeConfig,+ getEntityTypeLabel+} from "~/components/Layout/Topbar/Search/config";+import type {+ EntityTypeFilter,+ SearchFilterChipsProps+} from "~/components/Layout/Topbar/Search/types";++/** Entity types exposed as filter chips (keys are constrained to EntityType). */+const FILTERABLE_ENTITY_TYPES = Object.keys(entityTypeConfig) as Array<+ keyof typeof entityTypeConfig+>;++const FILTER_OPTIONS: { value: EntityTypeFilter; label: string }[] = [+ { value: "all", label: "All" },+ ...FILTERABLE_ENTITY_TYPES.map((value) => ({+ value,+ label: getEntityTypeLabel(value)+ }))+];++export function SearchFilterChips({+ selectedFilter,+ onFilterChange+}: SearchFilterChipsProps) {+ return (+ <div+ className="flex items-center gap-1.5 overflow-x-auto px-3 py-2 border-b border-border scrollbar-none"+ role="toolbar"+ aria-label="Filter search by type"+ >+ {FILTER_OPTIONS.map((option) => {+ const isSelected = selectedFilter === option.value;+ const config =+ option.value === "all" ? null : getEntityTypeConfig(option.value);+ const Icon = config?.icon;++ return (+ <button+ key={option.value}+ type="button"+ onClick={() => onFilterChange(option.value)}+ aria-pressed={isSelected}+ className={cn(+ "inline-flex items-center gap-1.5 flex-shrink-0 rounded-full px-2.5 py-1 text-xs font-medium transition-colors",+ "border focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",+ isSelected+ ? option.value === "all"+ ? "bg-foreground text-background border-foreground"+ : cn(+ config?.bgColor,+ config?.textColor,+ "border-transparent ring-1 ring-inset ring-black/5 dark:ring-white/10"+ )+ : "bg-muted/50 text-muted-foreground border-transparent hover:bg-muted hover:text-foreground"+ )}+ >+ {Icon ? <Icon className="w-3 h-3" /> : null}+ {option.value === "all" ? <Trans>All</Trans> : option.label}+ </button>+ );+ })}+ </div>+ );+}diff --git a/apps/erp/app/components/Layout/Topbar/Search/SearchResultItem.tsx b/apps/erp/app/components/Layout/Topbar/Search/SearchResultItem.tsxindex 617892c1d0..b7316daf11 100644--- a/apps/erp/app/components/Layout/Topbar/Search/SearchResultItem.tsx+++ b/apps/erp/app/components/Layout/Topbar/Search/SearchResultItem.tsx@@ -24,8 +24,20 @@ export function SearchResultItem({)}>{/* Icon */}- <div className="flex-shrink-0 w-8 h-8 rounded-lg bg-muted flex items-center justify-center">- {Icon && <Icon className="w-4 h-4 text-muted-foreground" />}+ <div+ className={cn(+ "flex-shrink-0 w-8 h-8 rounded-lg flex items-center justify-center",+ config.bgColor || "bg-muted"+ )}+ >+ {Icon && (+ <Icon+ className={cn(+ "w-4 h-4",+ config.textColor || "text-muted-foreground"+ )}+ />+ )}</div>{/* Content */}diff --git a/apps/erp/app/components/Layout/Topbar/Search/config.ts b/apps/erp/app/components/Layout/Topbar/Search/config.tsindex a92658b691..4d890ee534 100644--- a/apps/erp/app/components/Layout/Topbar/Search/config.ts+++ b/apps/erp/app/components/Layout/Topbar/Search/config.ts@@ -16,10 +16,11 @@ import {RiProgress4Line,RiProgress8Line} from "react-icons/ri";+import type { EntityType } from "~/components/Layout/Topbar/Search/types";-// Entity type styling configuration+// Entity type styling configuration (keys must match EntityType)export const entityTypeConfig: Record<- string,+ EntityType,{ bgColor: string; textColor: string; icon: IconType }> = {customer: {@@ -33,13 +34,13 @@ export const entityTypeConfig: Record<icon: PiShareNetworkFill},gauge: {- bgColor: "",- textColor: "",+ bgColor: "bg-amber-100 dark:bg-amber-900/30",+ textColor: "text-amber-600 dark:text-amber-400",icon: LuGauge},issue: {- bgColor: "",- textColor: "",+ bgColor: "bg-rose-100 dark:bg-rose-900/30",+ textColor: "text-rose-600 dark:text-rose-400",icon: LuOctagonAlert},item: {@@ -96,7 +97,7 @@ export const entityTypeConfig: Record<export function getEntityTypeConfig(entityType: string) {return (- entityTypeConfig[entityType] ?? {+ entityTypeConfig[entityType as EntityType] ?? {bgColor: "bg-muted",textColor: "text-muted-foreground",icon: nulldiff --git a/apps/erp/app/components/Layout/Topbar/Search/index.ts b/apps/erp/app/components/Layout/Topbar/Search/index.tsindex 84286a36d1..b887e3f9a3 100644--- a/apps/erp/app/components/Layout/Topbar/Search/index.ts+++ b/apps/erp/app/components/Layout/Topbar/Search/index.ts@@ -1,6 +1,5 @@export * from "./config";export { SearchEmptyState } from "./SearchEmptyState";-// @ts-expect-error TS2307 - TODO: fix typeexport { SearchFilterChips } from "./SearchFilterChips";export { SearchResultItem } from "./SearchResultItem";export * from "./types";diff --git a/apps/erp/app/components/Layout/Topbar/Search/types.ts b/apps/erp/app/components/Layout/Topbar/Search/types.tsindex 1a6d1b0157..f5356f5609 100644--- a/apps/erp/app/components/Layout/Topbar/Search/types.ts+++ b/apps/erp/app/components/Layout/Topbar/Search/types.ts@@ -18,8 +18,12 @@ export type EntityType =| "purchaseOrder"| "salesInvoice"| "purchaseInvoice"- | "equipmentType"- | "workCellType";+ | "quote"+ | "salesRfq"+ | "salesOrder"+ | "supplierQuote"+ | "issue"+ | "gauge";export type EntityTypeFilter = "all" | EntityType;