@jmruthers/pace-core 0.5.75 → 0.5.76

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 (226) hide show
  1. package/dist/{DataTable-HWZQGASI.js → DataTable-4GAVPIEG.js} +48 -30
  2. package/dist/{PublicLoadingSpinner-BKNBT6b6.d.ts → PublicLoadingSpinner-BiNER8F5.d.ts} +28 -17
  3. package/dist/{chunk-33PHABLB.js → chunk-AFGTSUAD.js} +10 -127
  4. package/dist/chunk-AFGTSUAD.js.map +1 -0
  5. package/dist/{chunk-2DFZ432F.js → chunk-K34IM5CT.js} +3 -5
  6. package/dist/{chunk-2DFZ432F.js.map → chunk-K34IM5CT.js.map} +1 -1
  7. package/dist/{chunk-2CHATWBF.js → chunk-KHJS6VIA.js} +199 -35
  8. package/dist/chunk-KHJS6VIA.js.map +1 -0
  9. package/dist/{chunk-ZTT2AXMX.js → chunk-KK73ZB4E.js} +2 -2
  10. package/dist/{chunk-CY3AHGO4.js → chunk-M5IWZRBT.js} +1750 -2815
  11. package/dist/chunk-M5IWZRBT.js.map +1 -0
  12. package/dist/{chunk-DAXLNIDY.js → chunk-Y6TXWPJO.js} +6 -4
  13. package/dist/{chunk-DAXLNIDY.js.map → chunk-Y6TXWPJO.js.map} +1 -1
  14. package/dist/{chunk-YNUBMSMV.js → chunk-YCKPEMJA.js} +186 -263
  15. package/dist/chunk-YCKPEMJA.js.map +1 -0
  16. package/dist/components.d.ts +1 -1
  17. package/dist/components.js +7 -6
  18. package/dist/components.js.map +1 -1
  19. package/dist/hooks.d.ts +17 -40
  20. package/dist/hooks.js +6 -6
  21. package/dist/index.d.ts +3 -3
  22. package/dist/index.js +12 -10
  23. package/dist/index.js.map +1 -1
  24. package/dist/rbac/index.d.ts +54 -1
  25. package/dist/rbac/index.js +5 -4
  26. package/dist/utils.js +1 -1
  27. package/docs/TERMINOLOGY.md +231 -0
  28. package/docs/api/classes/ColumnFactory.md +1 -1
  29. package/docs/api/classes/ErrorBoundary.md +1 -1
  30. package/docs/api/classes/InvalidScopeError.md +1 -1
  31. package/docs/api/classes/MissingUserContextError.md +1 -1
  32. package/docs/api/classes/OrganisationContextRequiredError.md +1 -1
  33. package/docs/api/classes/PermissionDeniedError.md +1 -1
  34. package/docs/api/classes/PublicErrorBoundary.md +1 -1
  35. package/docs/api/classes/RBACAuditManager.md +1 -1
  36. package/docs/api/classes/RBACCache.md +1 -1
  37. package/docs/api/classes/RBACEngine.md +1 -1
  38. package/docs/api/classes/RBACError.md +1 -1
  39. package/docs/api/classes/RBACNotInitializedError.md +1 -1
  40. package/docs/api/classes/SecureSupabaseClient.md +1 -1
  41. package/docs/api/classes/StorageUtils.md +1 -1
  42. package/docs/api/enums/FileCategory.md +1 -1
  43. package/docs/api/interfaces/AggregateConfig.md +1 -1
  44. package/docs/api/interfaces/ButtonProps.md +1 -1
  45. package/docs/api/interfaces/CardProps.md +1 -1
  46. package/docs/api/interfaces/ColorPalette.md +1 -1
  47. package/docs/api/interfaces/ColorShade.md +1 -1
  48. package/docs/api/interfaces/DataAccessRecord.md +1 -1
  49. package/docs/api/interfaces/DataTableAction.md +1 -1
  50. package/docs/api/interfaces/DataTableColumn.md +1 -1
  51. package/docs/api/interfaces/DataTableProps.md +1 -1
  52. package/docs/api/interfaces/DataTableToolbarButton.md +1 -1
  53. package/docs/api/interfaces/EmptyStateConfig.md +1 -1
  54. package/docs/api/interfaces/EnhancedNavigationMenuProps.md +1 -1
  55. package/docs/api/interfaces/EventLogoProps.md +1 -1
  56. package/docs/api/interfaces/FileDisplayProps.md +1 -1
  57. package/docs/api/interfaces/FileMetadata.md +1 -1
  58. package/docs/api/interfaces/FileReference.md +1 -1
  59. package/docs/api/interfaces/FileSizeLimits.md +1 -1
  60. package/docs/api/interfaces/FileUploadOptions.md +1 -1
  61. package/docs/api/interfaces/FileUploadProps.md +1 -1
  62. package/docs/api/interfaces/FooterProps.md +1 -1
  63. package/docs/api/interfaces/InactivityWarningModalProps.md +1 -1
  64. package/docs/api/interfaces/InputProps.md +1 -1
  65. package/docs/api/interfaces/LabelProps.md +1 -1
  66. package/docs/api/interfaces/LoginFormProps.md +1 -1
  67. package/docs/api/interfaces/NavigationAccessRecord.md +1 -1
  68. package/docs/api/interfaces/NavigationContextType.md +1 -1
  69. package/docs/api/interfaces/NavigationGuardProps.md +1 -1
  70. package/docs/api/interfaces/NavigationItem.md +1 -1
  71. package/docs/api/interfaces/NavigationMenuProps.md +1 -1
  72. package/docs/api/interfaces/NavigationProviderProps.md +1 -1
  73. package/docs/api/interfaces/Organisation.md +1 -1
  74. package/docs/api/interfaces/OrganisationContextType.md +1 -1
  75. package/docs/api/interfaces/OrganisationMembership.md +1 -1
  76. package/docs/api/interfaces/OrganisationProviderProps.md +1 -1
  77. package/docs/api/interfaces/OrganisationSecurityError.md +1 -1
  78. package/docs/api/interfaces/PaceAppLayoutProps.md +1 -1
  79. package/docs/api/interfaces/PaceLoginPageProps.md +1 -1
  80. package/docs/api/interfaces/PageAccessRecord.md +1 -1
  81. package/docs/api/interfaces/PagePermissionContextType.md +1 -1
  82. package/docs/api/interfaces/PagePermissionGuardProps.md +1 -1
  83. package/docs/api/interfaces/PagePermissionProviderProps.md +1 -1
  84. package/docs/api/interfaces/PaletteData.md +1 -1
  85. package/docs/api/interfaces/PermissionEnforcerProps.md +1 -1
  86. package/docs/api/interfaces/PublicErrorBoundaryProps.md +1 -1
  87. package/docs/api/interfaces/PublicErrorBoundaryState.md +1 -1
  88. package/docs/api/interfaces/PublicLoadingSpinnerProps.md +1 -1
  89. package/docs/api/interfaces/PublicPageFooterProps.md +1 -1
  90. package/docs/api/interfaces/PublicPageHeaderProps.md +1 -1
  91. package/docs/api/interfaces/PublicPageLayoutProps.md +1 -1
  92. package/docs/api/interfaces/RBACConfig.md +1 -1
  93. package/docs/api/interfaces/RBACContextType.md +1 -1
  94. package/docs/api/interfaces/RBACLogger.md +1 -1
  95. package/docs/api/interfaces/RBACProviderProps.md +1 -1
  96. package/docs/api/interfaces/RoleBasedRouterContextType.md +1 -1
  97. package/docs/api/interfaces/RoleBasedRouterProps.md +1 -1
  98. package/docs/api/interfaces/RouteAccessRecord.md +1 -1
  99. package/docs/api/interfaces/RouteConfig.md +1 -1
  100. package/docs/api/interfaces/SecureDataContextType.md +1 -1
  101. package/docs/api/interfaces/SecureDataProviderProps.md +1 -1
  102. package/docs/api/interfaces/StorageConfig.md +1 -1
  103. package/docs/api/interfaces/StorageFileInfo.md +1 -1
  104. package/docs/api/interfaces/StorageFileMetadata.md +1 -1
  105. package/docs/api/interfaces/StorageListOptions.md +1 -1
  106. package/docs/api/interfaces/StorageListResult.md +1 -1
  107. package/docs/api/interfaces/StorageUploadOptions.md +1 -1
  108. package/docs/api/interfaces/StorageUploadResult.md +1 -1
  109. package/docs/api/interfaces/StorageUrlOptions.md +1 -1
  110. package/docs/api/interfaces/StyleImport.md +1 -1
  111. package/docs/api/interfaces/SwitchProps.md +1 -1
  112. package/docs/api/interfaces/ToastActionElement.md +1 -1
  113. package/docs/api/interfaces/ToastProps.md +1 -1
  114. package/docs/api/interfaces/UnifiedAuthContextType.md +1 -1
  115. package/docs/api/interfaces/UnifiedAuthProviderProps.md +1 -1
  116. package/docs/api/interfaces/UseInactivityTrackerOptions.md +1 -1
  117. package/docs/api/interfaces/UseInactivityTrackerReturn.md +1 -1
  118. package/docs/api/interfaces/UsePublicEventLogoOptions.md +1 -1
  119. package/docs/api/interfaces/UsePublicEventLogoReturn.md +1 -1
  120. package/docs/api/interfaces/UsePublicEventOptions.md +1 -1
  121. package/docs/api/interfaces/UsePublicEventReturn.md +1 -1
  122. package/docs/api/interfaces/UsePublicRouteParamsReturn.md +1 -1
  123. package/docs/api/interfaces/UseResolvedScopeOptions.md +47 -0
  124. package/docs/api/interfaces/UseResolvedScopeReturn.md +47 -0
  125. package/docs/api/interfaces/UserEventAccess.md +1 -1
  126. package/docs/api/interfaces/UserMenuProps.md +1 -1
  127. package/docs/api/interfaces/UserProfile.md +1 -1
  128. package/docs/api/modules.md +57 -11
  129. package/docs/api-reference/providers.md +26 -7
  130. package/docs/best-practices/README.md +20 -0
  131. package/docs/best-practices/accessibility.md +566 -0
  132. package/docs/best-practices/performance-expansion.md +473 -0
  133. package/docs/core-concepts/authentication.md +15 -7
  134. package/docs/documentation-index.md +1 -1
  135. package/docs/documentation-templates.md +539 -0
  136. package/docs/getting-started/quick-start.md +16 -66
  137. package/docs/implementation-guides/component-styling.md +410 -0
  138. package/docs/implementation-guides/data-tables.md +1 -1
  139. package/docs/style-guide.md +39 -0
  140. package/package.json +1 -1
  141. package/src/__tests__/TEST_GUIDE_CURSOR.md +290 -0
  142. package/src/__tests__/helpers/supabaseMock.ts +48 -2
  143. package/src/components/DataTable/__tests__/DataTable.default-state.test.tsx +17 -6
  144. package/src/components/DataTable/__tests__/DataTableCore.test.tsx +73 -9
  145. package/src/components/DataTable/components/DataTableCore.tsx +280 -475
  146. package/src/components/DataTable/components/UnifiedTableBody.tsx +120 -153
  147. package/src/components/DataTable/components/index.ts +1 -2
  148. package/src/components/DataTable/context/__tests__/DataTableContext.test.tsx +208 -275
  149. package/src/components/DataTable/core/index.ts +1 -8
  150. package/src/components/DataTable/hooks/__tests__/useColumnOrderPersistence.test.ts +525 -0
  151. package/src/components/DataTable/hooks/__tests__/useColumnReordering.test.ts +570 -0
  152. package/src/components/DataTable/hooks/__tests__/useHierarchicalState.test.ts +214 -0
  153. package/src/components/DataTable/hooks/__tests__/useTableColumns.test.ts +224 -0
  154. package/src/components/DataTable/hooks/index.ts +6 -0
  155. package/src/components/DataTable/hooks/useColumnReordering.ts +1 -0
  156. package/src/components/DataTable/hooks/useDataTablePermissions.ts +149 -0
  157. package/src/components/DataTable/hooks/useDataTableState.ts +12 -6
  158. package/src/components/DataTable/hooks/useHierarchicalState.ts +26 -8
  159. package/src/components/DataTable/hooks/useTableColumns.ts +153 -0
  160. package/src/components/DataTable/index.ts +1 -9
  161. package/src/components/DataTable/utils/__tests__/COVERAGE_NOTE.md +89 -0
  162. package/src/components/DataTable/utils/__tests__/exportUtils.test.ts +3 -6
  163. package/src/components/DataTable/utils/__tests__/flexibleImport.test.ts +462 -0
  164. package/src/components/DataTable/utils/__tests__/hierarchicalSorting.test.ts +247 -0
  165. package/src/components/DataTable/utils/__tests__/hierarchicalUtils.test.ts +8 -6
  166. package/src/components/DataTable/utils/__tests__/performanceUtils.test.ts +466 -0
  167. package/src/components/DataTable/utils/__tests__/rowUtils.test.ts +265 -0
  168. package/src/components/DataTable/utils/errorHandling.ts +52 -460
  169. package/src/components/DataTable/utils/exportUtils.ts +46 -15
  170. package/src/components/DataTable/utils/hierarchicalSorting.ts +50 -3
  171. package/src/components/DataTable/utils/hierarchicalUtils.ts +167 -34
  172. package/src/components/DataTable/utils/index.ts +5 -0
  173. package/src/components/DataTable/utils/rowUtils.ts +68 -0
  174. package/src/components/EventSelector/EventSelector.test.tsx +672 -0
  175. package/src/components/Label/__tests__/Label.test.tsx +434 -0
  176. package/src/components/PublicLayout/__tests__/PublicPageContextChecker.test.tsx +190 -0
  177. package/src/components/PublicLayout/__tests__/PublicPageDebugger.test.tsx +185 -0
  178. package/src/components/PublicLayout/__tests__/PublicPageProvider.test.tsx +313 -0
  179. package/src/components/Select/Select.test.tsx +143 -120
  180. package/src/components/Select/Select.tsx +47 -212
  181. package/src/components/Select/hooks.ts +36 -1
  182. package/src/components/Select/index.ts +2 -1
  183. package/src/hooks/services/__tests__/useServiceHooks.test.tsx +137 -0
  184. package/src/hooks/useSecureDataAccess.test.ts +32 -29
  185. package/src/providers/__tests__/ProviderLifecycle.test.tsx +341 -0
  186. package/src/rbac/hooks/__tests__/usePermissions.integration.test.ts +437 -0
  187. package/src/rbac/hooks/index.ts +2 -0
  188. package/src/rbac/hooks/useResolvedScope.ts +232 -0
  189. package/src/services/__tests__/InactivityService.lifecycle.test.ts +411 -0
  190. package/src/services/__tests__/OrganisationService.pagination.test.ts +375 -0
  191. package/src/types/__tests__/README.md +114 -0
  192. package/src/types/__tests__/validation.test.ts +731 -0
  193. package/src/utils/__tests__/file-reference.test.ts +383 -0
  194. package/src/utils/__tests__/performanceBenchmark.test.ts +175 -0
  195. package/src/utils/appNameResolver.test.ts +54 -0
  196. package/src/validation/__tests__/csrf.unit.test.ts +63 -0
  197. package/src/validation/__tests__/passwordSchema.unit.test.ts +105 -0
  198. package/dist/chunk-2CHATWBF.js.map +0 -1
  199. package/dist/chunk-33PHABLB.js.map +0 -1
  200. package/dist/chunk-CY3AHGO4.js.map +0 -1
  201. package/dist/chunk-TYHR5X4W.js +0 -33
  202. package/dist/chunk-TYHR5X4W.js.map +0 -1
  203. package/dist/chunk-YNUBMSMV.js.map +0 -1
  204. package/dist/eventContext-BBA42P6G.js +0 -14
  205. package/dist/eventContext-BBA42P6G.js.map +0 -1
  206. package/docs/documentation-style-checklist.md +0 -294
  207. package/src/components/DataTable/components/DataTableBody.tsx +0 -488
  208. package/src/components/DataTable/components/DraggableColumnHeader.tsx +0 -144
  209. package/src/components/DataTable/components/VirtualizedDataTable.tsx +0 -515
  210. package/src/components/DataTable/core/ActionManager.ts +0 -235
  211. package/src/components/DataTable/core/ColumnManager.ts +0 -215
  212. package/src/components/DataTable/core/DataManager.ts +0 -188
  213. package/src/components/DataTable/core/DataTableContext.tsx +0 -181
  214. package/src/components/DataTable/core/LocalDataAdapter.ts +0 -264
  215. package/src/components/DataTable/core/PluginRegistry.ts +0 -229
  216. package/src/components/DataTable/core/StateManager.ts +0 -311
  217. package/src/components/DataTable/core/__tests__/ActionManager.test.ts +0 -634
  218. package/src/components/DataTable/core/__tests__/ColumnManager.test.ts +0 -193
  219. package/src/components/DataTable/core/__tests__/DataManager.test.ts +0 -519
  220. package/src/components/DataTable/core/__tests__/StateManager.test.ts +0 -714
  221. package/src/components/DataTable/core/interfaces.ts +0 -338
  222. package/src/components/DataTable/utils/debugTools.ts +0 -583
  223. package/src/components/Select/Select.bug-test.tsx +0 -69
  224. package/src/components/Select/Select.refactored.tsx +0 -497
  225. /package/dist/{DataTable-HWZQGASI.js.map → DataTable-4GAVPIEG.js.map} +0 -0
  226. /package/dist/{chunk-ZTT2AXMX.js.map → chunk-KK73ZB4E.js.map} +0 -0
@@ -1,488 +0,0 @@
1
- /**
2
- * @file DataTable Body Component
3
- * @package @jmruthers/pace-core
4
- * @module Components/DataTable/Components
5
- * @since 0.3.0
6
- *
7
- * The DataTable body component handles the main table content rendering including:
8
- * - Table headers with sorting indicators
9
- * - Data rows with cell rendering
10
- * - Inline editing capabilities
11
- * - Row creation interface
12
- * - Grouped rows with expansion/collapse
13
- * - Aggregate value display
14
- * - Empty state handling
15
- *
16
- * Features:
17
- * - Virtual scrolling support for large datasets
18
- * - Inline editing with input validation
19
- * - Row grouping with collapsible sections
20
- * - Custom cell renderers
21
- * - Aggregate calculations and display
22
- * - Loading and empty states
23
- * - Keyboard navigation
24
- * - Accessibility support
25
- *
26
- * @example
27
- * ```tsx
28
- * <DataTableBody
29
- * table={tableInstance}
30
- * isCreating={false}
31
- * creationData={{}}
32
- * onCreationDataChange={(data) => setCreationData(data)}
33
- * onSaveCreation={() => handleSave()}
34
- * onCancelCreation={() => handleCancel()}
35
- * editingRowId={null}
36
- * editingData={{}}
37
- * onEditingDataChange={(data) => setEditingData(data)}
38
- * grouping={['category']}
39
- * aggregates={[{ field: 'price', function: 'avg', label: 'Avg Price' }]}
40
- * getRowId={(row) => row.id}
41
- * emptyState={{ title: 'No data found' }}
42
- * />
43
- * ```
44
- *
45
- * @accessibility
46
- * - Proper table semantics with thead/tbody
47
- * - ARIA labels for interactive elements
48
- * - Keyboard navigation support
49
- * - Screen reader friendly
50
- * - Focus management during editing
51
- *
52
- * @performance
53
- * - Efficient re-rendering with React.memo
54
- * - Virtual scrolling for large datasets
55
- * - Optimized cell rendering
56
- * - Debounced input handling
57
- */
58
-
59
- import React from 'react';
60
- import { type Table, flexRender } from '@tanstack/react-table';
61
- import { Button } from '../../Button/Button';
62
- import { ChevronUp, ChevronDown, ChevronRight, ChevronsUpDown } from 'lucide-react';
63
- import { EmptyState } from './EmptyState';
64
- import { Input } from '../../Input/Input';
65
- import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../../Select/Select';
66
- import type { AggregateConfig } from '../types';
67
-
68
- /**
69
- * Props for the DataTable body component
70
- * @template TData - The type of data records in the table
71
- */
72
- interface DataTableBodyProps<TData extends Record<string, any>> {
73
- /** TanStack table instance */
74
- table: Table<TData>;
75
- /** Whether a new row is being created */
76
- isCreating: boolean;
77
- /** Data for the row being created */
78
- creationData: Record<string, any>;
79
- /** Callback when creation data changes */
80
- onCreationDataChange: (data: Record<string, any>) => void;
81
- /** Callback to save the new row */
82
- onSaveCreation: () => void;
83
- /** Callback to cancel row creation */
84
- onCancelCreation: () => void;
85
- /** ID of the row currently being edited */
86
- editingRowId: string | null;
87
- /** Data for the row being edited */
88
- editingData: Record<string, any>;
89
- /** Callback when editing data changes */
90
- onEditingDataChange: (data: Record<string, any>) => void;
91
- /** Current grouping configuration */
92
- grouping: string[];
93
- /** Aggregate configurations for grouped data */
94
- aggregates: AggregateConfig[];
95
- /** Function to get unique row ID */
96
- getRowId?: (row: TData, index: number) => string;
97
- /** Custom empty state configuration */
98
- emptyState?: {
99
- /** Empty state title */
100
- title?: string;
101
- /** Empty state description */
102
- description?: string;
103
- /** Empty state icon component */
104
- icon?: React.ComponentType<{ className?: string }>;
105
- /** Optional action button */
106
- action?: {
107
- /** Button label */
108
- label: string;
109
- /** Button click handler */
110
- onClick: () => void;
111
- };
112
- };
113
- /** Whether the table is currently filtered */
114
- isFiltered?: boolean;
115
- /** Callback to clear all filters */
116
- onClearFilters?: () => void;
117
- /** Hierarchical configuration */
118
- hierarchical?: {
119
- enabled: boolean;
120
- expandAll: () => void;
121
- collapseAll: () => void;
122
- isAllExpanded: boolean;
123
- hasAnyChildren: boolean;
124
- };
125
- }
126
-
127
- // Helper function to render the appropriate input type based on column configuration
128
- const renderEditField = (
129
- column: any,
130
- value: any,
131
- onChange: (value: any) => void,
132
- editingData: Record<string, any> = {},
133
- placeholder?: string
134
- ) => {
135
- const columnDef = column.columnDef;
136
-
137
- // Check if column is editable (default: true)
138
- if (columnDef.editable === false) {
139
- // Return the original value as text if column is not editable
140
- return <span className="text-sm text-gray-600">{value || ''}</span>;
141
- }
142
-
143
- // Check for custom field type
144
- if (columnDef.fieldType === 'select' && columnDef.fieldOptions) {
145
- // Use editAccessorKey if specified, otherwise use the column id
146
- const editKey = columnDef.editAccessorKey || column.id;
147
- const editValue = editingData[editKey] || value;
148
-
149
- return (
150
- <Select
151
- value={String(editValue || '')}
152
- onValueChange={(newValue) => {
153
- // If editAccessorKey is specified, update that field instead
154
- if (columnDef.editAccessorKey) {
155
- onChange({ [columnDef.editAccessorKey]: Number(newValue) });
156
- } else {
157
- onChange(newValue);
158
- }
159
- }}
160
- >
161
- <SelectTrigger className="w-full h-8">
162
- <SelectValue placeholder={placeholder || `Select ${column.id}`} />
163
- </SelectTrigger>
164
- <SelectContent>
165
- {columnDef.fieldOptions.map((option: any) => (
166
- <SelectItem key={option.value} value={String(option.value)}>
167
- {option.label}
168
- </SelectItem>
169
- ))}
170
- </SelectContent>
171
- </Select>
172
- );
173
- }
174
-
175
- if (columnDef.fieldType === 'date') {
176
- return (
177
- <Input
178
- type="date"
179
- value={value || ''}
180
- onChange={(e) => onChange(e.target.value)}
181
- className="w-full h-8"
182
- />
183
- );
184
- }
185
-
186
- // Default to text input
187
- return (
188
- <Input
189
- type="text"
190
- value={value || ''}
191
- onChange={(e) => onChange(e.target.value)}
192
- className="w-full h-8"
193
- placeholder={placeholder || `Enter ${column.id}`}
194
- />
195
- );
196
- };
197
-
198
- export function DataTableBody<TData extends Record<string, any>>({
199
- table,
200
- isCreating,
201
- creationData,
202
- onCreationDataChange,
203
- onSaveCreation,
204
- onCancelCreation,
205
- editingRowId,
206
- editingData,
207
- onEditingDataChange,
208
- grouping,
209
- aggregates,
210
- getRowId,
211
- emptyState,
212
- isFiltered,
213
- onClearFilters,
214
- hierarchical,
215
- }: DataTableBodyProps<TData>) {
216
-
217
- // Debug logging
218
- console.log('🔍 DataTableBody Debug:', {
219
- rowModelLength: table.getRowModel().rows.length,
220
- totalRowCount: table.getRowCount(),
221
- groupingEnabled: grouping.length > 0,
222
- grouping: grouping,
223
- rowAnalysis: table.getRowModel().rows.map(row => ({
224
- id: row.id,
225
- isGrouped: row.getIsGrouped(),
226
- hasParent: !!(typeof row.getParentRow === 'function' ? row.getParentRow() : false),
227
- subRowsCount: row.subRows?.length || 0,
228
- originalData: row.original?.meal_code || row.original?.id || 'no-id',
229
- })),
230
- paginationState: table.getState().pagination,
231
- });
232
-
233
- return (
234
- <>
235
- {/* Table Header */}
236
- <thead>
237
- {table.getHeaderGroups().map((headerGroup) => (
238
- <tr key={headerGroup.id}>
239
- {/* Expand/Collapse All Button - Only show for hierarchical tables */}
240
- {hierarchical?.enabled && hierarchical?.hasAnyChildren && (
241
- <th className="w-12">
242
- <Button
243
- variant="ghost"
244
- size="sm"
245
- onClick={hierarchical.isAllExpanded ? hierarchical.collapseAll : hierarchical.expandAll}
246
- className="h-8 w-8 p-0"
247
- aria-label={hierarchical.isAllExpanded ? 'Collapse all' : 'Expand all'}
248
- title={hierarchical.isAllExpanded ? 'Collapse all' : 'Expand all'}
249
- >
250
- {hierarchical.isAllExpanded ? (
251
- <ChevronDown className="h-4 w-4" />
252
- ) : (
253
- <ChevronRight className="h-4 w-4" />
254
- )}
255
- </Button>
256
- </th>
257
- )}
258
-
259
- {headerGroup.headers.map((header) => {
260
- const isSortable = header.column.getCanSort();
261
- const ariaSort = isSortable
262
- ? (header.column.getIsSorted() === 'asc'
263
- ? 'ascending'
264
- : header.column.getIsSorted() === 'desc'
265
- ? 'descending'
266
- : 'none')
267
- : undefined;
268
- return (
269
- <th
270
- key={header.id}
271
- {...(isSortable ? { 'aria-sort': ariaSort } : {})}
272
- >
273
- {header.isPlaceholder ? null : (
274
- isSortable ? (
275
- <Button
276
- variant="ghost"
277
- className="h-auto p-0 font-medium hover:bg-transparent"
278
- onClick={header.column.getToggleSortingHandler()}
279
- aria-label={`Sort by ${typeof header.column.columnDef.header === 'string' ? header.column.columnDef.header : 'column'}`}
280
- tabIndex={0}
281
- >
282
- <div className={`flex items-center gap-1 ${header.column.columnDef.meta?.align === 'right' ? 'justify-end' : ''}`}>
283
- {typeof header.column.columnDef.header === 'function'
284
- ? header.column.columnDef.header(header.getContext())
285
- : header.column.columnDef.header}
286
- {header.column.getIsSorted() === 'asc' ? (
287
- <ChevronUp className="h-4 w-4" />
288
- ) : header.column.getIsSorted() === 'desc' ? (
289
- <ChevronDown className="h-4 w-4" />
290
- ) : (
291
- <ChevronsUpDown className="h-4 w-4" />
292
- )}
293
- </div>
294
- </Button>
295
- ) : (
296
- <div className={header.column.columnDef.meta?.align === 'right' ? 'text-right' : ''}>
297
- {typeof header.column.columnDef.header === 'function'
298
- ? header.column.columnDef.header(header.getContext())
299
- : header.column.columnDef.header}
300
- </div>
301
- )
302
- )}
303
- </th>
304
- );
305
- })}
306
- </tr>
307
- ))}
308
- </thead>
309
-
310
- {/* Table Body */}
311
- <tbody>
312
- {/* Creation Row */}
313
- {isCreating && (
314
- <tr>
315
- {table.getVisibleFlatColumns().map((column) => (
316
- <td key={column.id}>
317
- {renderEditField(column, creationData[column.id], (value) => {
318
- if (typeof value === 'object' && value !== null) {
319
- // Handle editAccessorKey case
320
- onCreationDataChange({ ...creationData, ...value });
321
- } else {
322
- // Handle simple value case
323
- onCreationDataChange({ ...creationData, [column.id]: value });
324
- }
325
- }, creationData)}
326
- </td>
327
- ))}
328
- <td className="flex gap-1">
329
- <>
330
- <button
331
- onClick={onSaveCreation}
332
- className="h-8 w-8 p-0 bg-app-main-500 text-app-main-50 rounded hover:bg-app-main-600 flex items-center justify-center"
333
- title="Save new row"
334
- >
335
- <svg className="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
336
- <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M5 13l4 4L19 7" />
337
- </svg>
338
- </button>
339
- <button
340
- onClick={onCancelCreation}
341
- className="h-8 w-8 p-0 bg-app-sec-500 text-app-main-50 rounded hover:bg-app-sec-600 flex items-center justify-center"
342
- title="Cancel new row"
343
- >
344
- <svg className="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
345
- <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />
346
- </svg>
347
- </button>
348
- </>
349
- </td>
350
- </tr>
351
- )}
352
-
353
- {/* Table Rows */}
354
- {table.getRowModel().rows.length === 0 && (
355
- <tr>
356
- <td colSpan={table.getVisibleFlatColumns().length} role="status">
357
- <EmptyState
358
- title={emptyState?.title}
359
- description={emptyState?.description}
360
- icon={emptyState?.icon}
361
- action={emptyState?.action}
362
- isFiltered={isFiltered}
363
- onClearFilters={onClearFilters}
364
- />
365
- </td>
366
- </tr>
367
- )}
368
-
369
- {table.getRowModel().rows.map((row) => {
370
- const rowId = getRowId ? getRowId(row.original, row.index) : String(row.index);
371
- const isEditing = editingRowId === rowId;
372
-
373
- // Handle grouped rows
374
- if (row.getIsGrouped()) {
375
- const groupValue = row.getValue(grouping[0]);
376
- const subRowsCount = row.subRows?.length || 0;
377
- const isExpanded = row.getIsExpanded();
378
-
379
- return (
380
- <React.Fragment key={row.id}>
381
- {/* Group Header Row */}
382
- <tr className="bg-app-sec-50 hover:bg-app-sec-100">
383
- <td className="flex items-center py-2 font-medium" colSpan={table.getAllColumns().length}>
384
- <>
385
- <Button
386
- variant="ghost"
387
- size="sm"
388
- onClick={() => row.toggleExpanded()}
389
- className="p-0 h-auto mr-2"
390
- >
391
- {isExpanded ? (
392
- <ChevronDown className="h-4 w-4" />
393
- ) : (
394
- <ChevronRight className="h-4 w-4" />
395
- )}
396
- </Button>
397
- <span className="text-sm">
398
- {String(groupValue)} ({subRowsCount} items)
399
- </span>
400
- </>
401
- </td>
402
- </tr>
403
-
404
- {/* Render sub-rows if expanded */}
405
- {isExpanded && row.subRows?.map((subRow) => {
406
- const subRowId = getRowId ? getRowId(subRow.original, subRow.index) : String(subRow.index);
407
- const isSubRowEditing = editingRowId === subRowId;
408
-
409
- return (
410
- <tr key={subRow.id} className="border-l-2 border-l-blue-200">
411
- {subRow.getVisibleCells().map((cell) => (
412
- <td key={cell.id} className="pl-8">
413
- {isSubRowEditing && cell.column.id !== 'actions' ? (
414
- renderEditField(cell.column, editingData[cell.column.id], (value) => {
415
- if (typeof value === 'object' && value !== null) {
416
- // Handle editAccessorKey case
417
- onEditingDataChange({ ...editingData, ...value });
418
- } else {
419
- // Handle simple value case
420
- onEditingDataChange({ ...editingData, [cell.column.id]: value });
421
- }
422
- }, editingData)
423
- ) : (
424
- flexRender(cell.column.columnDef.cell, cell.getContext())
425
- )}
426
- </td>
427
- ))}
428
- </tr>
429
- );
430
- })}
431
- </React.Fragment>
432
- );
433
- }
434
-
435
- // Skip leaf rows when grouping is enabled - they're already rendered as sub-rows
436
- // A row is a leaf if it has a parent (part of a group) and is not itself a group header
437
- if (grouping.length > 0 && typeof row.getParentRow === 'function' && row.getParentRow() && !row.getIsGrouped()) {
438
- return null;
439
- }
440
-
441
- // Regular row (non-grouped or when grouping is disabled)
442
- return (
443
- <tr key={row.id}>
444
- {row.getVisibleCells().map((cell) => {
445
- const columnDef = cell.column.columnDef as any;
446
- const isColumnEditable = columnDef.editable !== false;
447
-
448
- return (
449
- <td key={cell.id}>
450
- {isEditing && cell.column.id !== 'actions' && isColumnEditable ? (
451
- // Check if column has a custom cell renderer - if so, use it in edit mode
452
- cell.column.columnDef.cell ? (
453
- flexRender(cell.column.columnDef.cell, {
454
- ...cell.getContext(),
455
- getIsEditing: () => true, // Always true in edit mode
456
- setValue: (value: any) => {
457
- if (typeof value === 'object' && value !== null) {
458
- onEditingDataChange({ ...editingData, ...value });
459
- } else {
460
- onEditingDataChange({ ...editingData, [cell.column.id]: value });
461
- }
462
- }
463
- })
464
- ) : (
465
- // Fall back to default edit field rendering when no custom cell renderer
466
- renderEditField(cell.column, editingData[cell.column.id], (value) => {
467
- if (typeof value === 'object' && value !== null) {
468
- // Handle editAccessorKey case
469
- onEditingDataChange({ ...editingData, ...value });
470
- } else {
471
- // Handle simple value case
472
- onEditingDataChange({ ...editingData, [cell.column.id]: value });
473
- }
474
- }, editingData)
475
- )
476
- ) : (
477
- flexRender(cell.column.columnDef.cell, cell.getContext())
478
- )}
479
- </td>
480
- );
481
- })}
482
- </tr>
483
- );
484
- })}
485
- </tbody>
486
- </>
487
- );
488
- }
@@ -1,144 +0,0 @@
1
- import React, { useState } from 'react';
2
- import { Button } from '../../Button/Button';
3
- import { ChevronUp, ChevronDown,ChevronsUpDown } from 'lucide-react';
4
- import { cn } from '../../../utils/cn';
5
- import type { Header } from '@tanstack/react-table';
6
-
7
- interface DraggableColumnHeaderProps<TData> {
8
- header: Header<TData, unknown>;
9
- onMoveLeft?: () => void;
10
- onMoveRight?: () => void;
11
- canMoveLeft?: boolean;
12
- canMoveRight?: boolean;
13
- enableReordering?: boolean;
14
- onColumnDrop?: (draggedColumnId: string, targetColumnId: string) => void;
15
- }
16
-
17
- export function DraggableColumnHeader<TData>({
18
- header,
19
- onMoveLeft,
20
- onMoveRight,
21
- canMoveLeft = false,
22
- canMoveRight = false,
23
- enableReordering = false,
24
- onColumnDrop,
25
- }: DraggableColumnHeaderProps<TData>) {
26
- const [isDragging, setIsDragging] = useState(false);
27
- const [dragOver, setDragOver] = useState(false);
28
-
29
- const isSortable = header.column.getCanSort ? header.column.getCanSort() : false;
30
- const ariaSort = isSortable
31
- ? (header.column.getIsSorted ? (header.column.getIsSorted() === 'asc'
32
- ? 'ascending'
33
- : header.column.getIsSorted() === 'desc'
34
- ? 'descending'
35
- : 'none') : 'none')
36
- : undefined;
37
-
38
- const handleDragStart = (e: React.DragEvent) => {
39
- if (!enableReordering) return;
40
-
41
- setIsDragging(true);
42
- e.dataTransfer.setData('text/plain', header.id);
43
- e.dataTransfer.effectAllowed = 'move';
44
-
45
- // Add visual feedback
46
- if (e.currentTarget instanceof HTMLElement) {
47
- e.currentTarget.style.opacity = '0.5';
48
- }
49
- };
50
-
51
- const handleDragEnd = (e: React.DragEvent) => {
52
- setIsDragging(false);
53
- setDragOver(false);
54
-
55
- // Reset visual feedback
56
- if (e.currentTarget instanceof HTMLElement) {
57
- e.currentTarget.style.opacity = '1';
58
- }
59
- };
60
-
61
- const handleDragOver = (e: React.DragEvent) => {
62
- if (!enableReordering) return;
63
-
64
- e.preventDefault();
65
- e.dataTransfer.dropEffect = 'move';
66
- setDragOver(true);
67
- };
68
-
69
- const handleDragLeave = (e: React.DragEvent) => {
70
- if (!enableReordering) return;
71
-
72
- // Only set dragOver to false if we're leaving the element entirely
73
- if (!e.currentTarget.contains(e.relatedTarget as Node)) {
74
- setDragOver(false);
75
- }
76
- };
77
-
78
- const handleDrop = (e: React.DragEvent) => {
79
- if (!enableReordering) return;
80
-
81
- e.preventDefault();
82
- setDragOver(false);
83
-
84
- const draggedHeaderId = e.dataTransfer.getData('text/plain');
85
- if (draggedHeaderId && draggedHeaderId !== header.id && onColumnDrop) {
86
- onColumnDrop(draggedHeaderId, header.id);
87
- }
88
- };
89
-
90
- return (
91
- <th
92
- className={cn(
93
- 'px-3 py-2 text-sm font-medium text-left relative group',
94
- isSortable && 'cursor-pointer hover:bg-sec-50',
95
- isDragging && 'opacity-50',
96
- dragOver && 'bg-main-50 border-main-200',
97
- enableReordering && 'cursor-move'
98
- )}
99
- style={{}}
100
- draggable={enableReordering}
101
- onDragStart={handleDragStart}
102
- onDragEnd={handleDragEnd}
103
- onDragOver={handleDragOver}
104
- onDragLeave={handleDragLeave}
105
- onDrop={handleDrop}
106
- {...(isSortable ? { 'aria-sort': ariaSort } : {})}
107
- >
108
- <div className="flex items-center justify-between">
109
- <div className="flex items-center gap-1 flex-1">
110
- {header.isPlaceholder ? null : (
111
- isSortable ? (
112
- <Button
113
- variant="ghost"
114
- className="h-auto p-0 font-medium hover:bg-transparent flex-1 justify-start"
115
- onClick={header.column.getToggleSortingHandler()}
116
- aria-label={`Sort by ${typeof header.column.columnDef.header === 'string' ? header.column.columnDef.header : 'column'}`}
117
- tabIndex={0}
118
- >
119
- <div className="flex items-center gap-1">
120
- {typeof header.column.columnDef.header === 'function'
121
- ? header.column.columnDef.header(header.getContext())
122
- : header.column.columnDef.header}
123
- {header.column.getIsSorted() === 'asc' ? (
124
- <ChevronUp className="h-4 w-4" />
125
- ) : header.column.getIsSorted() === 'desc' ? (
126
- <ChevronDown className="h-4 w-4" />
127
- ) : (
128
- <ChevronsUpDown className="h-4 w-4" />
129
- )}
130
- </div>
131
- </Button>
132
- ) : (
133
- <div className="flex-1">
134
- {typeof header.column.columnDef.header === 'function'
135
- ? header.column.columnDef.header(header.getContext())
136
- : header.column.columnDef.header}
137
- </div>
138
- )
139
- )}
140
- </div>
141
- </div>
142
- </th>
143
- );
144
- }