From ac4fd37b65ea6d02e4e034752c66e2cfbd154538 Mon Sep 17 00:00:00 2001 From: Ivan <8611739+IRBorisov@users.noreply.github.com> Date: Thu, 20 Mar 2025 19:23:23 +0300 Subject: [PATCH] B: Fix pagination change rendering error --- .../src/components/data-table/data-table.tsx | 2 ++ .../data-table/pagination-tools.tsx | 11 ++++++++-- .../components/data-table/use-data-table.ts | 22 ++----------------- rsconcept/frontend/src/index.css | 18 +++++++++++++++ rsconcept/frontend/src/styling/setup.css | 18 --------------- 5 files changed, 31 insertions(+), 40 deletions(-) diff --git a/rsconcept/frontend/src/components/data-table/data-table.tsx b/rsconcept/frontend/src/components/data-table/data-table.tsx index c2eeb001..0d16ca28 100644 --- a/rsconcept/frontend/src/components/data-table/data-table.tsx +++ b/rsconcept/frontend/src/components/data-table/data-table.tsx @@ -120,6 +120,7 @@ export function DataTable({ onRowDoubleClicked, noDataComponent, + onChangePaginationOption, paginationPerPage, paginationOptions = [10, 20, 30, 40, 50], @@ -182,6 +183,7 @@ export function DataTable({ ) : null} diff --git a/rsconcept/frontend/src/components/data-table/pagination-tools.tsx b/rsconcept/frontend/src/components/data-table/pagination-tools.tsx index 47838b54..06ec4421 100644 --- a/rsconcept/frontend/src/components/data-table/pagination-tools.tsx +++ b/rsconcept/frontend/src/components/data-table/pagination-tools.tsx @@ -12,15 +12,22 @@ interface PaginationToolsProps { id?: string; table: Table; paginationOptions: number[]; + onChangePaginationOption?: (newValue: number) => void; } -export function PaginationTools({ id, table, paginationOptions }: PaginationToolsProps) { +export function PaginationTools({ + id, + table, + onChangePaginationOption, + paginationOptions +}: PaginationToolsProps) { const handlePaginationOptionsChange = useCallback( (event: React.ChangeEvent) => { const perPage = Number(event.target.value); table.setPageSize(perPage); + onChangePaginationOption?.(perPage); }, - [table] + [table, onChangePaginationOption] ); return ( diff --git a/rsconcept/frontend/src/components/data-table/use-data-table.ts b/rsconcept/frontend/src/components/data-table/use-data-table.ts index 9b03370a..de43a338 100644 --- a/rsconcept/frontend/src/components/data-table/use-data-table.ts +++ b/rsconcept/frontend/src/components/data-table/use-data-table.ts @@ -1,6 +1,6 @@ 'use client'; -import { useCallback, useState } from 'react'; +import { useState } from 'react'; import { type ColumnSort, getCoreRowModel, @@ -11,7 +11,6 @@ import { type RowSelectionState, type SortingState, type TableOptions, - type Updater, useReactTable, type VisibilityState } from '@tanstack/react-table'; @@ -45,9 +44,6 @@ interface UseDataTableProps /** Number of rows per page. */ paginationPerPage?: number; - /** Callback to be called when the pagination option is changed. */ - onChangePaginationOption?: (newValue: number) => void; - /** Enable sorting. */ enableSorting?: boolean; @@ -73,7 +69,6 @@ export function useDataTable({ enablePagination, paginationPerPage = 10, - onChangePaginationOption, ...restProps }: UseDataTableProps) { @@ -83,19 +78,6 @@ export function useDataTable({ pageSize: paginationPerPage }); - const handleChangePagination = useCallback( - (updater: Updater) => { - setPagination(prev => { - const resolvedValue = typeof updater === 'function' ? updater(prev) : updater; - if (onChangePaginationOption && prev.pageSize !== resolvedValue.pageSize) { - onChangePaginationOption(resolvedValue.pageSize); - } - return resolvedValue; - }); - }, - [onChangePaginationOption] - ); - const table = useReactTable({ state: { pagination: pagination, @@ -111,7 +93,7 @@ export function useDataTable({ onSortingChange: enableSorting ? setSorting : undefined, getPaginationRowModel: enablePagination ? getPaginationRowModel() : undefined, - onPaginationChange: enablePagination ? handleChangePagination : undefined, + onPaginationChange: enablePagination ? setPagination : undefined, enableHiding: enableHiding, enableMultiRowSelection: enableRowSelection, diff --git a/rsconcept/frontend/src/index.css b/rsconcept/frontend/src/index.css index 0ef1fb9d..250e5bde 100644 --- a/rsconcept/frontend/src/index.css +++ b/rsconcept/frontend/src/index.css @@ -7,6 +7,24 @@ @custom-variant dark (&:is(.dark *)); +/* Uncomment to debug layering and overflow */ +/* *, +*::after, +*::before { + :focus, + :focus-visible, + :focus-within { + outline: 2px solid hotpink !important; + } +} */ + +/* *, +*::after, +*::before { + background: hsla(135, 50%, 50%, 0.05) !important; + outline: 2px solid hotpink !important; +} */ + @theme { /* stylelint-disable-next-line custom-property-pattern */ --color-*: initial; diff --git a/rsconcept/frontend/src/styling/setup.css b/rsconcept/frontend/src/styling/setup.css index 7ad2f2b1..823d4ff8 100644 --- a/rsconcept/frontend/src/styling/setup.css +++ b/rsconcept/frontend/src/styling/setup.css @@ -4,24 +4,6 @@ @import './constants.css' layer(base); -/* Uncomment to debug layering and overflow */ -/* *, -*::after, -*::before { - :focus, - :focus-visible, - :focus-within { - outline: 2px solid hotpink !important; - } -} */ - -/* *, -*::after, -*::before { - background: hsla(135, 50%, 50%, 0.05) !important; - outline: 2px solid hotpink !important; -} */ - @layer utilities { *, *::after,