From e5dc483d438396db036c7d61c72ed654a14dfd9c Mon Sep 17 00:00:00 2001 From: Denozordec Date: Thu, 25 Jun 2026 17:43:17 +0700 Subject: [PATCH] refactor: Enhance ChartCard and DataTable components by improving layout structure, adding pagination controls, and optimizing tab functionality for better user experience --- apps/web/src/components/chart-card.tsx | 18 +-- .../src/components/data-table-pagination.tsx | 112 +++++++++++------- .../web/src/components/data-table-toolbar.tsx | 36 ++---- packages/ui/src/components/tabs.tsx | 10 +- 4 files changed, 96 insertions(+), 80 deletions(-) diff --git a/apps/web/src/components/chart-card.tsx b/apps/web/src/components/chart-card.tsx index c3c0d4a..3a2604b 100644 --- a/apps/web/src/components/chart-card.tsx +++ b/apps/web/src/components/chart-card.tsx @@ -42,17 +42,19 @@ export function ChartCard({ {description && {description}} {action} - + {hasTabs ? ( - - - {chartTabLabel} - {tableTabLabel} - - + +
+ + {chartTabLabel} + {tableTabLabel} + +
+ {chart} - + {table}
diff --git a/apps/web/src/components/data-table-pagination.tsx b/apps/web/src/components/data-table-pagination.tsx index 8913e02..0d072f2 100644 --- a/apps/web/src/components/data-table-pagination.tsx +++ b/apps/web/src/components/data-table-pagination.tsx @@ -8,10 +8,19 @@ import { PaginationNext, PaginationPrevious, } from '@cfdm/ui/components/pagination' +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, +} from '@cfdm/ui/components/select' +import { pageSizeOptions } from '@/components/data-table-density' interface DataTablePaginationProps { table: Table selectedCount?: number + pageSizeLabel?: string } function buildPageRange(current: number, total: number): (number | 'ellipsis')[] { @@ -31,57 +40,80 @@ function buildPageRange(current: number, total: number): (number | 'ellipsis')[] export function DataTablePagination({ table, selectedCount, + pageSizeLabel = 'Строк', }: DataTablePaginationProps) { - const { pageIndex } = table.getState().pagination + const { pageIndex, pageSize } = table.getState().pagination const pageCount = table.getPageCount() - if (pageCount <= 1) return null - - const pages = buildPageRange(pageIndex + 1, pageCount) + const total = table.getFilteredRowModel().rows.length + const from = total === 0 ? 0 : pageIndex * pageSize + 1 + const to = Math.min((pageIndex + 1) * pageSize, total) return (
{selectedCount != null && selectedCount > 0 - ? `Выбрано: ${selectedCount} из ${table.getFilteredRowModel().rows.length}` - : `Всего: ${table.getFilteredRowModel().rows.length}`} + ? `Выбрано: ${selectedCount} из ${total}` + : `${from}–${to} из ${total}`}
- - - - table.previousPage()} - aria-disabled={!table.getCanPreviousPage()} - className={!table.getCanPreviousPage() ? 'pointer-events-none opacity-50' : undefined} - /> - - {pages.map((page, idx) => - page === 'ellipsis' ? ( - - +
+
+ {pageSizeLabel} + +
+ {pageCount > 1 && ( + + + + table.previousPage()} + aria-disabled={!table.getCanPreviousPage()} + className={!table.getCanPreviousPage() ? 'pointer-events-none opacity-50' : undefined} + /> - ) : ( - - table.setPageIndex(page - 1)} - > - {page} - + {buildPageRange(pageIndex + 1, pageCount).map((page, idx) => + page === 'ellipsis' ? ( + + + + ) : ( + + table.setPageIndex(page - 1)} + > + {page} + + + ), + )} + + table.nextPage()} + aria-disabled={!table.getCanNextPage()} + className={!table.getCanNextPage() ? 'pointer-events-none opacity-50' : undefined} + /> - ), - )} - - table.nextPage()} - aria-disabled={!table.getCanNextPage()} - className={!table.getCanNextPage() ? 'pointer-events-none opacity-50' : undefined} - /> - - - + + + )} +
) } diff --git a/apps/web/src/components/data-table-toolbar.tsx b/apps/web/src/components/data-table-toolbar.tsx index 0f6f2a4..918ed51 100644 --- a/apps/web/src/components/data-table-toolbar.tsx +++ b/apps/web/src/components/data-table-toolbar.tsx @@ -13,13 +13,11 @@ import { DropdownMenuLabel, DropdownMenuRadioGroup, DropdownMenuRadioItem, - DropdownMenuSeparator, DropdownMenuTrigger, } from '@cfdm/ui/components/dropdown-menu' import { AppButton } from '@/components/app-button' import { densityLabel, - pageSizeOptions, type Density, } from '@/components/data-table-density' @@ -66,13 +64,11 @@ export function DataTableToolbar({
- - Колонки - - } - /> + render={} + > + + Колонки + Видимость {columns.map((column) => ( @@ -90,12 +86,10 @@ export function DataTableToolbar({ - Плотность - - } - /> + render={} + > + Плотность + Плотность строк ({ ))} - - Строк на странице - table.setPageSize(Number(val))} - > - {pageSizeOptions.map((size) => ( - - {size} - - ))} -
diff --git a/packages/ui/src/components/tabs.tsx b/packages/ui/src/components/tabs.tsx index 5dbd1de..4fe5c11 100644 --- a/packages/ui/src/components/tabs.tsx +++ b/packages/ui/src/components/tabs.tsx @@ -11,9 +11,9 @@ function Tabs({ return (