@appdirect/design-system 0.0.16 → 0.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/bin/ad-sync-design-md.mjs +0 -0
  2. package/dist/ComplexComponents/DataTable/CellHoverReveal/CellHoverReveal.module.css +25 -0
  3. package/dist/ComplexComponents/DataTable/CellHoverReveal/index.js +24 -0
  4. package/dist/ComplexComponents/DataTable/CellHoverReveal/index.tsx +44 -0
  5. package/dist/ComplexComponents/DataTable/CustomBottomToolbar/CustomBottomToolbar.module.css +7 -0
  6. package/dist/ComplexComponents/DataTable/CustomBottomToolbar/index.js +25 -77
  7. package/dist/ComplexComponents/DataTable/CustomBottomToolbar/index.tsx +101 -157
  8. package/dist/ComplexComponents/DataTable/CustomBottomToolbar/utils.js +14 -7
  9. package/dist/ComplexComponents/DataTable/CustomBottomToolbar/utils.ts +13 -7
  10. package/dist/ComplexComponents/DataTable/CustomToolbarAlertBannerContent/CustomToolbarAlertBannerContent.module.css +4 -0
  11. package/dist/ComplexComponents/DataTable/CustomToolbarAlertBannerContent/index.js +8 -20
  12. package/dist/ComplexComponents/DataTable/CustomToolbarAlertBannerContent/index.tsx +40 -58
  13. package/dist/ComplexComponents/DataTable/CustomTopToolbar/CustomTopToolbar.module.css +7 -0
  14. package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/DateRangeSelectorFilter.module.css +3 -0
  15. package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/index.js +50 -154
  16. package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/index.tsx +59 -205
  17. package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/utils.js +48 -0
  18. package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/utils.ts +51 -0
  19. package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterChip.js +5 -25
  20. package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterChip.tsx +7 -28
  21. package/dist/ComplexComponents/DataTable/CustomTopToolbar/ResultCount.js +16 -0
  22. package/dist/ComplexComponents/DataTable/CustomTopToolbar/ResultCount.tsx +26 -0
  23. package/dist/ComplexComponents/DataTable/CustomTopToolbar/SearchFilter.js +26 -28
  24. package/dist/ComplexComponents/DataTable/CustomTopToolbar/SearchFilter.tsx +38 -38
  25. package/dist/ComplexComponents/DataTable/CustomTopToolbar/SelectFilter.js +8 -18
  26. package/dist/ComplexComponents/DataTable/CustomTopToolbar/SelectFilter.module.css +3 -0
  27. package/dist/ComplexComponents/DataTable/CustomTopToolbar/SelectFilter.tsx +25 -37
  28. package/dist/ComplexComponents/DataTable/CustomTopToolbar/index.js +67 -378
  29. package/dist/ComplexComponents/DataTable/CustomTopToolbar/index.tsx +170 -711
  30. package/dist/ComplexComponents/DataTable/DataTable.js +74 -393
  31. package/dist/ComplexComponents/DataTable/DataTable.tsx +229 -546
  32. package/dist/ComplexComponents/DataTable/DataTableGrid/DataTableGrid.module.css +85 -0
  33. package/dist/ComplexComponents/DataTable/DataTableGrid/index.js +46 -0
  34. package/dist/ComplexComponents/DataTable/DataTableGrid/index.tsx +143 -0
  35. package/dist/ComplexComponents/DataTable/DataTableShell/DataTableShell.module.css +38 -0
  36. package/dist/ComplexComponents/DataTable/DataTableShell/index.js +9 -0
  37. package/dist/ComplexComponents/DataTable/DataTableShell/index.tsx +47 -0
  38. package/dist/ComplexComponents/DataTable/ErrorOverlay/index.js +6 -6
  39. package/dist/ComplexComponents/DataTable/ErrorOverlay/index.tsx +53 -24
  40. package/dist/ComplexComponents/DataTable/SelectCheckbox/index.js +33 -0
  41. package/dist/ComplexComponents/DataTable/SelectCheckbox/index.tsx +63 -0
  42. package/dist/ComplexComponents/DataTable/SortableHeaderCell/SortableHeaderCell.module.css +3 -0
  43. package/dist/ComplexComponents/DataTable/SortableHeaderCell/index.js +43 -21
  44. package/dist/ComplexComponents/DataTable/SortableHeaderCell/index.tsx +62 -38
  45. package/dist/ComplexComponents/DataTable/ToggleDensityButton/index.js +18 -0
  46. package/dist/ComplexComponents/DataTable/ToggleDensityButton/index.tsx +47 -0
  47. package/dist/ComplexComponents/DataTable/ToggleFullScreenButton/index.js +19 -0
  48. package/dist/ComplexComponents/DataTable/ToggleFullScreenButton/index.tsx +59 -0
  49. package/dist/ComplexComponents/DataTable/ToolbarAlertBanner/ToolbarAlertBanner.module.css +15 -0
  50. package/dist/ComplexComponents/DataTable/ToolbarAlertBanner/index.js +8 -0
  51. package/dist/ComplexComponents/DataTable/ToolbarAlertBanner/index.tsx +20 -0
  52. package/dist/ComplexComponents/DataTable/hooks/useClickOutside.js +27 -0
  53. package/dist/ComplexComponents/DataTable/hooks/useClickOutside.ts +39 -0
  54. package/dist/ComplexComponents/DataTable/index.js +5 -1
  55. package/dist/ComplexComponents/DataTable/index.ts +13 -2
  56. package/dist/ComplexComponents/DataTable/table.module.css +9 -0
  57. package/dist/ComplexComponents/DataTable/tableFeatures.js +6 -0
  58. package/dist/ComplexComponents/DataTable/tableFeatures.ts +7 -0
  59. package/dist/ComplexComponents/DataTable/translations/en.js +16 -4
  60. package/dist/ComplexComponents/DataTable/translations/en.ts +16 -4
  61. package/dist/ComplexComponents/DataTable/translations/index.js +5 -0
  62. package/dist/ComplexComponents/DataTable/translations/index.ts +11 -1
  63. package/dist/ComplexComponents/DataTable/types.js +5 -0
  64. package/dist/ComplexComponents/DataTable/types.ts +17 -0
  65. package/dist/ComplexComponents/DataTable/utils/parseCSSVarId.js +3 -0
  66. package/dist/ComplexComponents/DataTable/utils/parseCSSVarId.ts +4 -0
  67. package/dist/DESIGN.md +9 -10
  68. package/dist/contracts/DataTable.json +83 -6
  69. package/dist/contracts/index.json +1 -1
  70. package/dist/css/foundations.css +4 -0
  71. package/dist/css/mantine.css +1 -1
  72. package/dist/css/tokens.css +3145 -0
  73. package/dist/index.js +3 -0
  74. package/dist/index.ts +14 -1
  75. package/dist/stories/ComplexComponents/DataTable/DataTable.stories.tsx +216 -458
  76. package/dist/stories/index.json +13 -15
  77. package/package.json +5 -3
  78. package/dist/ComplexComponents/DataTable/CustomTopToolbar/ResultCount/index.js +0 -31
  79. package/dist/ComplexComponents/DataTable/CustomTopToolbar/ResultCount/index.tsx +0 -76
  80. package/dist/hooks/useTableHandlers.js +0 -136
  81. package/dist/hooks/useTableHandlers.ts +0 -179
  82. package/dist/hooks/useTableRenderFunctions.js +0 -164
  83. package/dist/hooks/useTableRenderFunctions.tsx +0 -283
  84. package/dist/hooks/useTableState.js +0 -70
  85. package/dist/hooks/useTableState.ts +0 -81
@@ -1,582 +1,265 @@
1
1
  'use client';
2
2
 
3
- import React, { useMemo } from 'react';
4
- import {
5
- useMantineReactTable,
6
- MantineReactTable,
7
- MRT_PaginationState as PaginationState,
8
- MRT_RowSelectionState as RowSelectionState,
9
- MRT_DensityState as DensityState,
10
- MRT_RowData,
11
- MRT_ColumnDef as ColumnDef,
12
- } from 'mantine-react-table-open';
13
- import { useTableState } from '../../hooks/useTableState';
14
- import { useTableHandlers } from '../../hooks/useTableHandlers';
15
- import { useTableRenderFunctions } from '../../hooks/useTableRenderFunctions';
16
- import { type Filters, type DateRange, type City } from './CustomTopToolbar';
17
-
18
- // ========================== EXPORTS ==========================
19
3
  /**
20
- * Re-export commonly used types from sub-components for convenience
21
- * This allows consumers to import these types directly from the Table component
4
+ * DataTable: controlled composition of the micro-ui-ts table pieces.
5
+ *
6
+ * Source of truth for the pieces is `micro-ui-ts/src/components/Table`. This file is the one
7
+ * DS-only layer: it assembles the same pieces the micro-ui-ts `Table` page assembles, but takes
8
+ * all state as props (controlled, stateless). A prototype using `<DataTable>` therefore has the
9
+ * same shape as production: swap the mock data source for the real query and keep the rest.
10
+ *
11
+ * Rules for this file:
12
+ * - No state, no data fetching, no behaviour that is not a visible composition of the exported pieces.
13
+ * - Prop and type names follow micro-ui-ts (`PaginationState`, `RowSelectionState`, `DensityState`).
22
14
  */
23
- export type { Filters, DateRange, City };
24
-
25
- // TODO: Review integration with PageContentHeader Description feature
26
- // - Consider adding table description/subtitle support
27
- // - Evaluate if table metadata should be displayed in header area
28
- // - Review accessibility implications of description placement
29
15
 
30
- // ========================== TYPES ==========================
31
- /**
32
- * Union type for sort directions used throughout the table
33
- * null represents no sorting applied to a column
34
- */
35
- type SortDirection = 'asc' | 'desc' | null;
16
+ import React, { useMemo, type ReactElement, type ReactNode } from 'react';
17
+ import { createColumnHelper, useTable, type ColumnDef, type RowData } from '@tanstack/react-table';
18
+ import { RiDeleteBin5Line, RiSearchLine } from '@remixicon/react';
19
+ import { translate } from './translations';
20
+ import { dataTableFeatures } from './tableFeatures';
21
+ import { type DensityState, type PaginationState, type RowSelectionState } from './types';
22
+ import CustomTopToolbar, { type Filters } from './CustomTopToolbar';
23
+ import CustomBottomToolbar from './CustomBottomToolbar';
24
+ import CustomToolbarAlertBannerContent from './CustomToolbarAlertBannerContent';
25
+ import ToolbarAlertBanner from './ToolbarAlertBanner';
26
+ import ToggleDensityButton from './ToggleDensityButton';
27
+ import ToggleFullScreenButton from './ToggleFullScreenButton';
28
+ import ErrorOverlay from './ErrorOverlay';
29
+ import DataTableGrid from './DataTableGrid';
30
+ import DataTableShell from './DataTableShell';
31
+ import { getSelectColumnDef, RowSelectionContext } from './SelectCheckbox';
36
32
 
37
- /**
38
- * Enhanced TableColumn interface with better typing and additional options
39
- * Extends the basic column definition with custom properties
40
- */
41
- export interface DataTableColumn<T extends MRT_RowData> {
42
- /** The key from the data object to access the column value */
43
- accessorKey: keyof T;
44
- /** Column header - can be static text or a React component function */
45
- header: string | (() => React.ReactNode);
46
- /** Optional fixed width for the column in pixels */
47
- size?: number;
48
- /** Whether this column can be sorted by the user */
49
- enableSorting?: boolean;
50
- /** Whether filtering is enabled for this column */
51
- enableColumnFilter?: boolean;
52
- }
53
-
54
- /**
55
- * Page information interface for cursor-based pagination
56
- * Used to determine navigation availability and cursor positions
57
- */
33
+ /** Cursor pagination info, matching the AppDirect GraphQL `pageInfo`. */
58
34
  export interface PageInfo {
59
- /** Whether there are more pages after the current one */
60
35
  hasNextPage: boolean;
61
- /** Whether there are pages before the current one */
62
36
  hasPreviousPage: boolean;
63
- /** Cursor pointing to the start of the current page (for cursor-based pagination) */
64
- startCursor?: string;
65
- /** Cursor pointing to the end of the current page (for cursor-based pagination) */
66
- endCursor?: string;
37
+ startCursor?: string | null;
38
+ endCursor?: string | null;
67
39
  }
68
40
 
69
- /**
70
- * Comprehensive props interface for the Table component
71
- * Organized by functionality for better maintainability
72
- */
73
- export interface DataTableProps<T extends MRT_RowData> {
74
- // ==================== DATA PROPS ====================
75
- /** Array of data objects to display in the table */
76
- data: T[];
77
- /** Column definitions specifying how to render each column */
78
- columns: ColumnDef<T>[];
79
- /** Total number of items across all pages (for pagination display) */
80
- totalCount?: number;
81
-
82
- // ==================== LOADING AND ERROR STATES ====================
83
- /** Whether the table is currently loading data */
41
+ /** A bulk action shown in the selection banner. */
42
+ export interface DataTableSelectionAction {
43
+ label: string;
44
+ onClick: () => void;
45
+ SVGIcon?: ReactNode;
46
+ }
47
+
48
+ /** Column definitions for `DataTable`. Build them with `createDataTableColumnHelper<Row>()`. */
49
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- columns mix value types (string, number, ...)
50
+ export type DataTableColumnDef<TData extends RowData> = ColumnDef<typeof dataTableFeatures, TData, any>;
51
+
52
+ /** Same helper `micro-ui-ts` uses: `createColumnHelper<typeof dataTableFeatures, TData>()`. */
53
+ export const createDataTableColumnHelper = <TData extends RowData>() =>
54
+ createColumnHelper<typeof dataTableFeatures, TData>();
55
+
56
+ export interface DataTableProps<TData extends RowData> {
57
+ // ---- Data ----
58
+ data: TData[];
59
+ columns: DataTableColumnDef<TData>[];
60
+ /** Total rows across all pages. */
61
+ totalCount: number;
62
+ /** Row id accessor. Defaults to `row.id`. */
63
+ getRowId?: (row: TData) => string;
64
+
65
+ // ---- Loading and error ----
84
66
  isLoading?: boolean;
85
- /** Whether an error has occurred while loading data */
67
+ /** True while refetching (page change, sort, filter). */
68
+ isFetching?: boolean;
86
69
  isError?: boolean;
87
- /** Error message to display when isError is true */
88
- error?: string;
89
- /** Callback function to retry loading data after an error */
90
70
  onRetry?: () => void;
91
-
92
- // ==================== PAGINATION PROPS ====================
93
- /** Page information for cursor-based pagination */
71
+
72
+ // ---- Pagination (cursor based) ----
73
+ pagination: PaginationState;
94
74
  pageInfo?: PageInfo;
95
- /** Callback fired when pagination state changes (page or page size) */
96
- onPaginationChange?: (pagination: PaginationState) => void;
97
- /** Default number of rows to show per page */
98
- defaultPageSize?: number;
99
-
100
- // ==================== SELECTION PROPS ====================
101
- /** Callback fired when row selection changes */
102
- onRowSelectionChange?: (rowSelection: RowSelectionState) => void;
103
-
104
- // ==================== UI STATE PROPS ====================
105
- /** Callback fired when table density (row height) changes */
106
- onDensityChange?: (density: DensityState) => void;
107
- /** Default density setting for the table */
108
- defaultDensity?: DensityState;
109
-
110
- // ==================== SORTING PROPS ====================
111
- /** Callback fired when column sorting changes */
112
- onSortChange?: (field: string, direction: SortDirection) => void;
113
-
114
- // ==================== FILTER PROPS ====================
115
- /** Current state of all applied filters */
116
- filtersState?: Filters;
117
- /** Callback fired when filters are modified */
118
- onFiltersChange?: (filters: Filters) => void;
119
- /** Locale string for internationalization */
120
- locale?: string;
121
-
122
- // ==================== FEATURE TOGGLES ====================
123
- /** Whether to show the filters panel */
124
- showFilters?: boolean;
125
- /** Whether to show the global search input */
126
- showSearch?: boolean;
127
- /** Whether to show the density toggle button */
128
- showDensityToggle?: boolean;
129
- /** Whether to show the fullscreen toggle button */
130
- showFullScreenToggle?: boolean;
131
-
132
- // ==================== STYLE CUSTOMIZATION ====================
133
- /** Additional props to pass to the table container element */
134
- mantineTableContainerProps?: Record<string, any>;
135
- /** Additional props to pass to the paper wrapper element */
136
- mantinePaperProps?: Record<string, any>;
137
-
138
- // ==================== DEPRECATED/UNUSED PROPS ====================
139
- /** @deprecated Use totalCount instead - kept for backward compatibility */
140
- resultCount?: number;
141
- }
75
+ onPreviousPage: () => void;
76
+ onNextPage: () => void;
77
+ onPageSizeChange: (pageSize: number) => void;
142
78
 
143
- // ========================== CONSTANTS ==========================
144
- /**
145
- * Default values for various table configuration options
146
- * Centralized to ensure consistency and easy modification
147
- */
148
- const DEFAULT_VALUES = {
149
- /** Default number of rows per page */
150
- PAGE_SIZE: 10,
151
- /** Default table density (row height) - 'xs' is most compact */
152
- DENSITY: 'xs' as DensityState,
153
- /** Default locale for internationalization */
154
- LOCALE: 'en',
155
- /** Default total count when not provided */
156
- TOTAL_COUNT: 0,
157
- /** Default result count (deprecated) */
158
- RESULT_COUNT: 0,
159
- } as const;
79
+ // ---- Selection ----
80
+ rowSelection: RowSelectionState;
81
+ onRowSelectionChange: (rowSelection: RowSelectionState) => void;
82
+ /** Bulk actions in the selection banner. */
83
+ selectionActions?: DataTableSelectionAction[];
160
84
 
161
- /**
162
- * Feature flags that control which table features are enabled by default
163
- * Can be overridden by props but provide sensible defaults
164
- */
165
- const FEATURE_FLAGS = {
166
- /** Enable filters panel by default */
167
- SHOW_FILTERS: true,
168
- /** Enable global search by default */
169
- SHOW_SEARCH: true,
170
- /** Enable density toggle by default */
171
- SHOW_DENSITY_TOGGLE: true,
172
- /** Enable fullscreen toggle by default */
173
- SHOW_FULL_SCREEN_TOGGLE: true,
174
- } as const;
85
+ // ---- Display ----
86
+ density: DensityState;
87
+ onDensityChange: (density: DensityState) => void;
88
+ isFullScreen: boolean;
89
+ onFullScreenChange: (isFullScreen: boolean) => void;
175
90
 
176
- // ========================== CUSTOM HOOKS ==========================
91
+ // ---- Filters ----
92
+ filters: Filters;
93
+ onFiltersChange: (filters: Filters) => void;
94
+ /** Called by the empty state button to clear filters. */
95
+ onResetFilters: () => void;
96
+ showFilters: boolean;
97
+ onFilterToggleChange: () => void;
98
+ locale: string;
177
99
 
178
- /**
179
- * DataTable Component
180
- *
181
- * A powerful, feature-rich data table component built on top of Mantine React Table.
182
- * Supports pagination, sorting, filtering, row selection, density controls, and more.
183
- * Perfect for displaying large datasets with complex interaction requirements.
184
- *
185
- * @example
186
- * // Basic usage with minimal configuration
187
- * const userData = [
188
- * { id: '1', name: 'John Doe', email: 'john@example.com', status: 'Active' },
189
- * { id: '2', name: 'Jane Smith', email: 'jane@example.com', status: 'Inactive' },
190
- * ];
191
- *
192
- * const columns = [
193
- * { accessorKey: 'name', header: 'Name' },
194
- * { accessorKey: 'email', header: 'Email' },
195
- * { accessorKey: 'status', header: 'Status' },
196
- * ];
197
- *
198
- * <DataTable
199
- * data={userData}
200
- * columns={columns}
201
- * />
202
- *
203
- * @example
204
- * // Advanced usage with pagination and filtering
205
- * const [tableData, setTableData] = useState([]);
206
- * const [pagination, setPagination] = useState({ pageIndex: 0, pageSize: 10 });
207
- * const [filters, setFilters] = useState({});
208
- * const [isLoading, setIsLoading] = useState(false);
209
- *
210
- * // Fetch data when pagination or filters change
211
- * useEffect(() => {
212
- * fetchData(pagination, filters);
213
- * }, [pagination, filters]);
214
- *
215
- * <DataTable
216
- * data={tableData}
217
- * columns={columns}
218
- * isLoading={isLoading}
219
- * totalCount={1000}
220
- * defaultPageSize={20}
221
- * filtersState={filters}
222
- * onPaginationChange={setPagination}
223
- * onFiltersChange={setFilters}
224
- * pageInfo={{
225
- * hasNextPage: true,
226
- * hasPreviousPage: false,
227
- * startCursor: 'cursor-start',
228
- * endCursor: 'cursor-end'
229
- * }}
230
- * />
231
- *
232
- * @example
233
- * // With row selection and custom actions
234
- * const [selectedRows, setSelectedRows] = useState({});
235
- *
236
- * const handleRowSelection = (rowSelection) => {
237
- * setSelectedRows(rowSelection);
238
- * console.log('Selected rows:', Object.keys(rowSelection));
239
- * };
240
- *
241
- * const handleBulkAction = () => {
242
- * const selectedIds = Object.keys(selectedRows);
243
- * // Perform bulk action on selected rows
244
- * };
245
- *
246
- * <DataTable
247
- * data={tableData}
248
- * columns={columns}
249
- * onRowSelectionChange={handleRowSelection}
250
- * // Custom toolbar actions will appear when rows are selected
251
- * />
252
- *
253
- * @example
254
- * // Error handling and retry functionality
255
- * const [error, setError] = useState(null);
256
- * const [isError, setIsError] = useState(false);
257
- *
258
- * const handleRetry = () => {
259
- * setError(null);
260
- * setIsError(false);
261
- * // Retry data fetching logic
262
- * fetchData();
263
- * };
264
- *
265
- * <DataTable
266
- * data={tableData}
267
- * columns={columns}
268
- * isError={isError}
269
- * error={error}
270
- * onRetry={handleRetry}
271
- * />
272
- *
273
- * @example
274
- * // Customized table features and styling
275
- * <DataTable
276
- * data={tableData}
277
- * columns={columns}
278
- * defaultDensity="md"
279
- * showFilters={true}
280
- * showSearch={true}
281
- * showDensityToggle={true}
282
- * showFullScreenToggle={false}
283
- * locale="en-US"
284
- * mantineTableContainerProps={{
285
- * style: { maxHeight: '600px' }
286
- * }}
287
- * mantinePaperProps={{
288
- * shadow: 'md',
289
- * radius: 'md'
290
- * }}
291
- * />
292
- *
293
- * @example
294
- * // Dynamic columns with conditional rendering
295
- * const columns = useMemo(() => [
296
- * { accessorKey: 'name', header: 'Name', enableSorting: true },
297
- * { accessorKey: 'email', header: 'Email', enableColumnFilter: true },
298
- * {
299
- * accessorKey: 'status',
300
- * header: () => <Text fw="bold">Status</Text>,
301
- * size: 120,
302
- * enableSorting: false
303
- * },
304
- * {
305
- * accessorKey: 'actions',
306
- * header: 'Actions',
307
- * enableSorting: false,
308
- * enableColumnFilter: false,
309
- * Cell: ({ row }) => (
310
- * <Inline>
311
- * <Button size="xs" onClick={() => handleEdit(row.original)}>
312
- * Edit
313
- * </Button>
314
- * <Button size="xs" color="red" onClick={() => handleDelete(row.original)}>
315
- * Delete
316
- * </Button>
317
- * </Inline>
318
- * )
319
- * }
320
- * ], []);
321
- *
322
- * <DataTable
323
- * data={tableData}
324
- * columns={columns}
325
- * onSortChange={(field, direction) => {
326
- * console.log(`Sorting ${field} in ${direction} order`);
327
- * }}
328
- * />
329
- */
330
- export function DataTable<T extends MRT_RowData>({
331
- // ==================== DATA PROPS ====================
100
+ // ---- Overrides ----
101
+ /** Replaces the default empty/error fallback. */
102
+ emptyFallback?: ReactNode;
103
+ }
104
+
105
+ const getNumberOfSelectedRowsText = (rowSelection: RowSelectionState): string | undefined => {
106
+ const count = Object.keys(rowSelection).filter(key => rowSelection[key]).length;
107
+ return count > 0 ? translate('table.row.selected.count', { count }) : undefined;
108
+ };
109
+
110
+ const defaultGetRowId = <TData extends RowData>(row: TData): string =>
111
+ String((row as { id?: string | number })?.id);
112
+
113
+ export function DataTable<TData extends RowData>({
332
114
  data,
333
115
  columns,
334
- totalCount = DEFAULT_VALUES.TOTAL_COUNT,
335
-
336
- // ==================== LOADING AND ERROR STATES ====================
116
+ totalCount,
117
+ getRowId = defaultGetRowId,
337
118
  isLoading = false,
119
+ isFetching = false,
338
120
  isError = false,
339
- error,
340
121
  onRetry,
341
-
342
- // ==================== PAGINATION PROPS ====================
122
+ pagination,
343
123
  pageInfo,
344
- onPaginationChange,
345
- defaultPageSize = DEFAULT_VALUES.PAGE_SIZE,
346
-
347
- // ==================== SELECTION PROPS ====================
124
+ onPreviousPage,
125
+ onNextPage,
126
+ onPageSizeChange,
127
+ rowSelection,
348
128
  onRowSelectionChange,
349
-
350
- // ==================== UI STATE PROPS ====================
129
+ selectionActions = [],
130
+ density,
351
131
  onDensityChange,
352
- defaultDensity = DEFAULT_VALUES.DENSITY,
353
-
354
- // ==================== SORTING PROPS ====================
355
- onSortChange,
356
-
357
- // ==================== FILTER PROPS ====================
358
- filtersState = {},
359
- onFiltersChange = () => {},
360
- locale = DEFAULT_VALUES.LOCALE,
361
-
362
- // ==================== FEATURE TOGGLES ====================
363
- showFilters = FEATURE_FLAGS.SHOW_FILTERS,
364
- showSearch = FEATURE_FLAGS.SHOW_SEARCH,
365
- showDensityToggle = FEATURE_FLAGS.SHOW_DENSITY_TOGGLE,
366
- showFullScreenToggle = FEATURE_FLAGS.SHOW_FULL_SCREEN_TOGGLE,
367
-
368
- // ==================== STYLE CUSTOMIZATION ====================
369
- mantineTableContainerProps = {},
370
- mantinePaperProps = {},
371
-
372
- // ==================== DEPRECATED/UNUSED PROPS ====================
373
- resultCount = DEFAULT_VALUES.RESULT_COUNT,
374
- }: DataTableProps<T>) {
375
- // ==================== HOOK INITIALIZATION ====================
376
- /** Initialize table state management */
377
- const tableState = useTableState(defaultPageSize, defaultDensity);
378
-
379
- /** Initialize event handlers with proper memoization */
380
- const handlers = useTableHandlers(tableState, {
381
- onPaginationChange,
382
- onRowSelectionChange,
383
- onDensityChange,
384
- onSortChange,
385
- });
386
-
387
- /** Initialize render functions with all required dependencies */
388
- const renderFunctions = useTableRenderFunctions(
389
- {
390
- filtersState,
391
- locale,
392
- onFiltersChange,
393
- data,
394
- showFilters,
395
- isLoading,
396
- totalCount,
397
- pageInfo,
398
- error,
399
- onRetry,
400
- },
401
- { numberOfSelectedRows: tableState.numberOfSelectedRows },
402
- { handleClearSelection: handlers.handleClearSelection }
132
+ isFullScreen,
133
+ onFullScreenChange,
134
+ filters,
135
+ onFiltersChange,
136
+ onResetFilters,
137
+ showFilters,
138
+ onFilterToggleChange,
139
+ locale,
140
+ emptyFallback,
141
+ }: DataTableProps<TData>): ReactElement {
142
+ 'use no memo';
143
+
144
+ const columnHelper = createDataTableColumnHelper<TData>();
145
+
146
+ const tableColumns = useMemo(
147
+ () => columnHelper.columns([getSelectColumnDef(columnHelper), ...columns] as never),
148
+ // eslint-disable-next-line react-hooks/exhaustive-deps
149
+ [columns]
403
150
  );
404
151
 
405
- // ==================== TABLE CONFIGURATION ====================
406
- /**
407
- * Memoized table configuration object
408
- * Contains all options, state, and handlers for Mantine React Table
409
- */
410
- const tableConfig = useMemo(() => ({
411
- // ==================== CORE DATA AND COLUMNS ====================
412
- columns,
152
+ const table = useTable({
153
+ features: dataTableFeatures,
154
+ columns: tableColumns,
413
155
  data,
414
- /** Use the 'id' field from each row for unique identification (enables proper selection tracking) */
415
- getRowId: (row: T) => row.id as string,
416
-
417
- // ==================== FEATURE ENABLEMENT ====================
418
- /** Enable row selection with checkboxes */
419
- enableRowSelection: true,
420
- /** Allow multiple rows to be selected simultaneously */
421
- enableMultiRowSelection: true,
422
- /** Show select all checkbox in header */
423
- enableSelectAll: true,
424
- /** Enable column-specific filtering */
425
- enableColumnFilters: true,
426
- /** Enable column sorting */
427
- enableSorting: true,
428
- /** Allow users to resize columns */
429
- enableColumnResizing: true,
430
- /** Keep header visible when scrolling */
431
- enableStickyHeader: true,
432
- /** Show density toggle button */
433
- enableDensityToggle: showDensityToggle,
434
- /** Show fullscreen toggle button */
435
- enableFullScreenToggle: showFullScreenToggle,
436
- /** Enable pagination controls */
437
- enablePagination: true,
438
- /** Disable built-in row actions (we handle them manually) */
439
- enableRowActions: false,
440
- /** Disable individual column actions - we'll use a custom column visibility button */
441
- enableColumnActions: false,
442
- /** Enable column hiding feature */
443
- enableHiding: true,
444
- /** Use manual pagination (parent handles data slicing) */
445
- manualPagination: true,
446
-
447
- // ==================== DATA AND STATE ====================
448
- /** Total number of rows across all pages */
449
- rowCount: totalCount,
450
- /** Initial state with pinned actions column */
451
- initialState: {
452
- columnPinning: {
453
- right: ['actions'],
454
- },
156
+ defaultColumn: {
157
+ size: 180,
158
+ minSize: 40,
159
+ maxSize: 1000,
455
160
  },
456
- /** Current state object passed to Mantine React Table */
161
+ enableRowSelection: true,
162
+ getRowId: originalRow => getRowId(originalRow),
457
163
  state: {
458
- pagination: tableState.pagination,
459
- rowSelection: tableState.rowSelection,
460
- density: tableState.density,
461
- isLoading,
462
- showAlertBanner: tableState.showAlertBanner,
463
- },
464
-
465
- // ==================== LAYOUT CONFIGURATION ====================
466
- /** Use grid layout for better column control */
467
- layoutMode: 'grid' as const,
468
- /** Configure display columns (selection, etc.) */
469
- displayColumnDefOptions: {
470
- 'mrt-row-select': {
471
- size: 40, // Minimal width for checkbox
472
- grow: false, // Don't grow this column
473
- },
474
- },
475
- /** Enable column pinning to keep actions column fixed */
476
- enablePinning: true,
477
-
478
- // ==================== EVENT HANDLERS ====================
479
- /** Handle pagination changes (page navigation, page size changes) */
480
- onPaginationChange: handlers.handlePaginationChange,
481
- /** Handle row selection changes */
482
- onRowSelectionChange: handlers.handleRowSelectionChange,
483
- /** Handle density changes */
484
- onDensityChange: handlers.handleDensityChange,
485
- /** Handle sorting changes */
486
- onSortingChange: handlers.handleSortingChange,
487
-
488
- // ==================== RENDER FUNCTIONS ====================
489
- /** Custom top toolbar with filters and actions */
490
- renderTopToolbar: renderFunctions.renderTopToolbar,
491
- /** Custom bottom toolbar with pagination */
492
- renderBottomToolbar: renderFunctions.renderBottomToolbar,
493
- /** Custom alert banner for selection state */
494
- renderToolbarAlertBannerContent: renderFunctions.renderToolbarAlertBannerContent,
495
- /** Custom empty state with error handling */
496
- renderEmptyRowsFallback: renderFunctions.renderEmptyRowsFallback,
497
- /** Custom header cell renderer */
498
- mantineTableHeadCellProps: renderFunctions.renderTableHeadCell,
499
-
500
- // ==================== ACCESSIBILITY AND STYLING ====================
501
- /** Accessibility props for select all checkbox */
502
- mantineSelectAllCheckboxProps: {
503
- 'aria-label': 'Select all rows on this page',
164
+ rowSelection,
504
165
  },
505
- /** Accessibility props for individual row checkboxes */
506
- mantineSelectCheckboxProps: {
507
- 'aria-label': 'Select row',
166
+ onRowSelectionChange: updater => {
167
+ onRowSelectionChange(typeof updater === 'function' ? updater(rowSelection) : updater);
508
168
  },
509
- /** Table styling options */
510
- mantineTableProps: {
511
- striped: true, // Alternating row colors
512
- highlightOnHover: true, // Highlight rows on hover
513
- withColumnBorders: false, // No vertical borders between columns
514
- },
515
- /** Header row styling */
516
- mantineTableHeadRowProps: {
517
- style: {
518
- borderBottom: '2px solid var(--ad-color-border-subtle)',
519
- },
520
- },
521
- /** Body cell styling */
522
- mantineTableBodyCellProps: {
523
- style: {
524
- padding: 'var(--mantine-spacing-xs)',
525
- },
526
- },
527
- /** Alert banner styling */
528
- mantineToolbarAlertBannerProps: {
529
- color: 'blue',
530
- },
531
- /** Table container styling */
532
- mantineTableContainerProps: {
533
- style: {
534
- backgroundColor: 'var(--ad-color-bg-default)',
535
- },
536
- ...mantineTableContainerProps, // Allow prop overrides
537
- },
538
- /** Paper wrapper styling */
539
- mantinePaperProps: {
540
- style: {
541
- backgroundColor: 'var(--ad-color-bg-default)',
542
- },
543
- ...mantinePaperProps, // Allow prop overrides
544
- },
545
- }), [
546
- // ==================== MEMOIZATION DEPENDENCIES ====================
547
- // Core data dependencies
548
- columns,
549
- data,
550
- showDensityToggle,
551
- showFullScreenToggle,
552
- totalCount,
553
- isLoading,
554
- // State dependencies
555
- tableState.pagination,
556
- tableState.rowSelection,
557
- tableState.density,
558
- tableState.showAlertBanner,
559
- // Handler dependencies
560
- handlers.handlePaginationChange,
561
- handlers.handleRowSelectionChange,
562
- handlers.handleDensityChange,
563
- handlers.handleSortingChange,
564
- // Render function dependencies
565
- renderFunctions.renderTopToolbar,
566
- renderFunctions.renderBottomToolbar,
567
- renderFunctions.renderToolbarAlertBannerContent,
568
- renderFunctions.renderEmptyRowsFallback,
569
- renderFunctions.renderTableHeadCell,
570
- // Style customization dependencies
571
- mantineTableContainerProps,
572
- mantinePaperProps,
573
- ]);
169
+ });
170
+
171
+ const selectedCount = Object.values(rowSelection).filter(Boolean).length;
172
+ const isTableLoading = isFetching || isLoading;
173
+ const selectedRowsText = getNumberOfSelectedRowsText(rowSelection);
574
174
 
575
- // ==================== COMPONENT INITIALIZATION ====================
576
- /** Initialize the Mantine React Table instance with our configuration */
577
- const table = useMantineReactTable(tableConfig);
175
+ const fallback = emptyFallback ?? (
176
+ <ErrorOverlay
177
+ title={
178
+ isError
179
+ ? translate('table.overlay.error.state.title')
180
+ : translate('table.overlay.empty.state.title')
181
+ }
182
+ description={
183
+ isError
184
+ ? translate('table.overlay.error.state.description')
185
+ : translate('table.overlay.empty.state.description')
186
+ }
187
+ SVGIcon={isError ? undefined : <RiSearchLine />}
188
+ my="xl"
189
+ // Without onRetry there is nothing that can recover a load failure, so show no action rather than one that only clears filters.
190
+ actions={
191
+ isError && !onRetry
192
+ ? undefined
193
+ : [
194
+ {
195
+ label: isError
196
+ ? translate('table.overlay.error.state.button')
197
+ : translate('table.overlay.empty.state.button'),
198
+ onClick: isError ? onRetry : onResetFilters,
199
+ variant: 'default',
200
+ },
201
+ ]
202
+ }
203
+ />
204
+ );
578
205
 
579
- // ==================== RENDER ====================
580
- /** Render the table component */
581
- return <MantineReactTable table={table} />;
582
- }
206
+ return (
207
+ <DataTableShell
208
+ isFullScreen={isFullScreen}
209
+ isLoading={isTableLoading}
210
+ topToolbar={
211
+ <CustomTopToolbar
212
+ resultCount={totalCount}
213
+ filtersState={filters}
214
+ locale={locale}
215
+ onChange={(partial): void => onFiltersChange({ ...filters, ...partial })} // DS-ADAPT: toolbar emits partial updates; merge so controlled state keeps other fields
216
+ isLoading={isTableLoading}
217
+ showFilters={showFilters}
218
+ onFilterToggleChange={onFilterToggleChange}
219
+ fullscreenControl={
220
+ <ToggleFullScreenButton isFullScreen={isFullScreen} onChange={onFullScreenChange} />
221
+ }
222
+ densityControl={<ToggleDensityButton density={density} onChange={onDensityChange} />}
223
+ alertBanner={
224
+ <ToolbarAlertBanner selectedCount={selectedCount}>
225
+ <CustomToolbarAlertBannerContent
226
+ resetRowSelection={(): void => onRowSelectionChange({})}
227
+ numberOfSelectedRowsText={selectedRowsText}
228
+ actions={selectionActions.map(action => ({
229
+ label: action.label,
230
+ onClick: action.onClick,
231
+ SVGIcon: action.SVGIcon ?? <RiDeleteBin5Line size={14} />,
232
+ }))}
233
+ />
234
+ </ToolbarAlertBanner>
235
+ }
236
+ />
237
+ }
238
+ bottomToolbar={
239
+ <CustomBottomToolbar
240
+ isDisabled={isError}
241
+ paginationState={pagination}
242
+ hasPreviousPage={pageInfo?.hasPreviousPage}
243
+ hasNextPage={pageInfo?.hasNextPage}
244
+ totalNumOfRows={totalCount}
245
+ onNextPage={onNextPage}
246
+ onPreviousPage={onPreviousPage}
247
+ onPageSizeChange={onPageSizeChange}
248
+ isFetching={isFetching}
249
+ numberOfSelectedRowsText={selectedRowsText}
250
+ />
251
+ }
252
+ >
253
+ <RowSelectionContext.Provider value={rowSelection}>
254
+ <DataTableGrid
255
+ table={table}
256
+ density={density}
257
+ rowSelection={rowSelection}
258
+ isLoading={isTableLoading}
259
+ pageSize={pagination.pageSize}
260
+ emptyFallback={fallback}
261
+ />
262
+ </RowSelectionContext.Provider>
263
+ </DataTableShell>
264
+ );
265
+ }