From 8137de0be756de89e3bf26ac0b4ccb1f904d7a91 Mon Sep 17 00:00:00 2001 From: kwasniew Date: Tue, 9 Sep 2025 12:34:13 +0200 Subject: [PATCH] fix: limit reset when no pagination bar --- .../common/Table/PaginationBar/PaginationBar.tsx | 7 ------- frontend/src/hooks/usePersistentTableState.ts | 13 +++++++++++++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/frontend/src/component/common/Table/PaginationBar/PaginationBar.tsx b/frontend/src/component/common/Table/PaginationBar/PaginationBar.tsx index 7e265ea05e..9660ddde2e 100644 --- a/frontend/src/component/common/Table/PaginationBar/PaginationBar.tsx +++ b/frontend/src/component/common/Table/PaginationBar/PaginationBar.tsx @@ -1,5 +1,4 @@ import type React from 'react'; -import { useEffect } from 'react'; import { Box, Typography, Button, styled } from '@mui/material'; import { ConditionallyRender } from '../../ConditionallyRender/ConditionallyRender.tsx'; import { ReactComponent as ArrowRight } from 'assets/icons/arrowRight.svg'; @@ -61,12 +60,6 @@ export const PaginationBar: React.FC = ({ fetchNextPage, setPageLimit, }) => { - useEffect(() => { - if (![25, 50, 75, 100].includes(pageSize)) { - setPageLimit(25); - } - }, [pageSize]); - const itemRange = totalItems !== undefined && pageSize && totalItems > 1 ? `${pageIndex * pageSize + 1}-${Math.min( diff --git a/frontend/src/hooks/usePersistentTableState.ts b/frontend/src/hooks/usePersistentTableState.ts index 6087033bc8..5d13618372 100644 --- a/frontend/src/hooks/usePersistentTableState.ts +++ b/frontend/src/hooks/usePersistentTableState.ts @@ -51,6 +51,19 @@ export const usePersistentTableState = ( return reorderObject(tableState, [...searchParams.keys()]); }, [searchParams, tableState, reorderObject]); + useEffect(() => { + if ( + tableState.limit && + ![25, 50, 75, 100].includes(tableState.limit as number) + ) { + setTableStateInternal((prevState) => ({ + ...prevState, + limit: 25, + offset: 0, // Reset offset when changing limit + })); + } + }, [tableState.limit, setTableStateInternal]); + type SetTableStateInternalParam = Parameters< typeof setTableStateInternal >[0];