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: update search engine to use cmdk

Brad Barbinf05dbee268e2
diff --git a/apps/carbon/app/components/Form/Color.tsx b/apps/carbon/app/components/Form/Color.tsx
index a3cd424f51..548f8f28a8 100644
--- a/apps/carbon/app/components/Form/Color.tsx
+++ b/apps/carbon/app/components/Form/Color.tsx
@@ -40,7 +40,7 @@ const ColorPicker = ({ name, label }: ColorFieldProps) => {
<HexColorInput
color={value}
onChange={setValue}
- className="py-0 px-2 h-9 rounded-md outline-2 outline-offset-2 outline-transparent border border-border"
+ className="py-0 px-2 h-9 rounded-md outline-2 outline-offset-2 outline-transparent border border-border bg-background text-foreground focus:ring-ring focus:ring-offset-background focus:ring-2 focus:outline-none disabled:pointer-events-none disabled:opacity-50"
/>
</HStack>
{disclosure.isOpen && (
diff --git a/apps/carbon/app/components/Layout/PageTitle.tsx b/apps/carbon/app/components/Layout/PageTitle.tsx
index fe71922547..222fcd293b 100644
--- a/apps/carbon/app/components/Layout/PageTitle.tsx
+++ b/apps/carbon/app/components/Layout/PageTitle.tsx
@@ -8,8 +8,8 @@ type PageTitleProps = {
const PageTitle = ({ title, subtitle }: PageTitleProps) => {
return (
<VStack className="mb-4">
- <Heading size="h1">{title}</Heading>
- {subtitle && <p className="text-muted-foreground">{subtitle}</p>}
+ <Heading size="h2">{title}</Heading>
+ {subtitle && <p className="text-muted-foreground text-sm">{subtitle}</p>}
</VStack>
);
};
diff --git a/apps/carbon/app/components/Layout/SectionTitle.tsx b/apps/carbon/app/components/Layout/SectionTitle.tsx
index 326937cf68..06ce53ebf6 100644
--- a/apps/carbon/app/components/Layout/SectionTitle.tsx
+++ b/apps/carbon/app/components/Layout/SectionTitle.tsx
@@ -8,7 +8,9 @@ type SectionTitleProps = PropsWithChildren<{
const SectionTitle = ({ children, subtitle, ...props }: SectionTitleProps) => {
return (
<VStack className="mb4" {...props}>
- <Heading size="h3">{children}</Heading>
+ <Heading size="h3" className="font-light">
+ {children}
+ </Heading>
{subtitle && <p className="text-muted-foreground">{subtitle}</p>}
</VStack>
);
diff --git a/apps/carbon/app/components/Layout/Sidebar/IconSidebar.tsx b/apps/carbon/app/components/Layout/Sidebar/IconSidebar.tsx
index 8ac6eaafce..9113cb9d2a 100644
--- a/apps/carbon/app/components/Layout/Sidebar/IconSidebar.tsx
+++ b/apps/carbon/app/components/Layout/Sidebar/IconSidebar.tsx
@@ -38,7 +38,7 @@ const IconSidebar = () => {
}, new Set<string>());
return (
- <div className="h-full border-r border-border bg-background z-10">
+ <div className="h-full bg-background z-10 after:top-0 border-r border-border">
<div>
<TooltipProvider>
<VStack spacing={0} className="self-start sticky">
diff --git a/apps/carbon/app/components/Search/Search/Search.tsx b/apps/carbon/app/components/Search/Search/Search.tsx
index 1489b1fa71..8bbfe45ec4 100644
--- a/apps/carbon/app/components/Search/Search/Search.tsx
+++ b/apps/carbon/app/components/Search/Search/Search.tsx
@@ -1,32 +1,32 @@
import {
Button,
+ Command,
+ CommandEmpty,
+ CommandGroup,
+ CommandInput,
+ CommandItem,
+ CommandList,
+ CommandLoading,
+ CommandSeparator,
HStack,
- Input,
- InputGroup,
- InputLeftElement,
Kbd,
Modal,
- ModalBody,
ModalContent,
- VStack,
useDebounce,
useDisclosure,
useKeyboardShortcuts,
} from "@carbon/react";
-import { clip } from "@carbon/utils";
-import { Link, useNavigate } from "@remix-run/react";
-import clsx from "clsx";
-import { useCallback, useEffect, useRef, useState } from "react";
+import { useNavigate } from "@remix-run/react";
+import { useCallback, useEffect, useState } from "react";
import { AiOutlinePartition } from "react-icons/ai";
import { BiListCheck } from "react-icons/bi";
-import { BsArrowReturnLeft, BsCartDash, BsCartPlus } from "react-icons/bs";
+import { BsCartDash, BsCartPlus } from "react-icons/bs";
import { CgProfile } from "react-icons/cg";
import { HiOutlineDocumentDuplicate } from "react-icons/hi";
import { PiShareNetworkFill } from "react-icons/pi";
import { RxMagnifyingGlass } from "react-icons/rx";
import { useSidebar } from "~/components/Layout/Sidebar/useSidebar";
import { useSupabase } from "~/lib/supabase";
-import type { NavItem } from "~/types";
type SearchResult = {
id: number;
@@ -56,24 +56,18 @@ const SearchModal = ({
}) => {
const { supabase } = useSupabase();
const navigate = useNavigate();
+ const [loading, setLoading] = useState(false);
- const [query, setQuery] = useState("");
- const [debouncedQuery] = useDebounce(query, 500);
+ const [input, setInput] = useState("");
+ const [debouncedInput] = useDebounce(input, 500);
- const defaultResults = useSidebar();
- const [moduleResults, setModuleResults] = useState<NavItem[]>(defaultResults);
- const [searchResults, setSearchResults] = useState<SearchResult[]>([]);
- const [selectedIndex, setSelectedIndex] = useState<number>(0);
-
- const listboxRef = useRef<HTMLUListElement>(null);
+ const moduleResults = useSidebar();
- const onResultClick = () => {
- onClose();
- setQuery("");
- };
+ const [searchResults, setSearchResults] = useState<SearchResult[]>([]);
const getSearchResults = useCallback(
async (q: string) => {
+ setLoading(true);
const tokens = q.split(" ");
const search =
tokens.length > 1
@@ -91,151 +85,75 @@ const SearchModal = ({
} else {
setSearchResults([]);
}
+ setLoading(false);
},
[supabase]
);
- const getModuleResults = useCallback((q: string) => {
- setModuleResults(
- defaultResults.filter((item) => {
- return item.name.toLowerCase().includes(q.toLowerCase());
- })
- );
- // eslint-disable-next-line react-hooks/exhaustive-deps
- }, []);
-
- const onKeyDown = useCallback(
- (event: React.KeyboardEvent<HTMLInputElement>) => {
- const results = [...moduleResults, ...searchResults];
-
- const scrollToListItem = (index: number) => {
- const listbox = listboxRef.current;
- if (listbox) {
- const listItem = listbox.children[index] as HTMLLIElement;
- if (listItem) {
- listItem.scrollIntoView({
- block: "nearest",
- });
- }
- }
- };
-
- const next = () => {
- setSelectedIndex((prev) => {
- const newIndex = clip(prev + 1, 0, results.length - 1);
- scrollToListItem(newIndex);
- return newIndex;
- });
- };
-
- const prev = () => {
- setSelectedIndex((prev) => {
- const newIndex = clip(prev - 1, 0, results.length - 1);
- scrollToListItem(newIndex);
- return newIndex;
- });
- };
-
- switch (event.code) {
- case "Tab":
- event.preventDefault();
- if (event.shiftKey) {
- prev();
- } else {
- next();
- }
- break;
- case "ArrowDown":
- next();
- break;
- case "ArrowUp":
- prev();
- break;
- case "Enter":
- const selectedResult = results[selectedIndex];
- if (selectedResult) {
- if ("link" in selectedResult) {
- navigate(selectedResult.link);
- } else {
- navigate(selectedResult.to);
- }
- onResultClick();
- }
- break;
- default:
- break;
- }
- },
- // eslint-disable-next-line react-hooks/exhaustive-deps
- [debouncedQuery.length, navigate, searchResults, selectedIndex]
- );
-
useEffect(() => {
- setSelectedIndex(0);
- if (debouncedQuery) {
- getSearchResults(debouncedQuery).then(() => {
- getModuleResults(debouncedQuery);
- });
+ if (debouncedInput) {
+ getSearchResults(debouncedInput);
} else {
setSearchResults([]);
- setModuleResults(defaultResults);
}
- // eslint-disable-next-line react-hooks/exhaustive-deps
- }, [debouncedQuery, getModuleResults, getSearchResults]);
+ }, [debouncedInput, getSearchResults]);
+
+ const onInputChange = (value: string) => {
+ setInput(value);
+ };
+
+ const onSelect = (location: string) => {
+ navigate(location);
+ onClose();
+ };
return (
<Modal
open={isOpen}
onOpenChange={(open) => {
- setQuery("");
+ setInput("");
if (!open) onClose();
}}
>
<ModalContent className="rounded-lg top-[10vh] translate-y-0 p-0">
- <ModalBody className="max-h-[66vh]">
- <InputGroup
- size="lg"
- className="ring-0 focus-within:ring-0 shadow-none border-0"
- >
- <InputLeftElement className="pointer-events-none">
- <RxMagnifyingGlass className="text-muted-foreground" />
- </InputLeftElement>
- <Input
- placeholder="Search..."
- value={query}
- onChange={(e) => setQuery(e.target.value)}
- onKeyDown={onKeyDown}
- />
- </InputGroup>
-
- <div className="h-[calc(100%-3rem)] overflow-y-scroll p-4 pt-0">
- <ul role="listbox" ref={listboxRef}>
- {moduleResults.map((item, itemIndex) => (
- <Module
- key={item.to}
- item={item}
- selected={selectedIndex === itemIndex}
- onClick={onResultClick}
- onHover={() => setSelectedIndex(itemIndex)}
- />
+ <Command className="rounded-lg border shadow-md">
+ <CommandInput
+ placeholder="Type a command or search..."
+ value={input}
+ onValueChange={onInputChange}
+ />
+ <CommandList>
+ {loading && <CommandLoading />}
+ <CommandEmpty>No results found.</CommandEmpty>
+
+ <CommandGroup heading="Modules">
+ {moduleResults.map((module) => (
+ <CommandItem
+ key={module.name}
+ onSelect={() => onSelect(module.to)}
+ >
+ <module.icon className="mr-2 w-4 h-4" />
+ <span>{module.name}</span>
+ </CommandItem>
))}
-
- {searchResults.map((result, resultIndex) => (
- <Result
- key={result.uuid}
- result={result}
- selected={
- selectedIndex === resultIndex + moduleResults.length
- }
- onClick={onResultClick}
- onHover={() =>
- setSelectedIndex(resultIndex + moduleResults.length)
- }
- />
- ))}
- </ul>
- </div>
- </ModalBody>
+ </CommandGroup>
+ <CommandSeparator />
+ {searchResults.length > 0 && (
+ <CommandGroup heading="Search Results">
+ {searchResults.map((result) => (
+ <CommandItem
+ key={result.id}
+ value={`${input}${result.id}`}
+ onSelect={() => onSelect(result.link)}
+ >
+ <ResultIcon entity={result.entity} />
+ <span>{result.name}</span>
+ </CommandItem>
+ ))}
+ </CommandGroup>
+ )}
+ </CommandList>
+ </Command>
</ModalContent>
</Modal>
);
@@ -244,125 +162,28 @@ const SearchModal = ({
function ResultIcon({ entity }: { entity: SearchResult["entity"] | "Module" }) {
switch (entity) {
case "Customer":
- return (
- <PiShareNetworkFill className="w-8 h-8 mr-4 text-muted-foreground" />
- );
+ return <PiShareNetworkFill className="w-4 h-4 mr-2 " />;
case "Document":
- return (
- <HiOutlineDocumentDuplicate className="w-8 h-8 mr-4 text-muted-foreground" />
- );
+ return <HiOutlineDocumentDuplicate className="w-4 h-4 mr-2 " />;
case "Job":
- return <BiListCheck className="w-8 h-8 mr-4 text-muted-foreground" />;
+ return <BiListCheck className="w-4 h-4 mr-2 " />;
case "Part":
- return (
- <AiOutlinePartition className="w-8 h-8 mr-4 text-muted-foreground" />
- );
+ return <AiOutlinePartition className="w-4 h-4 mr-2 " />;
case "Person":
- return <CgProfile className="w-8 h-8 mr-4 text-muted-foreground" />;
+ return <CgProfile className="w-4 h-4 mr-2 " />;
case "Resource":
- return <CgProfile className="w-8 h-8 mr-4 text-muted-foreground" />;
+ return <CgProfile className="w-4 h-4 mr-2 " />;
case "Purchase Order":
- return <BsCartDash className="w-8 h-8 mr-4 text-muted-foreground" />;
+ return <BsCartDash className="w-4 h-4 mr-2 " />;
case "Sales Order":
- return <BsCartPlus className="w-8 h-8 mr-4 text-muted-foreground" />;
+ return <BsCartPlus className="w-4 h-4 mr-2 " />;
case "Supplier":
- return (
- <PiShareNetworkFill className="w-8 h-8 mr-4 text-muted-foreground" />
- );
+ return <PiShareNetworkFill className="w-4 h-4 mr-2 " />;
default:
return null;
}
}
-function EnterIcon() {
- return <BsArrowReturnLeft className="w-6 h-6 text-muted-foreground" />;
-}
-
-function Result({
- result,
- selected,
- onClick,
- onHover,
-}: {
- result: SearchResult;
- selected: boolean;
- onClick: () => void;
- onHover: () => void;
-}) {
- return (
- <Link to={result.link} onClick={onClick}>
- <li
- className={clsx(
- "flex w-full items-center bg-card rounded-lg min-h-[4rem] mt-2 p-2",
- {
- "bg-primary text-primary-foreground": selected,
- "bg-muted text-foreground": !selected,
- }
- )}
- role="option"
- aria-selected={selected}
- onMouseEnter={onHover}
- >
- <ResultIcon entity={result.entity} />
- <VStack spacing={0} className="flex-1">
- <p
- className={clsx("text-sm", {
- "text-primary-foreground/60": selected,
- "text-muted-foreground": !selected,
- })}
- >
- {result.entity}
- </p>
- <p className="font-bold">{result.name}</p>
- </VStack>
- <EnterIcon />
- </li>
- </Link>
- );
-}
-
-function Module({
- item,
- selected,
- onClick,
- onHover,
-}: {
- item: NavItem;
- selected: boolean;
- onClick: () => void;
- onHover: () => void;
-}) {
- return (
- <Link to={item.to} onClick={onClick}>
- <li
- className={clsx(
- "flex w-full items-center bg-card rounded-lg min-h-[4rem] mt-2 p-2",
- {
- "bg-primary text-primary-foreground": selected,
- "bg-muted text-foreground": !selected,
- }
- )}
- role="option"
- aria-selected={selected}
- onMouseEnter={onHover}
- >
- <VStack spacing={0} className="flex-1">
- <p
- className={clsx("text-sm", {
- "text-primary-foreground/60": selected,
- "text-muted-foreground": !selected,
- })}
- >
- Module
- </p>
- <p className="font-bold">{item.name}</p>
- </VStack>
- <EnterIcon />
- </li>
- </Link>
- );
-}
-
const SearchButton = () => {
const searchModal = useDisclosure();
useKeyboardShortcuts({
@@ -374,7 +195,7 @@ const SearchButton = () => {
<Button
leftIcon={<RxMagnifyingGlass />}
variant="secondary"
- className="text-muted-foreground w-[200px] px-2"
+ className=" w-[200px] px-2"
onClick={searchModal.onOpen}
>
<HStack className="w-full">
diff --git a/apps/carbon/app/components/Table/components/TableHeader.tsx b/apps/carbon/app/components/Table/components/TableHeader.tsx
index 01d320fff4..9365a8ecd3 100644
--- a/apps/carbon/app/components/Table/components/TableHeader.tsx
+++ b/apps/carbon/app/components/Table/components/TableHeader.tsx
@@ -44,7 +44,7 @@ const TableHeader = <T extends object>({
withSelectableRows,
}: HeaderProps<T>) => {
return (
- <HStack className="px-4 py-3 justify-between bg-background border-b border-border w-full">
+ <HStack className="px-4 py-1.5 justify-between bg-background border-b border-border w-full">
<HStack>
{withSelectableRows && actions.length > 0 && (
<Actions actions={actions} selectedRows={selectedRows} />
diff --git a/apps/carbon/app/modules/purchasing/purchasing.models.ts b/apps/carbon/app/modules/purchasing/purchasing.models.ts
index 14e82bf155..60ee0edc9b 100644
--- a/apps/carbon/app/modules/purchasing/purchasing.models.ts
+++ b/apps/carbon/app/modules/purchasing/purchasing.models.ts
@@ -2,6 +2,7 @@ import { withZod } from "@remix-validated-form/with-zod";
import { z } from "zod";
import { zfd } from "zod-form-data";
import { address, contact } from "~/types/validators";
+import { currencyCodes } from "../accounting";
export const purchaseOrderLineType = [
"Part",
@@ -150,7 +151,7 @@ export const purchaseOrderPaymentValidator = withZod(
invoiceSupplierContactId: zfd.text(z.string().optional()),
paymentTermId: zfd.text(z.string().optional()),
paymentComplete: zfd.checkbox(),
- currencyCode: zfd.text(z.string().optional()),
+ currencyCode: z.enum(currencyCodes).optional(),
})
);
diff --git a/apps/carbon/app/modules/purchasing/purchasing.service.ts b/apps/carbon/app/modules/purchasing/purchasing.service.ts
index 909125d986..f3652ba773 100644
--- a/apps/carbon/app/modules/purchasing/purchasing.service.ts
+++ b/apps/carbon/app/modules/purchasing/purchasing.service.ts
@@ -228,7 +228,7 @@ export async function getRequestsForQuotes(
if (args.search) {
query = query.or(
- `id.ilike.%${args.search}%,name.ilike.%${args.search}%,description.ilike.%${args.search}%`
+ `id.ilike.%${args.search}%,requestForQuoteId.ilike.%${args.search}%,description.ilike.%${args.search}%`
);
}
diff --git a/apps/carbon/app/modules/purchasing/ui/RequestForQuotes/RequestForQuotesTable.tsx b/apps/carbon/app/modules/purchasing/ui/RequestForQuotes/RequestForQuotesTable.tsx
index e000233da4..8271098c96 100644
--- a/apps/carbon/app/modules/purchasing/ui/RequestForQuotes/RequestForQuotesTable.tsx
+++ b/apps/carbon/app/modules/purchasing/ui/RequestForQuotes/RequestForQuotesTable.tsx
@@ -57,7 +57,7 @@ const RequestForQuotesTable = memo(
return [
{
accessorKey: "requestForQuoteId",
- header: "Name",
+ header: "ID",
cell: ({ row }) => (
<HStack>
{row.original.favorite ? (
diff --git a/apps/carbon/app/modules/sales/ui/useSalesSidebar.tsx b/apps/carbon/app/modules/sales/ui/useSalesSidebar.tsx
index 37985a8894..f27527945d 100644
--- a/apps/carbon/app/modules/sales/ui/useSalesSidebar.tsx
+++ b/apps/carbon/app/modules/sales/ui/useSalesSidebar.tsx
@@ -10,6 +10,10 @@ const salesRoutes: AuthenticatedRouteGroup[] = [
name: "Customers",
to: path.to.customers,
},
+ {
+ name: "Quotes",
+ to: path.to.quotes,
+ },
],
},
{
diff --git a/apps/carbon/app/modules/settings/ui/Company/CompanyForm.tsx b/apps/carbon/app/modules/settings/ui/Company/CompanyForm.tsx
index 0f2190e3e0..b180a83c8c 100644
--- a/apps/carbon/app/modules/settings/ui/Company/CompanyForm.tsx
+++ b/apps/carbon/app/modules/settings/ui/Company/CompanyForm.tsx
@@ -1,7 +1,6 @@
import { VStack } from "@carbon/react";
import { ValidatedForm } from "remix-validated-form";
import { Hidden, Input, Submit } from "~/components/Form";
-import { SectionTitle } from "~/components/Layout";
import { companyValidator } from "~/modules/settings";
import type { TypeOfValidator } from "~/types/validators";
import { path } from "~/utils/path";
@@ -13,7 +12,6 @@ type CompanyFormProps = {
const CompanyForm = ({ company }: CompanyFormProps) => {
return (
<div className="w-full">
- <SectionTitle>Basic Information</SectionTitle>
<ValidatedForm
method="post"
action={path.to.company}
diff --git a/apps/carbon/app/utils/path.ts b/apps/carbon/app/utils/path.ts
index 56617ef1d2..fae25336bc 100644
--- a/apps/carbon/app/utils/path.ts
+++ b/apps/carbon/app/utils/path.ts
@@ -353,6 +353,7 @@ export const path = {
generatePath(`${x}/purchase-order/${id}/release`),
purchaseOrders: `${x}/purchasing/orders`,
purchasing: `${x}/purchasing`,
+ quotes: `${x}/sales/quotes`,
receipt: (id: string) => generatePath(`${x}/inventory/receipts/${id}`),
receipts: `${x}/inventory/receipts`,
receiptInvoice: (id: string) => generatePath(`${x}/receipt/${id}/invoice`),
diff --git a/packages/react/src/Command.tsx b/packages/react/src/Command.tsx
index d19abbd691..13c1eb87d5 100644
--- a/packages/react/src/Command.tsx
+++ b/packages/react/src/Command.tsx
@@ -98,6 +98,13 @@ const CommandList = forwardRef<
CommandList.displayName = CommandPrimitive.List.displayName;
+const CommandLoading = forwardRef<
+ ElementRef<typeof CommandPrimitive.Loading>,
+ ComponentPropsWithoutRef<typeof CommandPrimitive.Loading>
+>((props, ref) => <CommandPrimitive.Loading ref={ref} {...props} />);
+
+CommandLoading.displayName = CommandPrimitive.Loading.displayName;
+
const CommandEmpty = forwardRef<
ElementRef<typeof CommandPrimitive.Empty>,
ComponentPropsWithoutRef<typeof CommandPrimitive.Empty>
@@ -272,6 +279,7 @@ export {
CommandInput,
CommandItem,
CommandList,
+ CommandLoading,
CommandSeparator,
CommandShortcut,
CommandTrigger,
diff --git a/packages/react/src/Table.tsx b/packages/react/src/Table.tsx
index 054e2ca762..2e11d9715e 100644
--- a/packages/react/src/Table.tsx
+++ b/packages/react/src/Table.tsx
@@ -69,7 +69,7 @@ const Th = forwardRef<
<th
ref={ref}
className={cn(
- "bg-popover h-11 px-6 text-left align-middle uppercase font-bold tracking-tight text-muted-foreground [&:has([role=checkbox])]:pr-0",
+ "bg-card h-11 px-6 text-left align-middle uppercase font-bold tracking-tight text-muted-foreground [&:has([role=checkbox])]:pr-0",
className
)}
{...props}
diff --git a/packages/react/src/index.tsx b/packages/react/src/index.tsx
index 16e95ab251..0e850f36d4 100644
--- a/packages/react/src/index.tsx
+++ b/packages/react/src/index.tsx
@@ -33,6 +33,7 @@ import {
CommandInput,
CommandItem,
CommandList,
+ CommandLoading,
CommandSeparator,
CommandShortcut,
CommandTrigger,
@@ -234,6 +235,7 @@ export {
CommandInput,
CommandItem,
CommandList,
+ CommandLoading,
CommandSeparator,
CommandShortcut,
CommandTrigger,