@ackplus/react-tanstack-data-table 1.1.12 → 1.1.13

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 (51) hide show
  1. package/README.md +143 -11
  2. package/dist/lib/components/droupdown/menu-dropdown.d.ts.map +1 -1
  3. package/dist/lib/components/droupdown/menu-dropdown.js +8 -1
  4. package/dist/lib/components/filters/filter-value-input.js +2 -2
  5. package/dist/lib/components/pagination/data-table-pagination.d.ts.map +1 -1
  6. package/dist/lib/components/pagination/data-table-pagination.js +10 -1
  7. package/dist/lib/components/toolbar/table-export-control.d.ts.map +1 -1
  8. package/dist/lib/components/toolbar/table-export-control.js +46 -12
  9. package/dist/lib/contexts/data-table-context.d.ts +7 -10
  10. package/dist/lib/contexts/data-table-context.d.ts.map +1 -1
  11. package/dist/lib/contexts/data-table-context.js +5 -1
  12. package/dist/lib/data-table.d.ts.map +1 -1
  13. package/dist/lib/data-table.js +561 -230
  14. package/dist/lib/features/column-filter.feature.js +38 -21
  15. package/dist/lib/features/selection.feature.d.ts.map +1 -1
  16. package/dist/lib/features/selection.feature.js +11 -3
  17. package/dist/lib/types/column.types.d.ts +19 -0
  18. package/dist/lib/types/column.types.d.ts.map +1 -1
  19. package/dist/lib/types/data-table-api.d.ts +24 -18
  20. package/dist/lib/types/data-table-api.d.ts.map +1 -1
  21. package/dist/lib/types/data-table.types.d.ts +36 -10
  22. package/dist/lib/types/data-table.types.d.ts.map +1 -1
  23. package/dist/lib/types/export.types.d.ts +57 -13
  24. package/dist/lib/types/export.types.d.ts.map +1 -1
  25. package/dist/lib/types/slots.types.d.ts +3 -1
  26. package/dist/lib/types/slots.types.d.ts.map +1 -1
  27. package/dist/lib/types/table.types.d.ts +1 -3
  28. package/dist/lib/types/table.types.d.ts.map +1 -1
  29. package/dist/lib/utils/debounced-fetch.utils.d.ts +8 -4
  30. package/dist/lib/utils/debounced-fetch.utils.d.ts.map +1 -1
  31. package/dist/lib/utils/debounced-fetch.utils.js +63 -14
  32. package/dist/lib/utils/export-utils.d.ts +14 -4
  33. package/dist/lib/utils/export-utils.d.ts.map +1 -1
  34. package/dist/lib/utils/export-utils.js +362 -66
  35. package/package.json +4 -2
  36. package/src/lib/components/droupdown/menu-dropdown.tsx +9 -3
  37. package/src/lib/components/filters/filter-value-input.tsx +2 -2
  38. package/src/lib/components/pagination/data-table-pagination.tsx +14 -2
  39. package/src/lib/components/toolbar/table-export-control.tsx +65 -9
  40. package/src/lib/contexts/data-table-context.tsx +16 -2
  41. package/src/lib/data-table.tsx +703 -222
  42. package/src/lib/features/column-filter.feature.ts +40 -19
  43. package/src/lib/features/selection.feature.ts +11 -5
  44. package/src/lib/types/column.types.ts +20 -1
  45. package/src/lib/types/data-table-api.ts +33 -15
  46. package/src/lib/types/data-table.types.ts +58 -3
  47. package/src/lib/types/export.types.ts +79 -10
  48. package/src/lib/types/slots.types.ts +3 -1
  49. package/src/lib/types/table.types.ts +1 -3
  50. package/src/lib/utils/debounced-fetch.utils.ts +90 -18
  51. package/src/lib/utils/export-utils.ts +496 -69
@@ -10,6 +10,8 @@ import {
10
10
  Box,
11
11
  IconButtonProps,
12
12
  SxProps,
13
+ Divider,
14
+ LinearProgress,
13
15
  } from '@mui/material';
14
16
 
15
17
  import { MenuDropdown } from '../droupdown/menu-dropdown';
@@ -46,6 +48,9 @@ export function TableExportControl(props: TableExportControlProps = {}) {
46
48
  slots,
47
49
  slotProps,
48
50
  isExporting,
51
+ exportPhase,
52
+ exportProgress,
53
+ onCancelExport,
49
54
  // Export callbacks from context (DataTable props)
50
55
  exportFilename: contextExportFilename,
51
56
  } = useDataTableContext();
@@ -80,11 +85,18 @@ export function TableExportControl(props: TableExportControlProps = {}) {
80
85
  }
81
86
  };
82
87
 
88
+ const handleCancelExport = () => {
89
+ if (onCancelExport) {
90
+ onCancelExport();
91
+ return;
92
+ }
93
+ apiRef?.current?.export.cancelExport();
94
+ };
95
+
83
96
  // Merge all props for maximum flexibility
84
97
  const mergedIconButtonProps = mergeSlotProps(
85
98
  {
86
99
  size: 'small',
87
- disabled: isExporting,
88
100
  sx: { flexShrink: 0 },
89
101
  },
90
102
  exportIconSlotProps,
@@ -98,6 +110,25 @@ export function TableExportControl(props: TableExportControlProps = {}) {
98
110
  menuItemProps || {}
99
111
  );
100
112
 
113
+ const progressPercentage = typeof exportProgress?.percentage === 'number'
114
+ ? Math.max(0, Math.min(100, exportProgress.percentage))
115
+ : undefined;
116
+
117
+ const getPhaseLabel = () => {
118
+ switch (exportPhase) {
119
+ case 'fetching':
120
+ return 'Fetching rows from server...';
121
+ case 'processing':
122
+ return 'Preparing export file...';
123
+ case 'downloading':
124
+ return 'Downloading file...';
125
+ case 'starting':
126
+ return 'Starting export...';
127
+ default:
128
+ return 'Export in progress...';
129
+ }
130
+ };
131
+
101
132
  return (
102
133
  <MenuDropdown
103
134
  anchor={(
@@ -162,15 +193,40 @@ export function TableExportControl(props: TableExportControlProps = {}) {
162
193
  </MenuItem>
163
194
 
164
195
  {isExporting && (
165
- <Box sx={{ p: 2, pt: 1 }}>
166
- <Typography
167
- variant="caption"
168
- color="text.secondary"
169
- sx={{ display: 'block', textAlign: 'center' }}
196
+ <>
197
+ <Box sx={{ px: 2, pb: 1 }}>
198
+ <Typography variant="caption" color="text.secondary" sx={{ display: 'block', mb: 0.75 }}>
199
+ {getPhaseLabel()}
200
+ </Typography>
201
+ <LinearProgress
202
+ variant={progressPercentage !== undefined ? 'determinate' : 'indeterminate'}
203
+ value={progressPercentage !== undefined ? progressPercentage : 0}
204
+ />
205
+ {(exportProgress?.processedRows !== undefined || exportProgress?.totalRows !== undefined) && (
206
+ <Typography variant="caption" color="text.secondary" sx={{ display: 'block', mt: 0.75 }}>
207
+ {`${exportProgress?.processedRows ?? 0}${exportProgress?.totalRows !== undefined ? ` / ${exportProgress.totalRows}` : ''}${progressPercentage !== undefined ? ` (${progressPercentage}%)` : ''}`}
208
+ </Typography>
209
+ )}
210
+ </Box>
211
+ <Divider sx={{ my: 1 }} />
212
+ <MenuItem
213
+ onClick={() => {
214
+ handleCancelExport();
215
+ handleClose();
216
+ }}
217
+ {...mergedMenuItemProps}
170
218
  >
171
- Export in progress...
172
- </Typography>
173
- </Box>
219
+ <ListItemText
220
+ primary="Cancel Export"
221
+ secondary="Stop current export job"
222
+ slotProps={{
223
+ primary: {
224
+ color: 'error.main',
225
+ },
226
+ }}
227
+ />
228
+ </MenuItem>
229
+ </>
174
230
  )}
175
231
  </Box>
176
232
  )}
@@ -2,7 +2,9 @@ import { Table } from '@tanstack/react-table';
2
2
  import React, { createContext, useContext, ReactNode, useMemo, RefObject, ReactElement } from 'react';
3
3
 
4
4
  import { ColumnFilterState, TableSize } from '../types';
5
+ import { SelectionState } from '../features';
5
6
  import { DataTableApi } from '../types/data-table-api';
7
+ import { ExportPhase, ExportProgressPayload, ServerExportResult } from '../types/export.types';
6
8
 
7
9
 
8
10
  /**
@@ -22,14 +24,20 @@ interface DataTableContextValue<T = any> {
22
24
  // Export state - managed by the DataTable component
23
25
  isExporting?: boolean;
24
26
  exportController?: AbortController | null;
27
+ exportPhase?: ExportPhase | null;
28
+ exportProgress?: ExportProgressPayload;
25
29
  onCancelExport?: () => void;
26
30
 
27
31
  // Export callbacks - passed from DataTable props
28
32
  exportFilename?: string;
29
- onExportProgress?: (progress: { processedRows?: number; totalRows?: number; percentage?: number }) => void;
33
+ onExportProgress?: (progress: ExportProgressPayload) => void;
30
34
  onExportComplete?: (result: { success: boolean; filename: string; totalRows: number }) => void;
31
35
  onExportError?: (error: { message: string; code: string }) => void;
32
- onServerExport?: (filters?: Partial<any>) => Promise<{ data: any[]; total: number }>;
36
+ onServerExport?: (
37
+ filters?: Partial<any>,
38
+ selection?: SelectionState,
39
+ signal?: AbortSignal
40
+ ) => Promise<ServerExportResult<any>>;
33
41
  }
34
42
 
35
43
  const DataTableContext = createContext<DataTableContextValue | null>(null);
@@ -51,6 +59,8 @@ export function DataTableProvider<T = any>({
51
59
  slotProps = {},
52
60
  isExporting,
53
61
  exportController,
62
+ exportPhase,
63
+ exportProgress,
54
64
  onCancelExport,
55
65
  exportFilename,
56
66
  onExportProgress,
@@ -70,6 +80,8 @@ export function DataTableProvider<T = any>({
70
80
  slotProps,
71
81
  isExporting,
72
82
  exportController,
83
+ exportPhase,
84
+ exportProgress,
73
85
  onCancelExport,
74
86
  exportFilename,
75
87
  onExportProgress,
@@ -88,6 +100,8 @@ export function DataTableProvider<T = any>({
88
100
  slotProps,
89
101
  isExporting,
90
102
  exportController,
103
+ exportPhase,
104
+ exportProgress,
91
105
  onCancelExport,
92
106
  exportFilename,
93
107
  onExportProgress,