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: table definitions for saved views

Brad Barbin63fc96459dd3
diff --git a/apps/erp/app/components/Table/Table.tsx b/apps/erp/app/components/Table/Table.tsx
index 6b0104bef2..dea3444807 100644
--- a/apps/erp/app/components/Table/Table.tsx
+++ b/apps/erp/app/components/Table/Table.tsx
@@ -81,6 +81,19 @@ 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>({
@@ -103,6 +116,7 @@ const Table = <T extends object>({
onSelectedRowsChange,
renderActions,
renderContextMenu,
+ savedView,
}: TableProps<T>) => {
const tableContainerRef = useRef<HTMLDivElement>(null);
@@ -120,12 +134,12 @@ const Table = <T extends object>({
/* Column Visibility */
const [columnVisibility, setColumnVisibility] = useState(
- defaultColumnVisibility ?? {}
+ savedView?.columnVisibility ?? defaultColumnVisibility ?? {}
);
/* Column Ordering */
const [columnOrder, setColumnOrder] = useState<ColumnOrderState>(
- defaultColumnOrder ?? []
+ savedView?.columnOrder ?? defaultColumnOrder ?? []
);
const [columnPinning, setColumnPinning] = useState<ColumnPinningState>(() => {
const left: string[] = [];
@@ -136,6 +150,9 @@ const Table = <T extends object>({
if (renderContextMenu) {
right.push("Actions");
}
+ if (savedView?.columnPinning) {
+ return savedView.columnPinning;
+ }
if (
defaultColumnPinning &&
"left" in defaultColumnPinning &&
@@ -558,6 +575,16 @@ const Table = <T extends object>({
delay: 300,
});
+ useEffect(() => {
+ console.log({
+ savedView: {
+ columnOrder,
+ columnPinning,
+ columnVisibility,
+ },
+ });
+ }, [columnOrder, columnPinning, columnVisibility, savedView]);
+
return (
<VStack
spacing={0}
diff --git a/apps/erp/app/modules/sales/ui/Quotes/QuotesTable.tsx b/apps/erp/app/modules/sales/ui/Quotes/QuotesTable.tsx
index 1866deaaff..57592fe900 100644
--- a/apps/erp/app/modules/sales/ui/Quotes/QuotesTable.tsx
+++ b/apps/erp/app/modules/sales/ui/Quotes/QuotesTable.tsx
@@ -314,6 +314,34 @@ 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 && (
<ConfirmDelete