From 17559adbd7811a29f306dc5db4ac582bad92e58e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Thu, 13 Jun 2024 15:32:11 +0200 Subject: [PATCH] Add: Add a useSelection hook The useSelection hook implements the entity selection at a entities list table. It is possible to select/deselect specific entities from the list/table, to select all entities displayed at the page or all entities for the current filter (filter without rows value applied). --- src/web/hooks/__tests__/useSelection.jsx | 78 ++++++++++++++++++++++++ src/web/hooks/useSelection.js | 58 ++++++++++++++++++ 2 files changed, 136 insertions(+) create mode 100644 src/web/hooks/__tests__/useSelection.jsx create mode 100644 src/web/hooks/useSelection.js diff --git a/src/web/hooks/__tests__/useSelection.jsx b/src/web/hooks/__tests__/useSelection.jsx new file mode 100644 index 0000000000..6996fcd058 --- /dev/null +++ b/src/web/hooks/__tests__/useSelection.jsx @@ -0,0 +1,78 @@ +/* SPDX-FileCopyrightText: 2024 Greenbone AG + * + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +/* eslint-disable react/prop-types */ + +import {describe, test, expect} from '@gsa/testing'; + +import {fireEvent, render, screen} from 'web/utils/testing'; +import SelectionType from 'web/utils/selectiontype'; + +import useSelection from '../useSelection'; + +const TestComponent = () => { + const {selected, selectionType, select, deselect, changeSelectionType} = + useSelection(SelectionType.SELECTION_USER); + return ( + <> + {selectionType} + + +