@goplusvn/core 0.1.0 → 0.1.1
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/package.json +2 -1
- package/src/assets/erp_wallpaper.png +0 -0
- package/src/assets/goeat_logo.png +0 -0
- package/src/audit/audit-manager.ts +139 -0
- package/src/audit/index.ts +11 -0
- package/src/audit/memory-audit-logger.ts +86 -0
- package/src/audit/types.ts +50 -0
- package/src/auth/auth-service.ts +97 -0
- package/src/auth/index.ts +266 -0
- package/src/code-generation/index.ts +69 -0
- package/src/configs/auth-routes.ts +17 -0
- package/src/configs/crud.ts +136 -0
- package/src/configs/data/navigations.ts +781 -0
- package/src/configs/data/oauth-links.ts +10 -0
- package/src/configs/entities/material-categories.config.ts +125 -0
- package/src/configs/i18n.ts +12 -0
- package/src/configs/index.ts +26 -0
- package/src/configs/status.ts +25 -0
- package/src/configs/themes.ts +100 -0
- package/src/crud/components/crud-bulk-actions.tsx +91 -0
- package/src/crud/components/crud-card-view.tsx +241 -0
- package/src/crud/components/crud-context.tsx +122 -0
- package/src/crud/components/crud-delete-dialog.tsx +145 -0
- package/src/crud/components/crud-dialog.tsx +406 -0
- package/src/crud/components/crud-empty-state.tsx +104 -0
- package/src/crud/components/crud-export-button.tsx +170 -0
- package/src/crud/components/crud-field-renderer.tsx +653 -0
- package/src/crud/components/crud-filter-chips.tsx +102 -0
- package/src/crud/components/crud-filters/checkbox-filter.tsx +97 -0
- package/src/crud/components/crud-filters/datetime-filter.tsx +83 -0
- package/src/crud/components/crud-filters/filter-builder.tsx +66 -0
- package/src/crud/components/crud-filters/index.tsx +76 -0
- package/src/crud/components/crud-filters/radio-filter.tsx +86 -0
- package/src/crud/components/crud-filters/select-filter.tsx +141 -0
- package/src/crud/components/crud-filters/text-filter.tsx +86 -0
- package/src/crud/components/crud-form.tsx +642 -0
- package/src/crud/components/crud-import-dialog.tsx +440 -0
- package/src/crud/components/crud-infinite-scroll.tsx +116 -0
- package/src/crud/components/crud-page.tsx +1017 -0
- package/src/crud/components/crud-provider.tsx +277 -0
- package/src/crud/components/crud-row-actions.tsx +189 -0
- package/src/crud/components/crud-search.tsx +82 -0
- package/src/crud/components/crud-sheet.tsx +336 -0
- package/src/crud/components/crud-table-skeleton.tsx +26 -0
- package/src/crud/components/crud-table-toolbar.tsx +91 -0
- package/src/crud/components/crud-table.tsx +352 -0
- package/src/crud/components/crud-virtual-table.tsx +55 -0
- package/src/crud/components/index.tsx +20 -0
- package/src/crud/crud-filters/checkbox-filter.tsx +87 -0
- package/src/crud/crud-filters/datetime-filter.tsx +82 -0
- package/src/crud/crud-filters/filter-builder.tsx +64 -0
- package/src/crud/crud-filters/index.tsx +78 -0
- package/src/crud/crud-filters/radio-filter.tsx +79 -0
- package/src/crud/crud-filters/select-filter.tsx +148 -0
- package/src/crud/crud-filters/text-filter.tsx +81 -0
- package/src/crud/index.ts +43 -0
- package/src/crud/lib/crud-service.test.ts +334 -0
- package/src/crud/lib/crud-service.ts +358 -0
- package/src/crud/lib/crud-utils.test.ts +354 -0
- package/src/crud/lib/crud-utils.ts +299 -0
- package/src/crud/lib/crud-validator.ts +247 -0
- package/src/crud/lib/data-loader.ts +234 -0
- package/src/crud/lib/field-calculator.ts +241 -0
- package/src/crud/lib/field-formatter.ts +240 -0
- package/src/crud/lib/import-export-service.test.ts +290 -0
- package/src/crud/lib/import-export-service.ts +352 -0
- package/src/crud/lib/import-server-utils.ts +109 -0
- package/src/crud/lib/lazy-loader.ts +241 -0
- package/src/crud/lib/parse-filters.ts +85 -0
- package/src/crud/lib/permissions.ts +52 -0
- package/src/crud/lib/serialize-config.ts +60 -0
- package/src/crud/lib/stream-loader.ts +145 -0
- package/src/crud/lib/translate-config.ts +335 -0
- package/src/crud/lib/types.ts +11 -0
- package/src/crud/pages/entity-crud-page.tsx +144 -0
- package/src/crud/server.ts +8 -0
- package/src/home/constants.tsx +142 -0
- package/src/home/feature-showcase.tsx +171 -0
- package/src/home/home-page.tsx +191 -0
- package/src/home/hooks/index.ts +1 -0
- package/src/home/hooks/useWidgetPreferences.ts +167 -0
- package/src/home/index.ts +33 -0
- package/src/home/quick-access-dialog.tsx +271 -0
- package/src/home/quick-access-menu.tsx +267 -0
- package/src/home/types.ts +140 -0
- package/src/home/welcome-card.tsx +92 -0
- package/src/home/widget-container.tsx +258 -0
- package/src/home/widgets/base-widget.tsx +200 -0
- package/src/home/widgets/customers-widget.tsx +74 -0
- package/src/home/widgets/index.ts +6 -0
- package/src/home/widgets/orders-widget.tsx +87 -0
- package/src/home/widgets/revenue-widget.tsx +71 -0
- package/src/home/widgets/stock-widget.tsx +109 -0
- package/src/hooks/index.tsx +598 -0
- package/src/hooks/use-tenant.test.tsx +30 -0
- package/src/hooks/use-tenant.ts +5 -0
- package/src/index.ts +17 -0
- package/src/infrastructure/__tests__/architecture-verification.spec.ts +103 -0
- package/src/infrastructure/api-service.ts +317 -0
- package/src/infrastructure/cache/cache-manager.ts +107 -0
- package/src/infrastructure/cache/cache.ts +120 -0
- package/src/infrastructure/cache/index.ts +8 -0
- package/src/infrastructure/cache/types.ts +48 -0
- package/src/infrastructure/cron/cron-manager.ts +239 -0
- package/src/infrastructure/cron/index.ts +6 -0
- package/src/infrastructure/cron/types.ts +41 -0
- package/src/infrastructure/event-bus/event-bus.ts +145 -0
- package/src/infrastructure/event-bus/index.ts +2 -0
- package/src/infrastructure/event-bus/types.ts +22 -0
- package/src/infrastructure/index.ts +32 -0
- package/src/infrastructure/lock/decorators.ts +67 -0
- package/src/infrastructure/lock/index.ts +2 -0
- package/src/infrastructure/lock/lock-manager.ts +33 -0
- package/src/infrastructure/logger/index.ts +2 -0
- package/src/infrastructure/logger/logger.ts +96 -0
- package/src/infrastructure/logger/types.ts +25 -0
- package/src/layout/index.tsx +185 -0
- package/src/navigation/index.ts +91 -0
- package/src/notification/index.ts +14 -0
- package/src/notification/notification-service.ts +120 -0
- package/src/notification/storage/in-memory.ts +56 -0
- package/src/notification/storage/index.ts +1 -0
- package/src/notification/types.ts +51 -0
- package/src/organization/branch-service.ts +299 -0
- package/src/organization/branches.config.ts +154 -0
- package/src/organization/index.ts +5 -0
- package/src/plugin/apps-registry.ts +97 -0
- package/src/plugin/index.ts +5 -0
- package/src/plugin/types.ts +41 -0
- package/src/providers/index.tsx +109 -0
- package/src/providers/tenant-provider.tsx +45 -0
- package/src/rbac/components/roles/role-card.tsx +158 -0
- package/src/rbac/components/roles/role-stats-cards.tsx +29 -0
- package/src/rbac/components/roles/role-toolbar.tsx +123 -0
- package/src/rbac/hooks/use-role-operations.ts +159 -0
- package/src/rbac/hooks/use-roles-data.ts +59 -0
- package/src/rbac/index.ts +297 -0
- package/src/rbac/lib/permission-helpers.ts +63 -0
- package/src/rbac/pages/action-list-page.tsx +25 -0
- package/src/rbac/pages/resource-list-page.tsx +25 -0
- package/src/rbac/pages/role-list-page.tsx +378 -0
- package/src/rbac/permission-service.ts +140 -0
- package/src/rbac/permissions.ts +135 -0
- package/src/rbac/resource-service.ts +115 -0
- package/src/rbac/resource-validator.ts +119 -0
- package/src/rbac/role-service.ts +165 -0
- package/src/rbac/server.ts +16 -0
- package/src/rbac/types.ts +38 -0
- package/src/schemas/action.schema.ts +66 -0
- package/src/schemas/branch.schema.ts +52 -0
- package/src/schemas/coming-soon-schema.ts +9 -0
- package/src/schemas/company.schema.ts +44 -0
- package/src/schemas/forgot-passward-schema.ts +9 -0
- package/src/schemas/index.ts +30 -0
- package/src/schemas/material-category.schema.ts +43 -0
- package/src/schemas/material-pricing.schema.ts +74 -0
- package/src/schemas/material.schema.ts +76 -0
- package/src/schemas/materials.ts +52 -0
- package/src/schemas/new-passward-schema.ts +15 -0
- package/src/schemas/partner-company.schema.ts +149 -0
- package/src/schemas/register-schema.ts +36 -0
- package/src/schemas/resource.schema.ts +133 -0
- package/src/schemas/role.schema.ts +11 -0
- package/src/schemas/sign-in-schema.ts +24 -0
- package/src/schemas/supplier-pricing.schema.ts +15 -0
- package/src/schemas/supplier.schema.ts +120 -0
- package/src/schemas/system-category-group.schema.ts +67 -0
- package/src/schemas/system-category.schema.ts +77 -0
- package/src/schemas/system-config.schema.ts +118 -0
- package/src/schemas/uom.schema.ts +75 -0
- package/src/schemas/user-supplier.schema.ts +179 -0
- package/src/schemas/user.schema.ts +18 -0
- package/src/schemas/verify-email-schema.ts +9 -0
- package/src/schemas/warehouse.schema.ts +49 -0
- package/src/system/components/categories/category-list.tsx +529 -0
- package/src/system/components/categories/category-manager.tsx +89 -0
- package/src/system/components/categories/group-sidebar.tsx +308 -0
- package/src/system/components/settings/setting-dialogs.tsx +197 -0
- package/src/system/components/settings/setting-field.tsx +291 -0
- package/src/system/components/settings/setting-form-dialog.tsx +308 -0
- package/src/system/components/settings/settings-groups.ts +80 -0
- package/src/system/components/settings/settings-search.tsx +71 -0
- package/src/system/components/settings/settings-section.tsx +74 -0
- package/src/system/components/settings/settings-sidebar.tsx +81 -0
- package/src/system/constants.ts +3 -0
- package/src/system/index.ts +150 -0
- package/src/system/job-manager.ts +176 -0
- package/src/system/pages/components/categories/category-list.tsx +537 -0
- package/src/system/pages/components/categories/category-manager.tsx +90 -0
- package/src/system/pages/components/categories/group-sidebar.tsx +311 -0
- package/src/system/pages/components/settings/sales-rules-settings.tsx +222 -0
- package/src/system/pages/components/settings/setting-dialogs.tsx +197 -0
- package/src/system/pages/components/settings/setting-field.tsx +292 -0
- package/src/system/pages/components/settings/setting-form-dialog.tsx +308 -0
- package/src/system/pages/components/settings/settings-groups.ts +87 -0
- package/src/system/pages/components/settings/settings-page.tsx +372 -0
- package/src/system/pages/components/settings/settings-search.tsx +71 -0
- package/src/system/pages/components/settings/settings-section.tsx +74 -0
- package/src/system/pages/components/settings/settings-sidebar.tsx +81 -0
- package/src/system/pages/components/settings/system-settings.tsx +244 -0
- package/src/system/pages/system-category-page.tsx +15 -0
- package/src/system/pages/system-settings-page.tsx +380 -0
- package/src/system/schemas/system-category-group.schema.ts +46 -0
- package/src/system/schemas/system-category.schema.ts +56 -0
- package/src/system/services/settings-service.ts +127 -0
- package/src/system/services/system-category-service.ts +63 -0
- package/src/system/types.ts +45 -0
- package/src/types/index.ts +703 -0
- package/src/ui/auth/auth-layout.tsx +135 -0
- package/src/ui/auth/forgot-password-form.tsx +98 -0
- package/src/ui/auth/index.tsx +7 -0
- package/src/ui/auth/new-password-form.tsx +107 -0
- package/src/ui/auth/oauth-links.tsx +30 -0
- package/src/ui/auth/register-form.tsx +202 -0
- package/src/ui/auth/sign-in-form.tsx +238 -0
- package/src/ui/auth/verify-email-form.tsx +104 -0
- package/src/ui/crud/index.tsx +10 -0
- package/src/ui/data-display/accordion.tsx +65 -0
- package/src/ui/data-display/aspect-ratio.tsx +11 -0
- package/src/ui/data-display/avatar.tsx +163 -0
- package/src/ui/data-display/bento-grid.tsx +77 -0
- package/src/ui/data-display/carousel.tsx +249 -0
- package/src/ui/data-display/chart.tsx +363 -0
- package/src/ui/data-display/code-block-highlight.tsx +54 -0
- package/src/ui/data-display/collapsible.tsx +42 -0
- package/src/ui/data-display/compact-stat-bar.tsx +149 -0
- package/src/ui/data-display/data-table/data-table-context.tsx +255 -0
- package/src/ui/data-display/data-table/data-table-empty-state.tsx +133 -0
- package/src/ui/data-display/data-table/data-table-skeleton.tsx +145 -0
- package/src/ui/data-display/data-table/data-table-toolbar.tsx +353 -0
- package/src/ui/data-display/data-table/data-table.tsx +597 -0
- package/src/ui/data-display/data-table/index.ts +44 -0
- package/src/ui/data-display/data-table-column-header.tsx +75 -0
- package/src/ui/data-display/data-table-pagination.tsx +130 -0
- package/src/ui/data-display/data-table-view-options.tsx +59 -0
- package/src/ui/data-display/formatted-number-input.tsx +210 -0
- package/src/ui/data-display/highlight.tsx +20 -0
- package/src/ui/data-display/hover-card.tsx +48 -0
- package/src/ui/data-display/index.tsx +50 -0
- package/src/ui/data-display/iphone-15-pro.tsx +114 -0
- package/src/ui/data-display/kanban/index.ts +4 -0
- package/src/ui/data-display/kanban/kanban-board.tsx +192 -0
- package/src/ui/data-display/kanban/kanban-column.tsx +74 -0
- package/src/ui/data-display/kanban/kanban-item.tsx +50 -0
- package/src/ui/data-display/kanban/kanban-types.ts +21 -0
- package/src/ui/data-display/kpi-card.tsx +68 -0
- package/src/ui/data-display/media-grid.tsx +110 -0
- package/src/ui/data-display/safari.tsx +175 -0
- package/src/ui/data-display/show-more-text.tsx +55 -0
- package/src/ui/data-display/tabs.tsx +68 -0
- package/src/ui/data-display/timeline.tsx +256 -0
- package/src/ui/feedback/alert.tsx +60 -0
- package/src/ui/feedback/context-menu.tsx +245 -0
- package/src/ui/feedback/drawer.tsx +132 -0
- package/src/ui/feedback/error-dialog.tsx +273 -0
- package/src/ui/feedback/index.tsx +183 -0
- package/src/ui/feedback/progress.tsx +32 -0
- package/src/ui/feedback/sheet.tsx +148 -0
- package/src/ui/feedback/sonner.tsx +36 -0
- package/src/ui/forms/command.tsx +157 -0
- package/src/ui/forms/date-picker.tsx +73 -0
- package/src/ui/forms/date-range-picker.tsx +76 -0
- package/src/ui/forms/date-time-picker.tsx +109 -0
- package/src/ui/forms/editor/editor-menu-bar.tsx +394 -0
- package/src/ui/forms/editor/index.tsx +130 -0
- package/src/ui/forms/editor/multi-select-example.tsx +1234 -0
- package/src/ui/forms/emoji-picker.tsx +109 -0
- package/src/ui/forms/file-dropzone.tsx +169 -0
- package/src/ui/forms/file-thumbnail.tsx +29 -0
- package/src/ui/forms/index.tsx +201 -0
- package/src/ui/forms/input-file.tsx +99 -0
- package/src/ui/forms/input-group.tsx +46 -0
- package/src/ui/forms/input-otp.tsx +81 -0
- package/src/ui/forms/input-phone.tsx +172 -0
- package/src/ui/forms/input-spin.tsx +116 -0
- package/src/ui/forms/input-tags.tsx +219 -0
- package/src/ui/forms/input-time.tsx +42 -0
- package/src/ui/forms/multi-select.tsx +629 -0
- package/src/ui/forms/multiple-date-picker.tsx +74 -0
- package/src/ui/forms/radio-group.tsx +42 -0
- package/src/ui/forms/rating.tsx +158 -0
- package/src/ui/forms/time-picker.tsx +57 -0
- package/src/ui/index.tsx +17 -0
- package/src/ui/layout/animated-list.tsx +77 -0
- package/src/ui/layout/animated-sidebar.tsx +294 -0
- package/src/ui/layout/command-menu.tsx +355 -0
- package/src/ui/layout/customizer.tsx +324 -0
- package/src/ui/layout/footer.tsx +43 -0
- package/src/ui/layout/full-screen-toggle.tsx +52 -0
- package/src/ui/layout/header-breadcrumb.tsx +77 -0
- package/src/ui/layout/horizontal-layout-header.tsx +83 -0
- package/src/ui/layout/horizontal-layout.tsx +50 -0
- package/src/ui/layout/index.tsx +25 -0
- package/src/ui/layout/language-dropdown.tsx +103 -0
- package/src/ui/layout/logo.tsx +63 -0
- package/src/ui/layout/main-layout.tsx +57 -0
- package/src/ui/layout/mode-dropdown.tsx +58 -0
- package/src/ui/layout/notification-dropdown.tsx +127 -0
- package/src/ui/layout/page-tabs.tsx +306 -0
- package/src/ui/layout/route-cache.tsx +214 -0
- package/src/ui/layout/sidebar-group-icon-menu.tsx +195 -0
- package/src/ui/layout/sidebar.tsx +279 -0
- package/src/ui/layout/tab-content-cache.tsx +201 -0
- package/src/ui/layout/tab-navigation-provider.tsx +536 -0
- package/src/ui/layout/toggle-mobile-sidebar.tsx +33 -0
- package/src/ui/layout/top-bar-header-menubar.tsx +412 -0
- package/src/ui/layout/user-dropdown.tsx +188 -0
- package/src/ui/layout/vertical-layout-header.tsx +65 -0
- package/src/ui/layout/vertical-layout.tsx +47 -0
- package/src/ui/management/audit-log-page.tsx +209 -0
- package/src/ui/management/cache-management.tsx +349 -0
- package/src/ui/management/index.ts +3 -0
- package/src/ui/management/job-management.tsx +308 -0
- package/src/ui/pages/not-found.tsx +30 -0
- package/src/ui/primitives/badge.tsx +66 -0
- package/src/ui/primitives/breadcrumb.tsx +103 -0
- package/src/ui/primitives/button.tsx +129 -0
- package/src/ui/primitives/calendar.tsx +74 -0
- package/src/ui/primitives/card.tsx +86 -0
- package/src/ui/primitives/checkbox.tsx +31 -0
- package/src/ui/primitives/client.ts +30 -0
- package/src/ui/primitives/combobox.tsx +290 -0
- package/src/ui/primitives/dialog.tsx +121 -0
- package/src/ui/primitives/dropdown-menu.tsx +239 -0
- package/src/ui/primitives/dynamic-icon.tsx +24 -0
- package/src/ui/primitives/index.tsx +134 -0
- package/src/ui/primitives/input-number.tsx +131 -0
- package/src/ui/primitives/input.tsx +22 -0
- package/src/ui/primitives/keyboard.tsx +23 -0
- package/src/ui/primitives/label.tsx +24 -0
- package/src/ui/primitives/menubar.tsx +262 -0
- package/src/ui/primitives/navigation-menu.tsx +157 -0
- package/src/ui/primitives/pagination.tsx +118 -0
- package/src/ui/primitives/popover.tsx +56 -0
- package/src/ui/primitives/prefetch-link.tsx +60 -0
- package/src/ui/primitives/resizable.tsx +59 -0
- package/src/ui/primitives/scroll-area.tsx +63 -0
- package/src/ui/primitives/select.tsx +172 -0
- package/src/ui/primitives/separator.tsx +51 -0
- package/src/ui/primitives/sidebar.tsx +844 -0
- package/src/ui/primitives/slider.tsx +27 -0
- package/src/ui/primitives/status-badge.tsx +47 -0
- package/src/ui/primitives/sticky-layout.tsx +50 -0
- package/src/ui/primitives/switch.tsx +29 -0
- package/src/ui/primitives/table.tsx +116 -0
- package/src/ui/primitives/tabs.tsx +55 -0
- package/src/ui/primitives/toggle-group.tsx +70 -0
- package/src/ui/primitives/toggle.tsx +47 -0
- package/src/ui/primitives/tooltip.tsx +59 -0
- package/src/user/components/dangerous-zone.tsx +34 -0
- package/src/user/components/delete-account-form.tsx +40 -0
- package/src/user/components/index.ts +4 -0
- package/src/user/components/profile-info-form.tsx +390 -0
- package/src/user/components/profile-info.tsx +32 -0
- package/src/user/components/unified-profile-dialog.tsx +1019 -0
- package/src/user/components/user-stats.tsx +27 -0
- package/src/user/components/user-toolbar.tsx +137 -0
- package/src/user/components/users-card-view.tsx +253 -0
- package/src/user/index.ts +11 -0
- package/src/user/pages/user-list-page.tsx +234 -0
- package/src/user/pages/users-client-page.tsx +385 -0
- package/src/user/profile-page.tsx +19 -0
- package/src/user/schemas.ts +68 -0
- package/src/user/types.ts +34 -0
- package/src/user/user-service.ts +538 -0
- package/src/utils/index.ts +906 -0
- package/src/workflow/activity-timeline.tsx +412 -0
- package/src/workflow/approval-workflow.tsx +31 -0
- package/src/workflow/index.ts +2 -0
|
@@ -0,0 +1,597 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { memo, useCallback, useEffect, useMemo } from "react";
|
|
4
|
+
import type { ReactNode, ReactElement } from "react";
|
|
5
|
+
import {
|
|
6
|
+
flexRender,
|
|
7
|
+
getCoreRowModel,
|
|
8
|
+
getFilteredRowModel,
|
|
9
|
+
getPaginationRowModel,
|
|
10
|
+
getSortedRowModel,
|
|
11
|
+
useReactTable,
|
|
12
|
+
} from "@tanstack/react-table";
|
|
13
|
+
import type {
|
|
14
|
+
ColumnDef,
|
|
15
|
+
SortingState as TanstackSortingState,
|
|
16
|
+
Table,
|
|
17
|
+
Row,
|
|
18
|
+
} from "@tanstack/react-table";
|
|
19
|
+
|
|
20
|
+
import { Checkbox } from "../../primitives/client";
|
|
21
|
+
import {
|
|
22
|
+
TableBody,
|
|
23
|
+
TableCell,
|
|
24
|
+
TableHead,
|
|
25
|
+
TableHeader,
|
|
26
|
+
TableRow,
|
|
27
|
+
} from "../../primitives";
|
|
28
|
+
import { DataTablePagination } from "../data-table-pagination";
|
|
29
|
+
import { DataTableSkeleton } from "./data-table-skeleton";
|
|
30
|
+
import { DataTableEmptyState } from "./data-table-empty-state";
|
|
31
|
+
import type { SortingState, PaginationState } from "./data-table-context";
|
|
32
|
+
|
|
33
|
+
// ============================================================================
|
|
34
|
+
// Types
|
|
35
|
+
// ============================================================================
|
|
36
|
+
|
|
37
|
+
export interface DataTablePaginationConfig {
|
|
38
|
+
page: number;
|
|
39
|
+
pageSize: number;
|
|
40
|
+
total: number;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface DataTableProps<TData> {
|
|
44
|
+
/**
|
|
45
|
+
* Data to display in the table
|
|
46
|
+
*/
|
|
47
|
+
data: TData[];
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Column definitions for the table
|
|
51
|
+
*/
|
|
52
|
+
columns: ColumnDef<TData>[];
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Pagination configuration (controlled)
|
|
56
|
+
*/
|
|
57
|
+
pagination?: DataTablePaginationConfig;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Callback when pagination changes
|
|
61
|
+
*/
|
|
62
|
+
onPaginationChange?: (pagination: PaginationState) => void;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Current sorting state (controlled)
|
|
66
|
+
*/
|
|
67
|
+
sorting?: SortingState | null;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Callback when sorting changes
|
|
71
|
+
*/
|
|
72
|
+
onSortingChange?: (sorting: SortingState | null) => void;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Enable row selection with checkboxes
|
|
76
|
+
* @default false
|
|
77
|
+
*/
|
|
78
|
+
enableRowSelection?: boolean;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Currently selected row IDs
|
|
82
|
+
*/
|
|
83
|
+
selectedRows?: Set<string>;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Callback when selection changes
|
|
87
|
+
*/
|
|
88
|
+
onSelectionChange?: (selectedRows: Set<string>) => void;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Function to get unique ID from row data
|
|
92
|
+
* @default (row) => row.id
|
|
93
|
+
*/
|
|
94
|
+
getRowId?: (row: TData) => string;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Show row numbers (STT column)
|
|
98
|
+
* @default false
|
|
99
|
+
*/
|
|
100
|
+
enableRowNumber?: boolean;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Whether data is loading
|
|
104
|
+
* @default false
|
|
105
|
+
*/
|
|
106
|
+
loading?: boolean;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Custom empty state component
|
|
110
|
+
*/
|
|
111
|
+
emptyState?: ReactNode;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Empty state configuration
|
|
115
|
+
*/
|
|
116
|
+
emptyStateConfig?: {
|
|
117
|
+
hasSearch?: boolean;
|
|
118
|
+
hasFilters?: boolean;
|
|
119
|
+
onClearSearch?: () => void;
|
|
120
|
+
onClearFilters?: () => void;
|
|
121
|
+
onCreate?: () => void;
|
|
122
|
+
createLabel?: string;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Callback when table instance is ready
|
|
127
|
+
*/
|
|
128
|
+
onTableReady?: (table: Table<TData>) => void;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Custom row click handler
|
|
132
|
+
*/
|
|
133
|
+
onRowClick?: (row: TData) => void;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Custom class name for the table container
|
|
137
|
+
*/
|
|
138
|
+
className?: string;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Height configuration
|
|
142
|
+
* @default "auto"
|
|
143
|
+
*/
|
|
144
|
+
height?: "auto" | "full" | string;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// ============================================================================
|
|
148
|
+
// DataTable Component
|
|
149
|
+
// ============================================================================
|
|
150
|
+
|
|
151
|
+
export function DataTable<TData extends Record<string, unknown>>({
|
|
152
|
+
data,
|
|
153
|
+
columns: userColumns,
|
|
154
|
+
pagination,
|
|
155
|
+
onPaginationChange,
|
|
156
|
+
sorting,
|
|
157
|
+
onSortingChange,
|
|
158
|
+
enableRowSelection = false,
|
|
159
|
+
selectedRows = new Set(),
|
|
160
|
+
onSelectionChange,
|
|
161
|
+
getRowId = (row) => String((row as Record<string, unknown>).id),
|
|
162
|
+
enableRowNumber = false,
|
|
163
|
+
loading = false,
|
|
164
|
+
emptyState,
|
|
165
|
+
emptyStateConfig,
|
|
166
|
+
onTableReady,
|
|
167
|
+
onRowClick,
|
|
168
|
+
className,
|
|
169
|
+
height = "auto",
|
|
170
|
+
}: DataTableProps<TData>) {
|
|
171
|
+
// Build final columns with selection and row number if enabled
|
|
172
|
+
const columns = useMemo<ColumnDef<TData>[]>(() => {
|
|
173
|
+
const cols: ColumnDef<TData>[] = [];
|
|
174
|
+
|
|
175
|
+
// Selection column
|
|
176
|
+
if (enableRowSelection) {
|
|
177
|
+
cols.push({
|
|
178
|
+
id: "select",
|
|
179
|
+
header: ({ table }) => (
|
|
180
|
+
<Checkbox
|
|
181
|
+
checked={
|
|
182
|
+
table.getIsAllPageRowsSelected() ||
|
|
183
|
+
(table.getIsSomePageRowsSelected() && "indeterminate")
|
|
184
|
+
}
|
|
185
|
+
onCheckedChange={(value) => {
|
|
186
|
+
const rowIds = table
|
|
187
|
+
.getRowModel()
|
|
188
|
+
.rows.map((row) => getRowId(row.original));
|
|
189
|
+
|
|
190
|
+
if (onSelectionChange) {
|
|
191
|
+
if (value) {
|
|
192
|
+
onSelectionChange(new Set(rowIds));
|
|
193
|
+
} else {
|
|
194
|
+
onSelectionChange(new Set());
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
table.toggleAllPageRowsSelected(!!value);
|
|
198
|
+
}}
|
|
199
|
+
aria-label="Select all"
|
|
200
|
+
/>
|
|
201
|
+
),
|
|
202
|
+
cell: ({ row }) => {
|
|
203
|
+
const rowId = getRowId(row.original);
|
|
204
|
+
return (
|
|
205
|
+
<Checkbox
|
|
206
|
+
checked={selectedRows.has(rowId)}
|
|
207
|
+
onCheckedChange={() => {
|
|
208
|
+
if (onSelectionChange) {
|
|
209
|
+
const newSelection = new Set(selectedRows);
|
|
210
|
+
if (newSelection.has(rowId)) {
|
|
211
|
+
newSelection.delete(rowId);
|
|
212
|
+
} else {
|
|
213
|
+
newSelection.add(rowId);
|
|
214
|
+
}
|
|
215
|
+
onSelectionChange(newSelection);
|
|
216
|
+
}
|
|
217
|
+
row.toggleSelected(!row.getIsSelected());
|
|
218
|
+
}}
|
|
219
|
+
aria-label="Select row"
|
|
220
|
+
/>
|
|
221
|
+
);
|
|
222
|
+
},
|
|
223
|
+
enableSorting: false,
|
|
224
|
+
enableHiding: false,
|
|
225
|
+
size: 50,
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// Row number (STT) column
|
|
230
|
+
if (enableRowNumber) {
|
|
231
|
+
cols.push({
|
|
232
|
+
id: "stt",
|
|
233
|
+
header: () => (
|
|
234
|
+
<div className="font-semibold text-center text-sm">STT</div>
|
|
235
|
+
),
|
|
236
|
+
cell: ({ row }) => {
|
|
237
|
+
const rowIndex = row.index;
|
|
238
|
+
const currentPage = pagination?.page ?? 1;
|
|
239
|
+
const pageSize = pagination?.pageSize ?? 10;
|
|
240
|
+
const stt = (currentPage - 1) * pageSize + rowIndex + 1;
|
|
241
|
+
return <div className="text-center font-medium">{stt}</div>;
|
|
242
|
+
},
|
|
243
|
+
enableSorting: false,
|
|
244
|
+
enableHiding: false,
|
|
245
|
+
size: 70,
|
|
246
|
+
minSize: 60,
|
|
247
|
+
maxSize: 80,
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// Add user columns
|
|
252
|
+
cols.push(...userColumns);
|
|
253
|
+
|
|
254
|
+
return cols;
|
|
255
|
+
}, [
|
|
256
|
+
userColumns,
|
|
257
|
+
enableRowSelection,
|
|
258
|
+
enableRowNumber,
|
|
259
|
+
selectedRows,
|
|
260
|
+
onSelectionChange,
|
|
261
|
+
getRowId,
|
|
262
|
+
pagination?.page,
|
|
263
|
+
pagination?.pageSize,
|
|
264
|
+
]);
|
|
265
|
+
|
|
266
|
+
// Convert our sorting format to tanstack's format
|
|
267
|
+
const tanstackSorting = useMemo<TanstackSortingState>(() => {
|
|
268
|
+
if (!sorting) return [];
|
|
269
|
+
return [
|
|
270
|
+
{
|
|
271
|
+
id: sorting.field,
|
|
272
|
+
desc: sorting.direction === "desc",
|
|
273
|
+
},
|
|
274
|
+
];
|
|
275
|
+
}, [sorting]);
|
|
276
|
+
|
|
277
|
+
// Handle sorting change
|
|
278
|
+
const handleSortingChange = useCallback(
|
|
279
|
+
(updater: unknown) => {
|
|
280
|
+
const newSorting =
|
|
281
|
+
typeof updater === "function" ? updater(tanstackSorting) : updater;
|
|
282
|
+
|
|
283
|
+
if (onSortingChange) {
|
|
284
|
+
if (Array.isArray(newSorting) && newSorting.length > 0) {
|
|
285
|
+
const sort = newSorting[0];
|
|
286
|
+
onSortingChange({
|
|
287
|
+
field: sort.id,
|
|
288
|
+
direction: sort.desc ? "desc" : "asc",
|
|
289
|
+
});
|
|
290
|
+
} else {
|
|
291
|
+
onSortingChange(null);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
},
|
|
295
|
+
[tanstackSorting, onSortingChange],
|
|
296
|
+
);
|
|
297
|
+
|
|
298
|
+
// Handle pagination change
|
|
299
|
+
const handlePaginationChange = useCallback(
|
|
300
|
+
(updater: unknown) => {
|
|
301
|
+
if (!onPaginationChange || !pagination) return;
|
|
302
|
+
|
|
303
|
+
const currentPagination = {
|
|
304
|
+
pageIndex: pagination.page - 1,
|
|
305
|
+
pageSize: pagination.pageSize,
|
|
306
|
+
};
|
|
307
|
+
const newPagination =
|
|
308
|
+
typeof updater === "function" ? updater(currentPagination) : updater;
|
|
309
|
+
|
|
310
|
+
onPaginationChange({
|
|
311
|
+
page: newPagination.pageIndex + 1,
|
|
312
|
+
pageSize: newPagination.pageSize,
|
|
313
|
+
});
|
|
314
|
+
},
|
|
315
|
+
[pagination, onPaginationChange],
|
|
316
|
+
);
|
|
317
|
+
|
|
318
|
+
// Calculate page count
|
|
319
|
+
const pageCount = useMemo(() => {
|
|
320
|
+
if (!pagination) return 1;
|
|
321
|
+
const count = Math.ceil(pagination.total / pagination.pageSize);
|
|
322
|
+
return count > 0 ? count : 1;
|
|
323
|
+
}, [pagination]);
|
|
324
|
+
|
|
325
|
+
// Create table instance
|
|
326
|
+
const table = useReactTable({
|
|
327
|
+
data: Array.isArray(data) ? data : [],
|
|
328
|
+
columns,
|
|
329
|
+
getCoreRowModel: getCoreRowModel(),
|
|
330
|
+
getPaginationRowModel: getPaginationRowModel(),
|
|
331
|
+
onSortingChange: handleSortingChange,
|
|
332
|
+
getSortedRowModel: getSortedRowModel(),
|
|
333
|
+
getFilteredRowModel: getFilteredRowModel(),
|
|
334
|
+
state: {
|
|
335
|
+
sorting: tanstackSorting,
|
|
336
|
+
pagination: pagination
|
|
337
|
+
? {
|
|
338
|
+
pageIndex: pagination.page - 1,
|
|
339
|
+
pageSize: pagination.pageSize,
|
|
340
|
+
}
|
|
341
|
+
: undefined,
|
|
342
|
+
},
|
|
343
|
+
onPaginationChange: handlePaginationChange,
|
|
344
|
+
manualPagination: !!pagination,
|
|
345
|
+
pageCount,
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
// Notify parent when table is ready
|
|
349
|
+
useEffect(() => {
|
|
350
|
+
if (onTableReady && table) {
|
|
351
|
+
onTableReady(table);
|
|
352
|
+
}
|
|
353
|
+
}, [table, onTableReady]);
|
|
354
|
+
|
|
355
|
+
// Get rows safely
|
|
356
|
+
let rows: Row<TData>[] = [];
|
|
357
|
+
try {
|
|
358
|
+
const rowModel = table.getRowModel();
|
|
359
|
+
if (rowModel && Array.isArray(rowModel.rows)) {
|
|
360
|
+
rows = rowModel.rows;
|
|
361
|
+
}
|
|
362
|
+
} catch (error) {
|
|
363
|
+
console.error("Error getting row model:", error);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// Height class
|
|
367
|
+
const heightClass =
|
|
368
|
+
height === "auto"
|
|
369
|
+
? ""
|
|
370
|
+
: height === "full"
|
|
371
|
+
? "min-h-[calc(100vh-16rem)]"
|
|
372
|
+
: height;
|
|
373
|
+
|
|
374
|
+
return (
|
|
375
|
+
<div
|
|
376
|
+
className={`flex flex-col border border-border dark:border-slate-800 rounded-md overflow-hidden bg-card ${heightClass} ${className || ""}`}
|
|
377
|
+
>
|
|
378
|
+
{/* Table Container - Scrollable */}
|
|
379
|
+
<div className="flex-1 overflow-auto relative">
|
|
380
|
+
<table className="w-max min-w-full caption-bottom text-xs relative">
|
|
381
|
+
<TableHeader className="sticky top-0 z-20 bg-card">
|
|
382
|
+
{table.getHeaderGroups().map((headerGroup) => (
|
|
383
|
+
<TableRow
|
|
384
|
+
key={headerGroup.id}
|
|
385
|
+
className="border-b-2 border-border dark:border-slate-700 hover:bg-transparent"
|
|
386
|
+
>
|
|
387
|
+
{headerGroup.headers.map((header) => (
|
|
388
|
+
<TableHead
|
|
389
|
+
key={header.id}
|
|
390
|
+
className="text-xs font-semibold text-foreground py-2.5"
|
|
391
|
+
style={{
|
|
392
|
+
width: header.getSize(),
|
|
393
|
+
minWidth: header.column.columnDef.minSize,
|
|
394
|
+
maxWidth: header.column.columnDef.maxSize,
|
|
395
|
+
}}
|
|
396
|
+
>
|
|
397
|
+
{header.isPlaceholder
|
|
398
|
+
? null
|
|
399
|
+
: flexRender(
|
|
400
|
+
header.column.columnDef.header,
|
|
401
|
+
header.getContext(),
|
|
402
|
+
)}
|
|
403
|
+
</TableHead>
|
|
404
|
+
))}
|
|
405
|
+
</TableRow>
|
|
406
|
+
))}
|
|
407
|
+
</TableHeader>
|
|
408
|
+
<TableBody>
|
|
409
|
+
{loading ? (
|
|
410
|
+
<>
|
|
411
|
+
<tr aria-live="polite" aria-busy="true" className="sr-only">
|
|
412
|
+
<td colSpan={columns.length} className="sr-only">
|
|
413
|
+
Loading table data...
|
|
414
|
+
</td>
|
|
415
|
+
</tr>
|
|
416
|
+
<DataTableSkeleton
|
|
417
|
+
columns={userColumns.length}
|
|
418
|
+
rows={pagination?.pageSize ?? 10}
|
|
419
|
+
showCheckbox={enableRowSelection}
|
|
420
|
+
showRowNumber={enableRowNumber}
|
|
421
|
+
/>
|
|
422
|
+
</>
|
|
423
|
+
) : rows.length > 0 ? (
|
|
424
|
+
rows.map((row) => (
|
|
425
|
+
<MemoizedTableRow
|
|
426
|
+
key={row.id}
|
|
427
|
+
row={row}
|
|
428
|
+
isSelected={row.getIsSelected()}
|
|
429
|
+
visibleCellsCount={row.getVisibleCells().length}
|
|
430
|
+
onRowClick={onRowClick}
|
|
431
|
+
/>
|
|
432
|
+
))
|
|
433
|
+
) : null}
|
|
434
|
+
</TableBody>
|
|
435
|
+
</table>
|
|
436
|
+
{/* Empty state - rendered outside table for proper viewport centering */}
|
|
437
|
+
{!loading && rows.length === 0 && (
|
|
438
|
+
<div className="flex items-center justify-center min-h-[300px]">
|
|
439
|
+
{emptyState || (
|
|
440
|
+
<DataTableEmptyState
|
|
441
|
+
hasSearch={emptyStateConfig?.hasSearch}
|
|
442
|
+
hasFilters={emptyStateConfig?.hasFilters}
|
|
443
|
+
onClearSearch={emptyStateConfig?.onClearSearch}
|
|
444
|
+
onClearFilters={emptyStateConfig?.onClearFilters}
|
|
445
|
+
primaryAction={
|
|
446
|
+
emptyStateConfig?.onCreate
|
|
447
|
+
? {
|
|
448
|
+
label: emptyStateConfig.createLabel || "Thêm mới",
|
|
449
|
+
onClick: emptyStateConfig.onCreate,
|
|
450
|
+
}
|
|
451
|
+
: undefined
|
|
452
|
+
}
|
|
453
|
+
/>
|
|
454
|
+
)}
|
|
455
|
+
</div>
|
|
456
|
+
)}
|
|
457
|
+
</div>
|
|
458
|
+
|
|
459
|
+
{/* Pagination Section */}
|
|
460
|
+
{pagination && (
|
|
461
|
+
<div className="border-t border-border dark:border-slate-800 bg-card px-4 sm:px-6 py-2 shrink-0">
|
|
462
|
+
<MemoizedPagination
|
|
463
|
+
table={table}
|
|
464
|
+
currentPage={pagination.page}
|
|
465
|
+
pageCount={pageCount}
|
|
466
|
+
pageSize={pagination.pageSize}
|
|
467
|
+
totalItems={pagination.total}
|
|
468
|
+
/>
|
|
469
|
+
</div>
|
|
470
|
+
)}
|
|
471
|
+
</div>
|
|
472
|
+
);
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
// ============================================================================
|
|
476
|
+
// Memoized TableRow
|
|
477
|
+
// ============================================================================
|
|
478
|
+
|
|
479
|
+
interface MemoizedTableRowProps<TData> {
|
|
480
|
+
row: Row<TData>;
|
|
481
|
+
isSelected: boolean;
|
|
482
|
+
visibleCellsCount: number;
|
|
483
|
+
onRowClick?: (row: TData) => void;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
// Ensure TData is maintained by making it a generic memo component, or casting it
|
|
487
|
+
const MemoizedTableRow = memo(
|
|
488
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
489
|
+
({ row, isSelected, onRowClick }: MemoizedTableRowProps<any>) => {
|
|
490
|
+
return (
|
|
491
|
+
<TableRow
|
|
492
|
+
data-state={isSelected && "selected"}
|
|
493
|
+
className={`transition-colors duration-100 even:bg-muted/30 hover:bg-accent/50 dark:hover:bg-slate-800/40 data-[state=selected]:bg-primary/5 border-b border-border/40 dark:border-slate-800 relative hover:border-l-[3px] hover:border-l-primary ${
|
|
494
|
+
onRowClick ? "cursor-pointer" : ""
|
|
495
|
+
}`}
|
|
496
|
+
onClick={onRowClick ? () => onRowClick(row.original) : undefined}
|
|
497
|
+
>
|
|
498
|
+
{row.getVisibleCells().map((cell) => (
|
|
499
|
+
<TableCell
|
|
500
|
+
key={cell.id}
|
|
501
|
+
className=""
|
|
502
|
+
style={{
|
|
503
|
+
width: cell.column.getSize(),
|
|
504
|
+
minWidth: cell.column.columnDef.minSize,
|
|
505
|
+
maxWidth: cell.column.columnDef.maxSize,
|
|
506
|
+
}}
|
|
507
|
+
>
|
|
508
|
+
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
|
509
|
+
</TableCell>
|
|
510
|
+
))}
|
|
511
|
+
</TableRow>
|
|
512
|
+
);
|
|
513
|
+
},
|
|
514
|
+
(prevProps, nextProps) => {
|
|
515
|
+
// Basic checks
|
|
516
|
+
if (
|
|
517
|
+
prevProps.row.id !== nextProps.row.id ||
|
|
518
|
+
prevProps.isSelected !== nextProps.isSelected ||
|
|
519
|
+
prevProps.onRowClick !== nextProps.onRowClick ||
|
|
520
|
+
prevProps.visibleCellsCount !== nextProps.visibleCellsCount ||
|
|
521
|
+
prevProps.row.original !== nextProps.row.original
|
|
522
|
+
) {
|
|
523
|
+
return false;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
// Since sizing could change without cells count changing
|
|
527
|
+
// We check if cell sizes changed
|
|
528
|
+
const prevCells = prevProps.row.getVisibleCells();
|
|
529
|
+
const nextCells = nextProps.row.getVisibleCells();
|
|
530
|
+
|
|
531
|
+
for (let i = 0; i < prevCells.length; i++) {
|
|
532
|
+
if (
|
|
533
|
+
prevCells[i]?.column.getSize() !== nextCells[i]?.column.getSize() ||
|
|
534
|
+
prevCells[i]?.id !== nextCells[i]?.id ||
|
|
535
|
+
prevCells[i]?.column.id !== nextCells[i]?.column.id
|
|
536
|
+
) {
|
|
537
|
+
return false;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
return true;
|
|
542
|
+
},
|
|
543
|
+
) as <TData>(props: MemoizedTableRowProps<TData>) => ReactElement;
|
|
544
|
+
// The type cast ensures the component retains the generic type TData
|
|
545
|
+
// Without this, the component type would default to `any` or `unknown`.
|
|
546
|
+
// Adding displayName to a typecast component can cause a ts error, so we cast it as any to add the display name.
|
|
547
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
548
|
+
(MemoizedTableRow as any).displayName = "MemoizedTableRow";
|
|
549
|
+
|
|
550
|
+
// ============================================================================
|
|
551
|
+
// Memoized Pagination
|
|
552
|
+
// ============================================================================
|
|
553
|
+
|
|
554
|
+
const MemoizedPagination = memo(
|
|
555
|
+
({
|
|
556
|
+
table,
|
|
557
|
+
currentPage,
|
|
558
|
+
pageSize,
|
|
559
|
+
totalItems,
|
|
560
|
+
}: {
|
|
561
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
562
|
+
table: Table<any>;
|
|
563
|
+
currentPage: number;
|
|
564
|
+
pageCount: number;
|
|
565
|
+
pageSize: number;
|
|
566
|
+
totalItems?: number;
|
|
567
|
+
}) => {
|
|
568
|
+
return (
|
|
569
|
+
<DataTablePagination
|
|
570
|
+
table={table}
|
|
571
|
+
totalItems={totalItems}
|
|
572
|
+
currentPage={currentPage}
|
|
573
|
+
pageSize={pageSize}
|
|
574
|
+
/>
|
|
575
|
+
);
|
|
576
|
+
},
|
|
577
|
+
(prevProps, nextProps) => {
|
|
578
|
+
const prevState = prevProps.table.getState().pagination;
|
|
579
|
+
const nextState = nextProps.table.getState().pagination;
|
|
580
|
+
|
|
581
|
+
return (
|
|
582
|
+
prevProps.currentPage === nextProps.currentPage &&
|
|
583
|
+
prevProps.pageCount === nextProps.pageCount &&
|
|
584
|
+
prevProps.pageSize === nextProps.pageSize &&
|
|
585
|
+
prevProps.totalItems === nextProps.totalItems &&
|
|
586
|
+
prevState.pageIndex === nextState.pageIndex &&
|
|
587
|
+
prevState.pageSize === nextState.pageSize
|
|
588
|
+
);
|
|
589
|
+
},
|
|
590
|
+
);
|
|
591
|
+
MemoizedPagination.displayName = "MemoizedPagination";
|
|
592
|
+
|
|
593
|
+
// ============================================================================
|
|
594
|
+
// Exports
|
|
595
|
+
// ============================================================================
|
|
596
|
+
|
|
597
|
+
export type { ColumnDef, Table, Row };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// @goerp/core/ui/data-display/data-table
|
|
2
|
+
// Reusable DataTable components for standalone table usage
|
|
3
|
+
|
|
4
|
+
// Context and hooks
|
|
5
|
+
export {
|
|
6
|
+
DataTableProvider,
|
|
7
|
+
useDataTable,
|
|
8
|
+
useDataTableOptional,
|
|
9
|
+
type DataTableContextValue,
|
|
10
|
+
type DataTableProviderProps,
|
|
11
|
+
type SortingState,
|
|
12
|
+
type ActiveFilter,
|
|
13
|
+
type PaginationState,
|
|
14
|
+
} from "./data-table-context";
|
|
15
|
+
|
|
16
|
+
// Main DataTable component
|
|
17
|
+
export {
|
|
18
|
+
DataTable,
|
|
19
|
+
type DataTableProps,
|
|
20
|
+
type DataTablePaginationConfig,
|
|
21
|
+
type ColumnDef,
|
|
22
|
+
type Table,
|
|
23
|
+
type Row,
|
|
24
|
+
} from "./data-table";
|
|
25
|
+
|
|
26
|
+
// Skeleton loading states
|
|
27
|
+
export {
|
|
28
|
+
DataTableSkeleton,
|
|
29
|
+
DataTableFullSkeleton,
|
|
30
|
+
type DataTableSkeletonProps,
|
|
31
|
+
} from "./data-table-skeleton";
|
|
32
|
+
|
|
33
|
+
// Empty state
|
|
34
|
+
export {
|
|
35
|
+
DataTableEmptyState,
|
|
36
|
+
type DataTableEmptyStateProps,
|
|
37
|
+
} from "./data-table-empty-state";
|
|
38
|
+
|
|
39
|
+
// Toolbar
|
|
40
|
+
export {
|
|
41
|
+
DataTableToolbar,
|
|
42
|
+
type DataTableToolbarProps,
|
|
43
|
+
type FilterConfig,
|
|
44
|
+
} from "./data-table-toolbar";
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// @goerp/core/ui/data-display
|
|
2
|
+
// DataTableColumnHeader component for table column headers with sorting
|
|
3
|
+
|
|
4
|
+
"use client";
|
|
5
|
+
|
|
6
|
+
import { ArrowDown, ArrowDownUp, ArrowUp, EyeOff, X } from "lucide-react";
|
|
7
|
+
|
|
8
|
+
import type { Column } from "@tanstack/react-table";
|
|
9
|
+
import type { ComponentProps } from "react";
|
|
10
|
+
|
|
11
|
+
import { cn } from "../../utils";
|
|
12
|
+
|
|
13
|
+
import { Button } from "../primitives";
|
|
14
|
+
import {
|
|
15
|
+
DropdownMenu,
|
|
16
|
+
DropdownMenuContent,
|
|
17
|
+
DropdownMenuItem,
|
|
18
|
+
DropdownMenuSeparator,
|
|
19
|
+
DropdownMenuTrigger,
|
|
20
|
+
} from "../primitives/client";
|
|
21
|
+
|
|
22
|
+
interface DataTableColumnHeaderProps<TData, TValue>
|
|
23
|
+
extends ComponentProps<"div"> {
|
|
24
|
+
column: Column<TData, TValue>;
|
|
25
|
+
title: string;
|
|
26
|
+
className?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function DataTableColumnHeader<TData, TValue>({
|
|
30
|
+
column,
|
|
31
|
+
title,
|
|
32
|
+
className,
|
|
33
|
+
}: DataTableColumnHeaderProps<TData, TValue>) {
|
|
34
|
+
if (!column.getCanSort()) {
|
|
35
|
+
return <div className={cn(className)}>{title}</div>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<div className={cn("flex items-center space-x-2", className)}>
|
|
40
|
+
<DropdownMenu>
|
|
41
|
+
<DropdownMenuTrigger asChild>
|
|
42
|
+
<Button
|
|
43
|
+
variant="ghost"
|
|
44
|
+
size="sm"
|
|
45
|
+
className="-ml-3 h-8 data-[state=open]:bg-accent"
|
|
46
|
+
>
|
|
47
|
+
<span>{title}</span>
|
|
48
|
+
{column.getIsSorted() === "desc" ? (
|
|
49
|
+
<ArrowDown className="ml-2 h-4 w-4" />
|
|
50
|
+
) : column.getIsSorted() === "asc" ? (
|
|
51
|
+
<ArrowUp className="ml-2 h-4 w-4" />
|
|
52
|
+
) : (
|
|
53
|
+
<ArrowDownUp className="ml-2 h-4 w-4" />
|
|
54
|
+
)}
|
|
55
|
+
</Button>
|
|
56
|
+
</DropdownMenuTrigger>
|
|
57
|
+
<DropdownMenuContent align="start">
|
|
58
|
+
<DropdownMenuItem onClick={() => column.toggleSorting(false)}>
|
|
59
|
+
<ArrowUp className="mr-2 h-3.5 w-3.5 text-muted-foreground/70" />
|
|
60
|
+
Asc
|
|
61
|
+
</DropdownMenuItem>
|
|
62
|
+
<DropdownMenuItem onClick={() => column.toggleSorting(true)}>
|
|
63
|
+
<ArrowDown className="mr-2 h-3.5 w-3.5 text-muted-foreground/70" />
|
|
64
|
+
Desc
|
|
65
|
+
</DropdownMenuItem>
|
|
66
|
+
<DropdownMenuSeparator />
|
|
67
|
+
<DropdownMenuItem onClick={() => column.toggleVisibility(false)}>
|
|
68
|
+
<EyeOff className="mr-2 h-3.5 w-3.5 text-muted-foreground/70" />
|
|
69
|
+
Hide
|
|
70
|
+
</DropdownMenuItem>
|
|
71
|
+
</DropdownMenuContent>
|
|
72
|
+
</DropdownMenu>
|
|
73
|
+
</div>
|
|
74
|
+
);
|
|
75
|
+
}
|