From 1a9941b38e2f353db6d1f97af44e5967092a39c9 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 --- .../Keys/KeysBatchMenu/KeysBatchDelete.tsx | 16 ++--- apps/renterd/contexts/keys/columns.tsx | 13 ++-- apps/renterd/contexts/keys/index.tsx | 24 ++----- 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 ++++++++++++++++--- 9 files changed, 111 insertions(+), 72 deletions(-) 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 (