From 7ee383afb0bfaa4f3d016659582f91c3b57f6e78 Mon Sep 17 00:00:00 2001 From: Alex Freska Date: Fri, 18 Oct 2024 11:44:18 -0400 Subject: [PATCH] refactor: refine multiselect API --- apps/renterd-e2e/src/specs/keys.spec.ts | 4 +- .../Keys/KeysBatchMenu/KeysBatchDelete.tsx | 16 ++--- .../components/Keys/KeysBatchMenu/index.tsx | 12 +--- .../components/Keys/KeysStatsMenu/index.tsx | 18 ++++++ apps/renterd/components/Keys/index.tsx | 2 + apps/renterd/contexts/keys/columns.tsx | 21 ++---- apps/renterd/contexts/keys/index.tsx | 44 ++++++------- apps/renterd/contexts/keys/types.ts | 7 +- .../src/components/Table/TableRow.tsx | 13 +++- .../src/components/Table/index.tsx | 4 +- libs/design-system/src/core/Tooltip.tsx | 4 +- .../src/multi/MultiSelectionMenu.tsx | 38 ++++++----- .../src/multi/useMultiSelect.tsx | 64 ++++++++++++++++--- 13 files changed, 150 insertions(+), 97 deletions(-) create mode 100644 apps/renterd/components/Keys/KeysStatsMenu/index.tsx diff --git a/apps/renterd-e2e/src/specs/keys.spec.ts b/apps/renterd-e2e/src/specs/keys.spec.ts index bee5151e7..d937d13a8 100644 --- a/apps/renterd-e2e/src/specs/keys.spec.ts +++ b/apps/renterd-e2e/src/specs/keys.spec.ts @@ -39,8 +39,8 @@ test('batch delete multiple keys', async ({ page }) => { const rowIdx3 = getKeyRowByIndex(page, 3) // Select all 4 keys. - await rowIdx0.getByLabel('select key').click() - await rowIdx3.getByLabel('select key').click({ modifiers: ['Shift'] }) + await rowIdx0.click() + await rowIdx3.click({ modifiers: ['Shift'] }) // Delete all 4 keys. const menu = page.getByLabel('key multiselect menu') diff --git a/apps/renterd/components/Keys/KeysBatchMenu/KeysBatchDelete.tsx b/apps/renterd/components/Keys/KeysBatchMenu/KeysBatchDelete.tsx index 6d0433cec..1fd8c5bb9 100644 --- a/apps/renterd/components/Keys/KeysBatchMenu/KeysBatchDelete.tsx +++ b/apps/renterd/components/Keys/KeysBatchMenu/KeysBatchDelete.tsx @@ -15,15 +15,11 @@ import { useDialog } from '../../../contexts/dialog' import { useKeys } from '../../../contexts/keys' export function KeysBatchDelete() { - const { selectionMap, deselect } = useKeys() + const { multiSelect } = useKeys() - const ids = useMemo( - () => Object.entries(selectionMap).map(([_, item]) => item.id), - [selectionMap] - ) const keys = useMemo( - () => Object.entries(selectionMap).map(([_, item]) => item.key), - [selectionMap] + () => Object.entries(multiSelect.selectionMap).map(([_, item]) => item.key), + [multiSelect.selectionMap] ) const { openConfirmDialog } = useDialog() const settingsS3 = useSettingsS3() @@ -43,13 +39,13 @@ export function KeysBatchDelete() { }, }, }) - deselect(ids) + multiSelect.deselectAll() if (response.error) { triggerErrorToast({ title: 'Error deleting keys', body: response.error }) } else { triggerSuccessToast({ title: `Keys deleted` }) } - }, [settingsS3.data, settingsS3Update, deselect, keys, ids]) + }, [settingsS3.data, settingsS3Update, multiSelect, keys]) return (