| import type { |
| ColumnOrderState, |
| ColumnSizingState, |
| VisibilityState, |
| } from "@tanstack/react-table"; |
|
|
| |
| |
| |
| export type TableId = "transactions" | "customers" | "invoices" | "vault"; |
|
|
| |
| |
| |
| export interface TableSettings { |
| columns: VisibilityState; |
| sizing: ColumnSizingState; |
| order: ColumnOrderState; |
| } |
|
|
| |
| |
| |
| export type AllTableSettings = { |
| [K in TableId]?: Partial<TableSettings>; |
| }; |
|
|
| |
| |
| |
| export const TABLE_SETTINGS_COOKIE = "table-settings"; |
|
|
| |
| |
| |
| export const defaultHiddenColumns: Record<TableId, string[]> = { |
| transactions: ["assigned", "tags", "method", "counterparty", "taxAmount"], |
| customers: ["tags", "website", "financeEmail", "language"], |
| invoices: [ |
| "sentAt", |
| "exclVat", |
| "exclTax", |
| "vatAmount", |
| "taxAmount", |
| "vatRate", |
| "taxRate", |
| "internalNote", |
| ], |
| vault: [], |
| }; |
|
|
| |
| |
| |
| export function getDefaultColumnVisibility(tableId: TableId): VisibilityState { |
| const columnsToHide = defaultHiddenColumns[tableId]; |
| return columnsToHide.reduce( |
| (acc, col) => { |
| acc[col] = false; |
| return acc; |
| }, |
| {} as Record<string, boolean>, |
| ); |
| } |
|
|
| |
| |
| |
| export function getDefaultTableSettings(tableId: TableId): TableSettings { |
| return { |
| columns: getDefaultColumnVisibility(tableId), |
| sizing: {}, |
| order: [], |
| }; |
| } |
|
|
| |
| |
| |
| export function mergeWithDefaults( |
| saved: Partial<TableSettings> | undefined, |
| tableId: TableId, |
| ): TableSettings { |
| const defaults = getDefaultTableSettings(tableId); |
| return { |
| columns: saved?.columns ?? defaults.columns, |
| sizing: saved?.sizing ?? defaults.sizing, |
| order: saved?.order ?? defaults.order, |
| }; |
| } |
|
|