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
feat: ui for saving view
Brad Barbind47e68abb056
diff --git a/apps/erp/app/components/Table/Table.tsx b/apps/erp/app/components/Table/Table.tsxindex bcc3247d1d..821df6f554 100644--- a/apps/erp/app/components/Table/Table.tsx+++ b/apps/erp/app/components/Table/Table.tsx@@ -1,6 +1,7 @@import {ActionMenu,Button,+ cn,ContextMenu,ContextMenuContent,ContextMenuTrigger,@@ -17,10 +18,9 @@ import {Th,Thead,Tr,- VStack,- cn,useEscape,useMount,+ VStack,} from "@carbon/react";import { clamp } from "@carbon/utils";import { useNavigation } from "@remix-run/react";@@ -44,7 +44,7 @@ import type {EditableTableCellComponent,Position,} from "~/components/Editable";-import type { fieldMappings } from "~/modules/shared";+import type { fieldMappings, SavedView } from "~/modules/shared";import {IndeterminateCheckbox,Pagination,@@ -81,19 +81,6 @@ interface TableProps<T extends object> {onSelectedRowsChange?: (selectedRows: T[]) => void;renderActions?: (selectedRows: T[]) => ReactNode;renderContextMenu?: (row: T) => JSX.Element | null;- savedView?: {- columnOrder?: string[];- columnPinning?: ColumnPinningState;- columnVisibility?: Record<string, boolean>;- filters?: any;- };- onSaveView?: (view: {- name: string;- columnOrder: string[];- columnPinning: ColumnPinningState;- columnVisibility: Record<string, boolean>;- filters: any;- }) => void;}const Table = <T extends object>({@@ -116,10 +103,11 @@ const Table = <T extends object>({onSelectedRowsChange,renderActions,renderContextMenu,- savedView,}: TableProps<T>) => {const tableContainerRef = useRef<HTMLDivElement>(null);+ const savedView = useSavedView();+/* Data for Optimistic Updates */const [internalData, setInternalData] = useState<T[]>(data);useEffect(() => {@@ -606,7 +594,7 @@ const Table = <T extends object>({spacing={0}className={cn("h-full bg-card",- !compact && "flex flex-col w-full px-0 md:px-4 lg:px-8 xl:px-12"+ !compact && "flex flex-col w-full px-0 md:px-4 lg:px-6")}><TableHeader@@ -908,4 +896,8 @@ function getActionColumn<T>(];}+function useSavedView(): SavedView | undefined {+ return undefined;+}+export default Table;diff --git a/apps/erp/app/components/Table/components/Columns.tsx b/apps/erp/app/components/Table/components/Columns.tsxindex c1654afe80..cc71681a7a 100644--- a/apps/erp/app/components/Table/components/Columns.tsx+++ b/apps/erp/app/components/Table/components/Columns.tsx@@ -8,6 +8,9 @@ import {DrawerTrigger,HStack,IconButton,+ Tooltip,+ TooltipContent,+ TooltipTrigger,} from "@carbon/react";import type { Column, ColumnOrderState } from "@tanstack/react-table";import { Reorder } from "framer-motion";@@ -35,18 +38,25 @@ const Columns = <T extends object>({}: ColumnsProps<T>) => {return (<Drawer>- <DrawerTrigger asChild>- <IconButton- aria-label="Columns"- title="Columns"- variant="ghost"- icon={<LuColumns2 />}- />+ <DrawerTrigger>+ <Tooltip>+ <TooltipTrigger asChild>+ <IconButton+ aria-label="Columns"+ title="Columns"+ variant="ghost"+ icon={<LuColumns2 />}+ />+ </TooltipTrigger>+ <TooltipContent>+ <p>Column visibility and order</p>+ </TooltipContent>+ </Tooltip></DrawerTrigger><DrawerContent><DrawerHeader>- <DrawerTitle>Edit column view</DrawerTitle>- <DrawerDescription>Manage and reorder columns</DrawerDescription>+ <DrawerTitle>Edit column visibility</DrawerTitle>+ <DrawerDescription>Hide, pin and reorder columns</DrawerDescription></DrawerHeader><DrawerBody><Reorder.Groupdiff --git a/apps/erp/app/components/Table/components/Sort/Sort.tsx b/apps/erp/app/components/Table/components/Sort/Sort.tsxindex cf67e9923f..956e632314 100644--- a/apps/erp/app/components/Table/components/Sort/Sort.tsx+++ b/apps/erp/app/components/Table/components/Sort/Sort.tsx@@ -13,6 +13,9 @@ import {PopoverHeader,PopoverTrigger,Switch,+ Tooltip,+ TooltipContent,+ TooltipTrigger,cn,} from "@carbon/react";import { Reorder } from "framer-motion";@@ -37,14 +40,21 @@ const Sort = ({ columnAccessors }: SortProps) => {return (<Popover>- <PopoverTrigger asChild>- <IconButton- aria-label="Sort"- title="Sort"- variant={hasNoSorts ? "ghost" : "secondary"}- icon={<LuArrowUpDown />}- className={cn(hasNoSorts && "!border-dashed border-border")}- />+ <PopoverTrigger>+ <Tooltip>+ <TooltipTrigger asChild>+ <IconButton+ aria-label="Sort"+ title="Sort"+ variant={hasNoSorts ? "ghost" : "secondary"}+ icon={<LuArrowUpDown />}+ className={cn(hasNoSorts && "!border-dashed border-border")}+ />+ </TooltipTrigger>+ <TooltipContent>+ <p>Sort by</p>+ </TooltipContent>+ </Tooltip></PopoverTrigger><PopoverContent className="w-[420px]">{hasNoSorts && (diff --git a/apps/erp/app/components/Table/components/TableHeader.tsx b/apps/erp/app/components/Table/components/TableHeader.tsxindex 5062959cac..24232a7cbe 100644--- a/apps/erp/app/components/Table/components/TableHeader.tsx+++ b/apps/erp/app/components/Table/components/TableHeader.tsx@@ -1,6 +1,10 @@+import { Input, ValidatedForm } from "@carbon/form";import {Badge,Button,+ Card,+ CardContent,+ CardFooter,cn,DropdownMenu,DropdownMenuContent,@@ -12,11 +16,16 @@ import {Heading,HStack,IconButton,+ Tooltip,+ TooltipContent,+ TooltipTrigger,+ useDisclosure,} from "@carbon/react";import type { Column, ColumnOrderState } from "@tanstack/react-table";import { useState, type ReactNode } from "react";import { BsThreeDotsVertical } from "react-icons/bs";-import { LuCheck, LuFilePen, LuImport, LuLock } from "react-icons/lu";+import { LuCheck, LuFilePen, LuImport, LuLayers, LuLock } from "react-icons/lu";+import { z } from "zod";import { SearchFilter } from "~/components";import { ImportCSVModal } from "~/components/ImportCSVModal";import { CollapsibleSidebarTrigger } from "~/components/Layout/Navigation";@@ -79,53 +88,91 @@ const TableHeader = <T extends object>({keyof typeof fieldMappings | null>(null);+ const savedViewDisclosure = useDisclosure();+return (<div className={cn("w-full flex flex-col", !compact && "mb-8")}>- <HStack- className={cn(- compact- ? "px-4 py-2 justify-between bg-card border-b w-full"- : "px-4 md:px-0 py-6 md:py-10 justify-between bg-card w-full relative"- )}- >- <HStack spacing={1}>- <CollapsibleSidebarTrigger />- {title && <Heading size={compact ? "h3" : "h2"}>{title}</Heading>}- </HStack>+ {savedViewDisclosure.isOpen ? (+ <ValidatedForm+ onSubmit={() => {}}+ validator={z.object({+ name: z+ .string()+ .min(1, { message: "A name is required to save a view" }),+ })}+ className="w-full px-2 md:px-0"+ >+ <Card className="my-4 p-0">+ <CardContent className="flex flex-col gap-0 p-4">+ <Input+ autoFocus+ name="name"+ placeholder="My Saved View"+ label=""+ className="border-none p-0 ring-0 focus-visible:ring-0 focus-visible:ring-offset-0 font-medium text-base"+ />+ <Input+ name="description"+ label=""+ placeholder="Description (optional)"+ className="border-none p-0 ring-0 focus-visible:ring-0 focus-visible:ring-offset-0 text-sm"+ />+ </CardContent>+ <CardFooter className="border-t bg-muted/30 p-4">+ <Button variant="secondary" onClick={savedViewDisclosure.onClose}>+ Cancel+ </Button>+ <Button>Save</Button>+ </CardFooter>+ </Card>+ </ValidatedForm>+ ) : (+ <HStack+ className={cn(+ compact+ ? "px-4 py-2 justify-between bg-card border-b w-full"+ : "px-4 md:px-0 py-6 justify-between bg-card w-full relative"+ )}+ >+ <HStack spacing={1}>+ <CollapsibleSidebarTrigger />+ {title && <Heading size={compact ? "h3" : "h2"}>{title}</Heading>}+ </HStack>- <HStack>- {/* <Button variant="secondary" leftIcon={<LuDownload />}>+ <HStack>+ {/* <Button variant="secondary" leftIcon={<LuDownload />}>Export- </Button> */}- <>{primaryAction}</>- {importCSV && (- <DropdownMenu>- <DropdownMenuTrigger asChild>- <IconButton- aria-label="Table actions"- variant="secondary"- icon={<BsThreeDotsVertical />}- />- </DropdownMenuTrigger>- <DropdownMenuContent align="end">- <DropdownMenuLabel>Bulk Import</DropdownMenuLabel>- <DropdownMenuSeparator />- {importCSV.map(({ table, label }) => (- <DropdownMenuItem- key={table}- onClick={() => {- setImportCSVTable(table);- }}- >- <DropdownMenuIcon icon={<LuImport />} />- Import {label} CSV- </DropdownMenuItem>- ))}- </DropdownMenuContent>- </DropdownMenu>- )}+ </Button> */}+ <>{primaryAction}</>+ {importCSV && (+ <DropdownMenu>+ <DropdownMenuTrigger asChild>+ <IconButton+ aria-label="Table actions"+ variant="secondary"+ icon={<BsThreeDotsVertical />}+ />+ </DropdownMenuTrigger>+ <DropdownMenuContent align="end">+ <DropdownMenuLabel>Bulk Import</DropdownMenuLabel>+ <DropdownMenuSeparator />+ {importCSV.map(({ table, label }) => (+ <DropdownMenuItem+ key={table}+ onClick={() => {+ setImportCSVTable(table);+ }}+ >+ <DropdownMenuIcon icon={<LuImport />} />+ Import {label} CSV+ </DropdownMenuItem>+ ))}+ </DropdownMenuContent>+ </DropdownMenu>+ )}+ </HStack></HStack>- </HStack>+ )}<HStackclassName={cn(compact@@ -167,6 +214,20 @@ const TableHeader = <T extends object>({withSelectableRows={withSelectableRows}/>+ <Tooltip>+ <TooltipTrigger asChild>+ <IconButton+ aria-label="Save View"+ variant={savedViewDisclosure.isOpen ? "active" : "ghost"}+ icon={<LuLayers />}+ onClick={savedViewDisclosure.onToggle}+ />+ </TooltipTrigger>+ <TooltipContent>+ <p>Save View</p>+ </TooltipContent>+ </Tooltip>+{withPagination &&(pagination.canNextPage || pagination.canPreviousPage) && (<PaginationButtons {...pagination} condensed />diff --git a/apps/erp/app/modules/sales/ui/Quotes/QuotesTable.tsx b/apps/erp/app/modules/sales/ui/Quotes/QuotesTable.tsxindex 57592fe900..1866deaaff 100644--- a/apps/erp/app/modules/sales/ui/Quotes/QuotesTable.tsx+++ b/apps/erp/app/modules/sales/ui/Quotes/QuotesTable.tsx@@ -314,34 +314,6 @@ const QuotesTable = memo(({ data, count }: QuotesTableProps) => {}renderContextMenu={renderContextMenu}title="Quotes"- savedView={{- columnOrder: [- "quoteId",- "status",- "createdBy",- "customerId",- "customerReference",- "salesPersonId",- "estimatorId",- "assignee",- "dueDate",- "expirationDate",- "locationName",- "createdAt",- "updatedBy",- "updatedAt",- ],- columnPinning: {- left: ["quoteId", "status"],- right: ["Actions"],- },- columnVisibility: {- createdAt: true,- createdBy: true,- updatedAt: false,- updatedBy: false,- },- }}/>{selectedQuotation && selectedQuotation.id && (<ConfirmDeletediff --git a/apps/erp/app/modules/shared/types.ts b/apps/erp/app/modules/shared/types.tsindex c9e721f03e..6f3700b4b4 100644--- a/apps/erp/app/modules/shared/types.ts+++ b/apps/erp/app/modules/shared/types.ts@@ -1,3 +1,4 @@+import type { ColumnPinningState } from "@tanstack/react-table";import type { z } from "zod";import type { StorageItem } from "~/types";import type {@@ -57,6 +58,15 @@ export type OptimisticFileObject = Omit<"owner" | "updated_at" | "created_at" | "last_accessed_at" | "buckets">;-export type StandardFactor = (typeof standardFactorType)[number];-export type QuantityEffect = (quantity: number) => number;++export type SavedView = {+ columnOrder: string[];+ columnPinning: ColumnPinningState;+ columnVisibility: Record<string, boolean>;+ name: string;+ sort: string;+ filters: string;+};++export type StandardFactor = (typeof standardFactorType)[number];