@jmruthers/pace-core 0.5.136 → 0.5.139
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.
- package/dist/{DataTable-CYOHOX3O.js → DataTable-JXFCA2BJ.js} +10 -9
- package/dist/{EventLogo-801uofbR.d.ts → EventLogo-rFL_kRjk.d.ts} +73 -1
- package/dist/{UnifiedAuthProvider-5E5TUNMS.js → UnifiedAuthProvider-XIQQ7LVU.js} +4 -5
- package/dist/{chunk-YLKIDTUK.js → chunk-22WKWKRX.js} +4 -4
- package/dist/{chunk-TVYPTYOY.js → chunk-4C7EXCAR.js} +60 -24
- package/dist/chunk-4C7EXCAR.js.map +1 -0
- package/dist/{chunk-NOHEVYVX.js → chunk-5JMOHWDI.js} +417 -319
- package/dist/chunk-5JMOHWDI.js.map +1 -0
- package/dist/{chunk-FHWWBIHA.js → chunk-6DXZ6V5Q.js} +5 -5
- package/dist/{chunk-2TWNJ46Y.js → chunk-6LAAY47Q.js} +2 -2
- package/dist/{chunk-444EZN6N.js → chunk-7QCC6MCP.js} +88 -1
- package/dist/chunk-7QCC6MCP.js.map +1 -0
- package/dist/chunk-BJPBT3CU.js +21 -0
- package/dist/chunk-BJPBT3CU.js.map +1 -0
- package/dist/{chunk-L6PGMCMD.js → chunk-BOOI7GK2.js} +38 -12
- package/dist/chunk-BOOI7GK2.js.map +1 -0
- package/dist/{chunk-XARJS7CD.js → chunk-INQLMHPF.js} +2 -2
- package/dist/chunk-JISYG63F.js +70 -0
- package/dist/chunk-JISYG63F.js.map +1 -0
- package/dist/{chunk-SL2YQDR6.js → chunk-MA6EPSGZ.js} +2 -2
- package/dist/{chunk-5DPZ5EAT.js → chunk-OWAG3GSU.js} +1 -3
- package/dist/{chunk-LTV3XIJJ.js → chunk-T6JN6LH6.js} +4 -4
- package/dist/{chunk-HJGGOMQ6.js → chunk-TLT2ZR3L.js} +147 -103
- package/dist/chunk-TLT2ZR3L.js.map +1 -0
- package/dist/{chunk-4MT5BGGL.js → chunk-YCWDTTUK.js} +4 -6
- package/dist/{chunk-4MT5BGGL.js.map → chunk-YCWDTTUK.js.map} +1 -1
- package/dist/components.d.ts +1 -1
- package/dist/components.js +12 -11
- package/dist/components.js.map +1 -1
- package/dist/hooks.js +8 -9
- package/dist/hooks.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +15 -14
- package/dist/index.js.map +1 -1
- package/dist/providers.js +3 -4
- package/dist/rbac/index.js +8 -9
- package/dist/schema-DTDZQe2u.d.ts +28 -0
- package/dist/types.d.ts +152 -3
- package/dist/types.js +51 -16
- package/dist/types.js.map +1 -1
- package/dist/utils.d.ts +89 -4
- package/dist/utils.js +214 -96
- package/dist/utils.js.map +1 -1
- package/dist/validation.d.ts +1 -343
- package/dist/validation.js +3 -100
- package/docs/api/classes/ColumnFactory.md +1 -1
- package/docs/api/classes/ErrorBoundary.md +1 -1
- package/docs/api/classes/InvalidScopeError.md +1 -1
- package/docs/api/classes/MissingUserContextError.md +1 -1
- package/docs/api/classes/OrganisationContextRequiredError.md +1 -1
- package/docs/api/classes/PermissionDeniedError.md +1 -1
- package/docs/api/classes/PublicErrorBoundary.md +1 -1
- package/docs/api/classes/RBACAuditManager.md +1 -1
- package/docs/api/classes/RBACCache.md +1 -1
- package/docs/api/classes/RBACEngine.md +1 -1
- package/docs/api/classes/RBACError.md +1 -1
- package/docs/api/classes/RBACNotInitializedError.md +1 -1
- package/docs/api/classes/SecureSupabaseClient.md +1 -1
- package/docs/api/classes/StorageUtils.md +1 -1
- package/docs/api/enums/FileCategory.md +1 -1
- package/docs/api/interfaces/AggregateConfig.md +1 -1
- package/docs/api/interfaces/BadgeProps.md +27 -0
- package/docs/api/interfaces/ButtonProps.md +1 -1
- package/docs/api/interfaces/CardProps.md +1 -1
- package/docs/api/interfaces/ColorPalette.md +1 -1
- package/docs/api/interfaces/ColorShade.md +1 -1
- package/docs/api/interfaces/DataAccessRecord.md +1 -1
- package/docs/api/interfaces/DataRecord.md +1 -1
- package/docs/api/interfaces/DataTableAction.md +1 -1
- package/docs/api/interfaces/DataTableColumn.md +1 -1
- package/docs/api/interfaces/DataTableProps.md +1 -1
- package/docs/api/interfaces/DataTableToolbarButton.md +1 -1
- package/docs/api/interfaces/EmptyStateConfig.md +1 -1
- package/docs/api/interfaces/EnhancedNavigationMenuProps.md +1 -1
- package/docs/api/interfaces/EventAppRoleData.md +1 -1
- package/docs/api/interfaces/EventLogoProps.md +1 -1
- package/docs/api/interfaces/ExportColumn.md +1 -1
- package/docs/api/interfaces/ExportOptions.md +1 -1
- package/docs/api/interfaces/FileDisplayProps.md +1 -1
- package/docs/api/interfaces/FileMetadata.md +1 -1
- package/docs/api/interfaces/FileReference.md +1 -1
- package/docs/api/interfaces/FileSizeLimits.md +1 -1
- package/docs/api/interfaces/FileUploadOptions.md +1 -1
- package/docs/api/interfaces/FileUploadProps.md +1 -1
- package/docs/api/interfaces/FooterProps.md +1 -1
- package/docs/api/interfaces/GrantEventAppRoleParams.md +1 -1
- package/docs/api/interfaces/InactivityWarningModalProps.md +1 -1
- package/docs/api/interfaces/InputProps.md +1 -1
- package/docs/api/interfaces/LabelProps.md +1 -1
- package/docs/api/interfaces/LoginFormProps.md +1 -1
- package/docs/api/interfaces/NavigationAccessRecord.md +1 -1
- package/docs/api/interfaces/NavigationContextType.md +1 -1
- package/docs/api/interfaces/NavigationGuardProps.md +1 -1
- package/docs/api/interfaces/NavigationItem.md +1 -1
- package/docs/api/interfaces/NavigationMenuProps.md +1 -1
- package/docs/api/interfaces/NavigationProviderProps.md +1 -1
- package/docs/api/interfaces/Organisation.md +1 -1
- package/docs/api/interfaces/OrganisationContextType.md +1 -1
- package/docs/api/interfaces/OrganisationMembership.md +1 -1
- package/docs/api/interfaces/OrganisationProviderProps.md +1 -1
- package/docs/api/interfaces/OrganisationSecurityError.md +1 -1
- package/docs/api/interfaces/PaceAppLayoutProps.md +1 -1
- package/docs/api/interfaces/PaceLoginPageProps.md +1 -1
- package/docs/api/interfaces/PageAccessRecord.md +1 -1
- package/docs/api/interfaces/PagePermissionContextType.md +1 -1
- package/docs/api/interfaces/PagePermissionGuardProps.md +1 -1
- package/docs/api/interfaces/PagePermissionProviderProps.md +1 -1
- package/docs/api/interfaces/PaletteData.md +1 -1
- package/docs/api/interfaces/PermissionEnforcerProps.md +1 -1
- package/docs/api/interfaces/ProtectedRouteProps.md +1 -1
- package/docs/api/interfaces/PublicErrorBoundaryProps.md +1 -1
- package/docs/api/interfaces/PublicErrorBoundaryState.md +1 -1
- package/docs/api/interfaces/PublicLoadingSpinnerProps.md +1 -1
- package/docs/api/interfaces/PublicPageFooterProps.md +1 -1
- package/docs/api/interfaces/PublicPageHeaderProps.md +1 -1
- package/docs/api/interfaces/PublicPageLayoutProps.md +1 -1
- package/docs/api/interfaces/RBACConfig.md +1 -1
- package/docs/api/interfaces/RBACLogger.md +1 -1
- package/docs/api/interfaces/RevokeEventAppRoleParams.md +1 -1
- package/docs/api/interfaces/RoleBasedRouterContextType.md +1 -1
- package/docs/api/interfaces/RoleBasedRouterProps.md +1 -1
- package/docs/api/interfaces/RoleManagementResult.md +1 -1
- package/docs/api/interfaces/RouteAccessRecord.md +1 -1
- package/docs/api/interfaces/RouteConfig.md +1 -1
- package/docs/api/interfaces/SecureDataContextType.md +1 -1
- package/docs/api/interfaces/SecureDataProviderProps.md +1 -1
- package/docs/api/interfaces/SessionRestorationLoaderProps.md +1 -1
- package/docs/api/interfaces/StorageConfig.md +1 -1
- package/docs/api/interfaces/StorageFileInfo.md +1 -1
- package/docs/api/interfaces/StorageFileMetadata.md +1 -1
- package/docs/api/interfaces/StorageListOptions.md +1 -1
- package/docs/api/interfaces/StorageListResult.md +1 -1
- package/docs/api/interfaces/StorageUploadOptions.md +1 -1
- package/docs/api/interfaces/StorageUploadResult.md +1 -1
- package/docs/api/interfaces/StorageUrlOptions.md +1 -1
- package/docs/api/interfaces/StyleImport.md +1 -1
- package/docs/api/interfaces/SwitchProps.md +1 -1
- package/docs/api/interfaces/ToastActionElement.md +1 -1
- package/docs/api/interfaces/ToastProps.md +1 -1
- package/docs/api/interfaces/UnifiedAuthContextType.md +1 -1
- package/docs/api/interfaces/UnifiedAuthProviderProps.md +1 -1
- package/docs/api/interfaces/UseInactivityTrackerOptions.md +1 -1
- package/docs/api/interfaces/UseInactivityTrackerReturn.md +1 -1
- package/docs/api/interfaces/UsePublicEventOptions.md +1 -1
- package/docs/api/interfaces/UsePublicEventReturn.md +1 -1
- package/docs/api/interfaces/UsePublicFileDisplayOptions.md +1 -1
- package/docs/api/interfaces/UsePublicFileDisplayReturn.md +1 -1
- package/docs/api/interfaces/UsePublicRouteParamsReturn.md +1 -1
- package/docs/api/interfaces/UseResolvedScopeOptions.md +1 -1
- package/docs/api/interfaces/UseResolvedScopeReturn.md +1 -1
- package/docs/api/interfaces/UserEventAccess.md +1 -1
- package/docs/api/interfaces/UserMenuProps.md +1 -1
- package/docs/api/interfaces/UserProfile.md +1 -1
- package/docs/api/modules.md +84 -15
- package/docs/architecture/README.md +0 -1
- package/docs/styles/README.md +0 -2
- package/examples/RBAC/CompleteRBACExample.tsx +324 -0
- package/examples/RBAC/EventBasedApp.tsx +239 -0
- package/examples/RBAC/PermissionExample.tsx +151 -0
- package/examples/RBAC/index.ts +13 -0
- package/examples/public-pages/CorrectPublicPageImplementation.tsx +301 -0
- package/examples/public-pages/PublicEventPage.tsx +274 -0
- package/examples/public-pages/PublicPageApp.tsx +308 -0
- package/examples/public-pages/PublicPageUsageExample.tsx +216 -0
- package/examples/public-pages/index.ts +14 -0
- package/package.json +1 -10
- package/src/__tests__/TEST_STANDARD.md +92 -0
- package/src/components/Badge/Badge.test.tsx +314 -0
- package/src/components/Badge/Badge.tsx +304 -0
- package/src/components/Badge/index.ts +3 -0
- package/src/components/DataTable/__tests__/DataTableCore.test-setup.ts +217 -0
- package/src/components/DataTable/__tests__/styles.test.ts +1 -1
- package/src/components/DataTable/components/ColumnFilter.tsx +8 -4
- package/src/components/DataTable/components/DataTableBody.tsx +461 -0
- package/src/components/DataTable/components/DraggableColumnHeader.tsx +144 -0
- package/src/components/DataTable/components/FilterRow.tsx +9 -3
- package/src/components/DataTable/components/PaginationControls.tsx +1 -0
- package/src/components/DataTable/components/VirtualizedDataTable.tsx +513 -0
- package/src/components/DataTable/components/__tests__/AccessDeniedPage.test.tsx +14 -68
- package/src/components/DataTable/components/__tests__/ColumnFilter.test.tsx +62 -0
- package/src/components/DataTable/components/__tests__/FilterRow.test.tsx +43 -0
- package/src/components/DataTable/core/ActionManager.ts +235 -0
- package/src/components/DataTable/core/ColumnManager.ts +205 -0
- package/src/components/DataTable/core/DataManager.ts +188 -0
- package/src/components/DataTable/core/DataTableContext.tsx +181 -0
- package/src/components/DataTable/core/LocalDataAdapter.ts +273 -0
- package/src/components/DataTable/core/PluginRegistry.ts +229 -0
- package/src/components/DataTable/core/StateManager.ts +311 -0
- package/src/components/DataTable/core/interfaces.ts +338 -0
- package/src/components/DataTable/styles.ts +27 -6
- package/src/components/DataTable/utils/__tests__/columnUtils.test.ts +94 -0
- package/src/components/DataTable/utils/columnUtils.ts +40 -0
- package/src/components/DataTable/utils/debugTools.ts +609 -0
- package/src/components/DataTable/utils/index.ts +1 -0
- package/src/components/Dialog/README.md +804 -0
- package/src/components/Dialog/utils/__tests__/safeHtml.unit.test.ts +611 -0
- package/src/components/Dialog/utils/safeHtml.ts +185 -0
- package/src/components/Footer/Footer.test.tsx +1 -1
- package/src/components/Form/Form.test.tsx +1 -1
- package/src/components/Form/FormErrorSummary.tsx +113 -0
- package/src/components/Form/FormFieldset.tsx +127 -0
- package/src/components/Form/FormLiveRegion.tsx +198 -0
- package/src/components/LoginForm/LoginForm.test.tsx +1 -1
- package/src/components/PaceAppLayout/__tests__/PaceAppLayout.performance.test.tsx +76 -10
- package/src/components/PaceLoginPage/PaceLoginPage.tsx +1 -1
- package/src/components/PasswordReset/PasswordResetForm.test.tsx +597 -0
- package/src/components/PasswordReset/PasswordResetForm.tsx +201 -0
- package/src/components/PublicLayout/PublicPageDebugger.tsx +104 -0
- package/src/components/PublicLayout/PublicPageDiagnostic.tsx +162 -0
- package/src/components/PublicLayout/__tests__/PublicPageFooter.test.tsx +1 -1
- package/src/components/Select/Select.test.tsx +1 -1
- package/src/components/Select/Select.tsx +20 -8
- package/src/components/Table/__tests__/Table.test.tsx +1 -1
- package/src/components/index.ts +3 -0
- package/src/hooks/__tests__/useFileUrl.unit.test.ts +83 -85
- package/src/index.ts +4 -0
- package/src/rbac/hooks/useCan.test.ts +24 -0
- package/src/rbac/hooks/usePermissions.ts +49 -12
- package/src/styles/core.css +3 -0
- package/src/utils/appConfig.ts +47 -0
- package/src/utils/appIdResolver.test.ts +499 -0
- package/src/utils/appIdResolver.ts +130 -0
- package/src/utils/appNameResolver.simple.test.ts +212 -0
- package/src/utils/appNameResolver.test.ts +121 -0
- package/src/utils/appNameResolver.ts +191 -0
- package/src/utils/audit.ts +127 -0
- package/src/utils/auth-utils.ts +96 -0
- package/src/utils/bundleAnalysis.ts +129 -0
- package/src/utils/cn.ts +7 -0
- package/src/utils/debugLogger.ts +67 -0
- package/src/utils/deviceFingerprint.ts +215 -0
- package/src/utils/dynamicUtils.ts +105 -0
- package/src/utils/file-reference.test.ts +788 -0
- package/src/utils/file-reference.ts +519 -0
- package/src/utils/formatDate.test.ts +237 -0
- package/src/utils/formatting.ts +133 -0
- package/src/utils/index.ts +7 -0
- package/src/utils/lazyLoad.tsx +44 -0
- package/src/utils/logger.ts +179 -0
- package/src/utils/organisationContext.test.ts +322 -0
- package/src/utils/organisationContext.ts +153 -0
- package/src/utils/performanceBenchmark.ts +64 -0
- package/src/utils/performanceBudgets.ts +110 -0
- package/src/utils/permissionTypes.ts +37 -0
- package/src/utils/permissionUtils.test.ts +393 -0
- package/src/utils/permissionUtils.ts +34 -0
- package/src/utils/sanitization.ts +264 -0
- package/src/utils/schemaUtils.ts +37 -0
- package/src/utils/secureDataAccess.test.ts +711 -0
- package/src/utils/secureDataAccess.ts +377 -0
- package/src/utils/secureErrors.ts +79 -0
- package/src/utils/secureStorage.ts +244 -0
- package/src/utils/security.ts +156 -0
- package/src/utils/securityMonitor.ts +45 -0
- package/src/utils/sessionTracking.ts +126 -0
- package/src/utils/validation.ts +111 -0
- package/src/utils/validationUtils.ts +120 -0
- package/src/validation/index.ts +2 -2
- package/dist/chunk-444EZN6N.js.map +0 -1
- package/dist/chunk-APIBCTL2.js +0 -670
- package/dist/chunk-APIBCTL2.js.map +0 -1
- package/dist/chunk-HJGGOMQ6.js.map +0 -1
- package/dist/chunk-K2WWTH7O.js +0 -94
- package/dist/chunk-K2WWTH7O.js.map +0 -1
- package/dist/chunk-L6PGMCMD.js.map +0 -1
- package/dist/chunk-LMC26NLJ.js +0 -84
- package/dist/chunk-LMC26NLJ.js.map +0 -1
- package/dist/chunk-NOHEVYVX.js.map +0 -1
- package/dist/chunk-TVYPTYOY.js.map +0 -1
- package/dist/validation-8npbysjg.d.ts +0 -177
- /package/dist/{DataTable-CYOHOX3O.js.map → DataTable-JXFCA2BJ.js.map} +0 -0
- /package/dist/{UnifiedAuthProvider-5E5TUNMS.js.map → UnifiedAuthProvider-XIQQ7LVU.js.map} +0 -0
- /package/dist/{chunk-YLKIDTUK.js.map → chunk-22WKWKRX.js.map} +0 -0
- /package/dist/{chunk-FHWWBIHA.js.map → chunk-6DXZ6V5Q.js.map} +0 -0
- /package/dist/{chunk-2TWNJ46Y.js.map → chunk-6LAAY47Q.js.map} +0 -0
- /package/dist/{chunk-XARJS7CD.js.map → chunk-INQLMHPF.js.map} +0 -0
- /package/dist/{chunk-SL2YQDR6.js.map → chunk-MA6EPSGZ.js.map} +0 -0
- /package/dist/{chunk-5DPZ5EAT.js.map → chunk-OWAG3GSU.js.map} +0 -0
- /package/dist/{chunk-LTV3XIJJ.js.map → chunk-T6JN6LH6.js.map} +0 -0
- /package/examples/{components → components 2}/DataTable/HierarchicalActionsExample.tsx +0 -0
- /package/examples/{components → components 2}/DataTable/HierarchicalExample.tsx +0 -0
- /package/examples/{components → components 2}/DataTable/InitialPageSizeExample.tsx +0 -0
- /package/examples/{components → components 2}/DataTable/PerformanceExample.tsx +0 -0
- /package/examples/{components → components 2}/DataTable/index.ts +0 -0
- /package/examples/{components → components 2}/Dialog/BasicHtmlTest.tsx +0 -0
- /package/examples/{components → components 2}/Dialog/DebugHtmlExample.tsx +0 -0
- /package/examples/{components → components 2}/Dialog/HtmlDialogExample.tsx +0 -0
- /package/examples/{components → components 2}/Dialog/ScrollableDialogExample.tsx +0 -0
- /package/examples/{components → components 2}/Dialog/SimpleHtmlTest.tsx +0 -0
- /package/examples/{components → components 2}/Dialog/SmartDialogExample.tsx +0 -0
- /package/examples/{components → components 2}/Dialog/index.ts +0 -0
- /package/examples/{components → components 2}/index.ts +0 -0
|
@@ -0,0 +1,461 @@
|
|
|
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 for custom field type
|
|
138
|
+
if (columnDef.fieldType === 'select' && columnDef.fieldOptions) {
|
|
139
|
+
// Use editAccessorKey if specified, otherwise use the column id
|
|
140
|
+
const editKey = columnDef.editAccessorKey || column.id;
|
|
141
|
+
const editValue = editingData[editKey] || value;
|
|
142
|
+
|
|
143
|
+
return (
|
|
144
|
+
<Select
|
|
145
|
+
value={String(editValue || '')}
|
|
146
|
+
onValueChange={(newValue) => {
|
|
147
|
+
// If editAccessorKey is specified, update that field instead
|
|
148
|
+
if (columnDef.editAccessorKey) {
|
|
149
|
+
onChange({ [columnDef.editAccessorKey]: Number(newValue) });
|
|
150
|
+
} else {
|
|
151
|
+
onChange(newValue);
|
|
152
|
+
}
|
|
153
|
+
}}
|
|
154
|
+
>
|
|
155
|
+
<SelectTrigger className="w-full h-8">
|
|
156
|
+
<SelectValue placeholder={placeholder || `Select ${column.id}`} />
|
|
157
|
+
</SelectTrigger>
|
|
158
|
+
<SelectContent>
|
|
159
|
+
{columnDef.fieldOptions.map((option: any) => (
|
|
160
|
+
<SelectItem key={option.value} value={String(option.value)}>
|
|
161
|
+
{option.label}
|
|
162
|
+
</SelectItem>
|
|
163
|
+
))}
|
|
164
|
+
</SelectContent>
|
|
165
|
+
</Select>
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (columnDef.fieldType === 'date') {
|
|
170
|
+
return (
|
|
171
|
+
<Input
|
|
172
|
+
type="date"
|
|
173
|
+
value={value || ''}
|
|
174
|
+
onChange={(e) => onChange(e.target.value)}
|
|
175
|
+
className="w-full h-8"
|
|
176
|
+
/>
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// Default to text input
|
|
181
|
+
return (
|
|
182
|
+
<Input
|
|
183
|
+
type="text"
|
|
184
|
+
value={value || ''}
|
|
185
|
+
onChange={(e) => onChange(e.target.value)}
|
|
186
|
+
className="w-full h-8"
|
|
187
|
+
placeholder={placeholder || `Enter ${column.id}`}
|
|
188
|
+
/>
|
|
189
|
+
);
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
export function DataTableBody<TData extends Record<string, any>>({
|
|
193
|
+
table,
|
|
194
|
+
isCreating,
|
|
195
|
+
creationData,
|
|
196
|
+
onCreationDataChange,
|
|
197
|
+
onSaveCreation,
|
|
198
|
+
onCancelCreation,
|
|
199
|
+
editingRowId,
|
|
200
|
+
editingData,
|
|
201
|
+
onEditingDataChange,
|
|
202
|
+
grouping,
|
|
203
|
+
aggregates,
|
|
204
|
+
getRowId,
|
|
205
|
+
emptyState,
|
|
206
|
+
isFiltered,
|
|
207
|
+
onClearFilters,
|
|
208
|
+
hierarchical,
|
|
209
|
+
}: DataTableBodyProps<TData>) {
|
|
210
|
+
|
|
211
|
+
// Debug logging
|
|
212
|
+
console.log('🔍 DataTableBody Debug:', {
|
|
213
|
+
rowModelLength: table.getRowModel().rows.length,
|
|
214
|
+
totalRowCount: table.getRowCount(),
|
|
215
|
+
groupingEnabled: grouping.length > 0,
|
|
216
|
+
grouping: grouping,
|
|
217
|
+
rowAnalysis: table.getRowModel().rows.map(row => ({
|
|
218
|
+
id: row.id,
|
|
219
|
+
isGrouped: row.getIsGrouped(),
|
|
220
|
+
hasParent: !!(typeof row.getParentRow === 'function' ? row.getParentRow() : false),
|
|
221
|
+
subRowsCount: row.subRows?.length || 0,
|
|
222
|
+
originalData: row.original?.meal_code || row.original?.id || 'no-id',
|
|
223
|
+
})),
|
|
224
|
+
paginationState: table.getState().pagination,
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
return (
|
|
228
|
+
<>
|
|
229
|
+
{/* Table Header */}
|
|
230
|
+
<thead>
|
|
231
|
+
{table.getHeaderGroups().map((headerGroup) => (
|
|
232
|
+
<tr key={headerGroup.id}>
|
|
233
|
+
{/* Expand/Collapse All Button - Only show for hierarchical tables */}
|
|
234
|
+
{hierarchical?.enabled && hierarchical?.hasAnyChildren && (
|
|
235
|
+
<th className="w-12">
|
|
236
|
+
<Button
|
|
237
|
+
variant="ghost"
|
|
238
|
+
size="sm"
|
|
239
|
+
onClick={hierarchical.isAllExpanded ? hierarchical.collapseAll : hierarchical.expandAll}
|
|
240
|
+
className="h-8 w-8 p-0"
|
|
241
|
+
aria-label={hierarchical.isAllExpanded ? 'Collapse all' : 'Expand all'}
|
|
242
|
+
title={hierarchical.isAllExpanded ? 'Collapse all' : 'Expand all'}
|
|
243
|
+
>
|
|
244
|
+
{hierarchical.isAllExpanded ? (
|
|
245
|
+
<ChevronDown className="h-4 w-4" />
|
|
246
|
+
) : (
|
|
247
|
+
<ChevronRight className="h-4 w-4" />
|
|
248
|
+
)}
|
|
249
|
+
</Button>
|
|
250
|
+
</th>
|
|
251
|
+
)}
|
|
252
|
+
|
|
253
|
+
{headerGroup.headers.map((header) => {
|
|
254
|
+
const isSortable = header.column.getCanSort();
|
|
255
|
+
const ariaSort = isSortable
|
|
256
|
+
? (header.column.getIsSorted() === 'asc'
|
|
257
|
+
? 'ascending'
|
|
258
|
+
: header.column.getIsSorted() === 'desc'
|
|
259
|
+
? 'descending'
|
|
260
|
+
: 'none')
|
|
261
|
+
: undefined;
|
|
262
|
+
return (
|
|
263
|
+
<th
|
|
264
|
+
key={header.id}
|
|
265
|
+
{...(isSortable ? { 'aria-sort': ariaSort } : {})}
|
|
266
|
+
>
|
|
267
|
+
{header.isPlaceholder ? null : (
|
|
268
|
+
isSortable ? (
|
|
269
|
+
<Button
|
|
270
|
+
variant="ghost"
|
|
271
|
+
className="h-auto p-0 font-medium hover:bg-transparent"
|
|
272
|
+
onClick={header.column.getToggleSortingHandler()}
|
|
273
|
+
aria-label={`Sort by ${typeof header.column.columnDef.header === 'string' ? header.column.columnDef.header : 'column'}`}
|
|
274
|
+
tabIndex={0}
|
|
275
|
+
>
|
|
276
|
+
<div className="flex items-center gap-1">
|
|
277
|
+
{typeof header.column.columnDef.header === 'function'
|
|
278
|
+
? header.column.columnDef.header(header.getContext())
|
|
279
|
+
: header.column.columnDef.header}
|
|
280
|
+
{header.column.getIsSorted() === 'asc' ? (
|
|
281
|
+
<ChevronUp className="h-4 w-4" />
|
|
282
|
+
) : header.column.getIsSorted() === 'desc' ? (
|
|
283
|
+
<ChevronDown className="h-4 w-4" />
|
|
284
|
+
) : (
|
|
285
|
+
<ChevronsUpDown className="h-4 w-4" />
|
|
286
|
+
)}
|
|
287
|
+
</div>
|
|
288
|
+
</Button>
|
|
289
|
+
) : (
|
|
290
|
+
<div>
|
|
291
|
+
{typeof header.column.columnDef.header === 'function'
|
|
292
|
+
? header.column.columnDef.header(header.getContext())
|
|
293
|
+
: header.column.columnDef.header}
|
|
294
|
+
</div>
|
|
295
|
+
)
|
|
296
|
+
)}
|
|
297
|
+
</th>
|
|
298
|
+
);
|
|
299
|
+
})}
|
|
300
|
+
</tr>
|
|
301
|
+
))}
|
|
302
|
+
</thead>
|
|
303
|
+
|
|
304
|
+
{/* Table Body */}
|
|
305
|
+
<tbody>
|
|
306
|
+
{/* Creation Row */}
|
|
307
|
+
{isCreating && (
|
|
308
|
+
<tr>
|
|
309
|
+
{table.getVisibleFlatColumns().map((column) => (
|
|
310
|
+
<td key={column.id}>
|
|
311
|
+
{renderEditField(column, creationData[column.id], (value) => {
|
|
312
|
+
if (typeof value === 'object' && value !== null) {
|
|
313
|
+
// Handle editAccessorKey case
|
|
314
|
+
onCreationDataChange({ ...creationData, ...value });
|
|
315
|
+
} else {
|
|
316
|
+
// Handle simple value case
|
|
317
|
+
onCreationDataChange({ ...creationData, [column.id]: value });
|
|
318
|
+
}
|
|
319
|
+
}, creationData)}
|
|
320
|
+
</td>
|
|
321
|
+
))}
|
|
322
|
+
<td className="flex gap-1">
|
|
323
|
+
<>
|
|
324
|
+
<button
|
|
325
|
+
onClick={onSaveCreation}
|
|
326
|
+
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"
|
|
327
|
+
title="Save new row"
|
|
328
|
+
>
|
|
329
|
+
<svg className="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
330
|
+
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M5 13l4 4L19 7" />
|
|
331
|
+
</svg>
|
|
332
|
+
</button>
|
|
333
|
+
<button
|
|
334
|
+
onClick={onCancelCreation}
|
|
335
|
+
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"
|
|
336
|
+
title="Cancel new row"
|
|
337
|
+
>
|
|
338
|
+
<svg className="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
339
|
+
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />
|
|
340
|
+
</svg>
|
|
341
|
+
</button>
|
|
342
|
+
</>
|
|
343
|
+
</td>
|
|
344
|
+
</tr>
|
|
345
|
+
)}
|
|
346
|
+
|
|
347
|
+
{/* Table Rows */}
|
|
348
|
+
{table.getRowModel().rows.length === 0 && (
|
|
349
|
+
<tr>
|
|
350
|
+
<td colSpan={table.getVisibleFlatColumns().length} role="status">
|
|
351
|
+
<EmptyState
|
|
352
|
+
title={emptyState?.title}
|
|
353
|
+
description={emptyState?.description}
|
|
354
|
+
icon={emptyState?.icon}
|
|
355
|
+
action={emptyState?.action}
|
|
356
|
+
isFiltered={isFiltered}
|
|
357
|
+
onClearFilters={onClearFilters}
|
|
358
|
+
/>
|
|
359
|
+
</td>
|
|
360
|
+
</tr>
|
|
361
|
+
)}
|
|
362
|
+
|
|
363
|
+
{table.getRowModel().rows.map((row) => {
|
|
364
|
+
const rowId = getRowId ? getRowId(row.original, row.index) : String(row.index);
|
|
365
|
+
const isEditing = editingRowId === rowId;
|
|
366
|
+
|
|
367
|
+
// Handle grouped rows
|
|
368
|
+
if (row.getIsGrouped()) {
|
|
369
|
+
const groupValue = row.getValue(grouping[0]);
|
|
370
|
+
const subRowsCount = row.subRows?.length || 0;
|
|
371
|
+
const isExpanded = row.getIsExpanded();
|
|
372
|
+
|
|
373
|
+
return (
|
|
374
|
+
<React.Fragment key={row.id}>
|
|
375
|
+
{/* Group Header Row */}
|
|
376
|
+
<tr className="bg-app-sec-50 hover:bg-app-sec-100">
|
|
377
|
+
<td className="flex items-center py-2 font-medium" colSpan={table.getAllColumns().length}>
|
|
378
|
+
<>
|
|
379
|
+
<Button
|
|
380
|
+
variant="ghost"
|
|
381
|
+
size="sm"
|
|
382
|
+
onClick={() => row.toggleExpanded()}
|
|
383
|
+
className="p-0 h-auto mr-2"
|
|
384
|
+
>
|
|
385
|
+
{isExpanded ? (
|
|
386
|
+
<ChevronDown className="h-4 w-4" />
|
|
387
|
+
) : (
|
|
388
|
+
<ChevronRight className="h-4 w-4" />
|
|
389
|
+
)}
|
|
390
|
+
</Button>
|
|
391
|
+
<span className="text-sm">
|
|
392
|
+
{String(groupValue)} ({subRowsCount} items)
|
|
393
|
+
</span>
|
|
394
|
+
</>
|
|
395
|
+
</td>
|
|
396
|
+
</tr>
|
|
397
|
+
|
|
398
|
+
{/* Render sub-rows if expanded */}
|
|
399
|
+
{isExpanded && row.subRows?.map((subRow) => {
|
|
400
|
+
const subRowId = getRowId ? getRowId(subRow.original, subRow.index) : String(subRow.index);
|
|
401
|
+
const isSubRowEditing = editingRowId === subRowId;
|
|
402
|
+
|
|
403
|
+
return (
|
|
404
|
+
<tr key={subRow.id} className="border-l-2 border-l-blue-200">
|
|
405
|
+
{subRow.getVisibleCells().map((cell) => (
|
|
406
|
+
<td key={cell.id} className="pl-8">
|
|
407
|
+
{isSubRowEditing && cell.column.id !== 'actions' ? (
|
|
408
|
+
renderEditField(cell.column, editingData[cell.column.id], (value) => {
|
|
409
|
+
if (typeof value === 'object' && value !== null) {
|
|
410
|
+
// Handle editAccessorKey case
|
|
411
|
+
onEditingDataChange({ ...editingData, ...value });
|
|
412
|
+
} else {
|
|
413
|
+
// Handle simple value case
|
|
414
|
+
onEditingDataChange({ ...editingData, [cell.column.id]: value });
|
|
415
|
+
}
|
|
416
|
+
}, editingData)
|
|
417
|
+
) : (
|
|
418
|
+
flexRender(cell.column.columnDef.cell, cell.getContext())
|
|
419
|
+
)}
|
|
420
|
+
</td>
|
|
421
|
+
))}
|
|
422
|
+
</tr>
|
|
423
|
+
);
|
|
424
|
+
})}
|
|
425
|
+
</React.Fragment>
|
|
426
|
+
);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
// Skip leaf rows when grouping is enabled - they're already rendered as sub-rows
|
|
430
|
+
// A row is a leaf if it has a parent (part of a group) and is not itself a group header
|
|
431
|
+
if (grouping.length > 0 && typeof row.getParentRow === 'function' && row.getParentRow() && !row.getIsGrouped()) {
|
|
432
|
+
return null;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
// Regular row (non-grouped or when grouping is disabled)
|
|
436
|
+
return (
|
|
437
|
+
<tr key={row.id}>
|
|
438
|
+
{row.getVisibleCells().map((cell) => (
|
|
439
|
+
<td key={cell.id}>
|
|
440
|
+
{isEditing && cell.column.id !== 'actions' ? (
|
|
441
|
+
renderEditField(cell.column, editingData[cell.column.id], (value) => {
|
|
442
|
+
if (typeof value === 'object' && value !== null) {
|
|
443
|
+
// Handle editAccessorKey case
|
|
444
|
+
onEditingDataChange({ ...editingData, ...value });
|
|
445
|
+
} else {
|
|
446
|
+
// Handle simple value case
|
|
447
|
+
onEditingDataChange({ ...editingData, [cell.column.id]: value });
|
|
448
|
+
}
|
|
449
|
+
}, editingData)
|
|
450
|
+
) : (
|
|
451
|
+
flexRender(cell.column.columnDef.cell, cell.getContext())
|
|
452
|
+
)}
|
|
453
|
+
</td>
|
|
454
|
+
))}
|
|
455
|
+
</tr>
|
|
456
|
+
);
|
|
457
|
+
})}
|
|
458
|
+
</tbody>
|
|
459
|
+
</>
|
|
460
|
+
);
|
|
461
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
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
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { ColumnFilter } from './ColumnFilter';
|
|
3
3
|
import type { Header, Table } from '@tanstack/react-table';
|
|
4
|
+
import { getColumnHeaderText } from '../utils/columnUtils';
|
|
4
5
|
|
|
5
6
|
interface FilterRowProps<TData> {
|
|
6
7
|
table: Table<TData>;
|
|
@@ -52,10 +53,15 @@ export function FilterRow<TData>({ table, visibleColumns }: FilterRowProps<TData
|
|
|
52
53
|
|
|
53
54
|
// PRIORITY 1: Check if column has explicit filter type configuration
|
|
54
55
|
// This MUST be checked first and must respect any explicit value, including 'text'
|
|
55
|
-
//
|
|
56
|
+
// Check for valid filter type strings explicitly to prevent any edge cases
|
|
56
57
|
// This prevents auto-detection from overriding explicit filterType settings
|
|
57
58
|
const explicitFilterType = columnDef.filterType;
|
|
58
|
-
if (
|
|
59
|
+
if (
|
|
60
|
+
explicitFilterType === 'text' ||
|
|
61
|
+
explicitFilterType === 'select' ||
|
|
62
|
+
explicitFilterType === 'number' ||
|
|
63
|
+
explicitFilterType === 'date'
|
|
64
|
+
) {
|
|
59
65
|
// Explicit filterType set - return it immediately (no auto-detection)
|
|
60
66
|
// This ensures filterType: 'text' is always respected, even for columns with ≤10 unique values
|
|
61
67
|
return explicitFilterType as 'text' | 'select' | 'number' | 'date';
|
|
@@ -108,7 +114,7 @@ export function FilterRow<TData>({ table, visibleColumns }: FilterRowProps<TData
|
|
|
108
114
|
column={column}
|
|
109
115
|
filterType={filterType}
|
|
110
116
|
options={options}
|
|
111
|
-
placeholder={`Filter ${column
|
|
117
|
+
placeholder={`Filter ${getColumnHeaderText(column)}...`}
|
|
112
118
|
/>
|
|
113
119
|
) : (
|
|
114
120
|
<div className="h-8 flex items-center text-sec-400 text-sm">
|
|
@@ -108,6 +108,7 @@ export function PaginationControls<TData extends DataRecord>({
|
|
|
108
108
|
selectedText={currentPageSize?.toString() || '10'}
|
|
109
109
|
onValueChange={(value) => setPageSize(Number(value))}
|
|
110
110
|
disabled={isLoading}
|
|
111
|
+
direction="up"
|
|
111
112
|
className="w-36 h-8"
|
|
112
113
|
>
|
|
113
114
|
|