From cf02a9ce06fb654c5fdae6f0a50f133885d13494 Mon Sep 17 00:00:00 2001 From: Andreas Berger Date: Fri, 17 Jan 2025 16:21:44 +0100 Subject: [PATCH] optimize code Signed-off-by: Andreas Berger --- .../CatalogTable/OffsetPaginatedCatalogTable.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/catalog/src/components/CatalogTable/OffsetPaginatedCatalogTable.tsx b/plugins/catalog/src/components/CatalogTable/OffsetPaginatedCatalogTable.tsx index 0bec07722e..2f7e5a168e 100644 --- a/plugins/catalog/src/components/CatalogTable/OffsetPaginatedCatalogTable.tsx +++ b/plugins/catalog/src/components/CatalogTable/OffsetPaginatedCatalogTable.tsx @@ -37,14 +37,14 @@ export function OffsetPaginatedCatalogTable( ); useEffect(() => { - if (clientPagination) { + if (clientPagination || !setOffset) { return; } - if (totalItems && page * limit >= totalItems) { - setOffset?.(Math.max(0, totalItems - limit)); - } else { - setOffset?.(Math.max(0, page * limit)); + let newOffset = page * limit; + if (totalItems && newOffset >= totalItems) { + newOffset = totalItems - limit; } + setOffset(Math.max(0, newOffset)); }, [setOffset, page, limit, totalItems, clientPagination]); const showPagination = (totalItems ?? data.length) > limit;