From 3af32a485001cf9ddca9ae8e5493114533e6ace0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Thu, 13 Jun 2024 11:34:09 +0200 Subject: [PATCH] Add: Add a useFilterSortBy hook The hook determines the sort field and direction of a filter and allows to change both via a returned function. The hook can be used to implement the filter changes when clicking on the different header columns of a entities list. --- src/web/hooks/__tests__/useFilterSortBy.jsx | 67 +++++++++++++++++++++ src/web/hooks/useFilterSortBy.js | 49 +++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 src/web/hooks/__tests__/useFilterSortBy.jsx create mode 100644 src/web/hooks/useFilterSortBy.js diff --git a/src/web/hooks/__tests__/useFilterSortBy.jsx b/src/web/hooks/__tests__/useFilterSortBy.jsx new file mode 100644 index 0000000000..263bad2164 --- /dev/null +++ b/src/web/hooks/__tests__/useFilterSortBy.jsx @@ -0,0 +1,67 @@ +/* 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 useFilterSortBy from '../useFilterSortBy'; + +const TestComponent = ({filter, changeFilter}) => { + const [sortBy, sortDir, sortChange] = useFilterSortBy(filter, changeFilter); + return ( + <> + {sortBy} + {sortDir} +