From c2f9047960667d4ba27c431a45dedc4e6d5b46b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Thu, 13 Jun 2024 12:02:44 +0200 Subject: [PATCH] Add: Add a usePagination hook The hook returns functions the update a filter for getting the next, previous, first and last page for a list of entities. --- src/web/hooks/__tests__/usePagination.jsx | 108 ++++++++++++++++++++++ src/web/hooks/usePagination.js | 54 +++++++++++ 2 files changed, 162 insertions(+) create mode 100644 src/web/hooks/__tests__/usePagination.jsx create mode 100644 src/web/hooks/usePagination.js diff --git a/src/web/hooks/__tests__/usePagination.jsx b/src/web/hooks/__tests__/usePagination.jsx new file mode 100644 index 0000000000..827bf344c7 --- /dev/null +++ b/src/web/hooks/__tests__/usePagination.jsx @@ -0,0 +1,108 @@ +/* SPDX-FileCopyrightText: 2024 Greenbone AG + * + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +/* eslint-disable react/prop-types */ + +import {describe, test, expect, testing} from '@gsa/testing'; + +import {fireEvent, render, screen} from 'web/utils/testing'; + +import Filter from 'gmp/models/filter'; + +import usePagination from '../usePagination'; + +const TestComponent = ({filter, counts, changeFilter}) => { + const [first, last, next, previous] = usePagination( + filter, + counts, + changeFilter, + ); + return ( + <> +