-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(renterd): keys batch operations
- Loading branch information
1 parent
6a0eb54
commit c8599c7
Showing
8 changed files
with
174 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'renterd': minor | ||
--- | ||
|
||
The key management table now supports multiselect and batch deletion. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
apps/renterd/components/Keys/KeysBatchMenu/KeysBatchDelete.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { | ||
Button, | ||
Paragraph, | ||
triggerSuccessToast, | ||
triggerErrorToast, | ||
} from '@siafoundation/design-system' | ||
import { Delete16 } from '@siafoundation/react-icons' | ||
import { | ||
useSettingsS3, | ||
useSettingsS3Update, | ||
} from '@siafoundation/renterd-react' | ||
import { useCallback, useMemo } from 'react' | ||
import { omit } from '@technically/lodash' | ||
import { useDialog } from '../../../contexts/dialog' | ||
import { useKeys } from '../../../contexts/keys' | ||
|
||
export function KeysBatchDelete() { | ||
const { selectionMap, deselect } = useKeys() | ||
|
||
const ids = useMemo( | ||
() => Object.entries(selectionMap).map(([_, item]) => item.id), | ||
[selectionMap] | ||
) | ||
const keys = useMemo( | ||
() => Object.entries(selectionMap).map(([_, item]) => item.key), | ||
[selectionMap] | ||
) | ||
const { openConfirmDialog } = useDialog() | ||
const settingsS3 = useSettingsS3() | ||
const settingsS3Update = useSettingsS3Update() | ||
const deleteKeys = useCallback(async () => { | ||
if (!settingsS3.data) { | ||
triggerErrorToast({ title: 'Error deleting key' }) | ||
return | ||
} | ||
const newKeys = omit(settingsS3.data?.authentication.v4Keypairs, keys) | ||
const response = await settingsS3Update.put({ | ||
payload: { | ||
...settingsS3.data, | ||
authentication: { | ||
...settingsS3.data.authentication, | ||
v4Keypairs: newKeys, | ||
}, | ||
}, | ||
}) | ||
deselect(ids) | ||
if (response.error) { | ||
triggerErrorToast({ title: 'Error deleting keys', body: response.error }) | ||
} else { | ||
triggerSuccessToast({ title: `Keys deleted` }) | ||
} | ||
}, [settingsS3.data, settingsS3Update, deselect, keys, ids]) | ||
|
||
return ( | ||
<Button | ||
tip="Delete keys" | ||
onClick={() => { | ||
openConfirmDialog({ | ||
title: `Delete keys`, | ||
action: 'Remove', | ||
variant: 'red', | ||
body: ( | ||
<div className="flex flex-col gap-1"> | ||
<Paragraph size="14"> | ||
Are you sure you would like to delete the{' '} | ||
{ids.length.toLocaleString()} selected keys? | ||
</Paragraph> | ||
</div> | ||
), | ||
onConfirm: async () => { | ||
deleteKeys() | ||
}, | ||
}) | ||
}} | ||
> | ||
<Delete16 /> | ||
</Button> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { MultiSelectionMenu } from '@siafoundation/design-system' | ||
import { useKeys } from '../../../contexts/keys' | ||
import { KeysBatchDelete } from './KeysBatchDelete' | ||
|
||
export function KeysBatchMenu() { | ||
const { selectionCount, isPageAllSelected, pageCount, deselectAll } = | ||
useKeys() | ||
|
||
return ( | ||
<MultiSelectionMenu | ||
isVisible={selectionCount > 0} | ||
selectionCount={selectionCount} | ||
isPageAllSelected={isPageAllSelected} | ||
deselectAll={deselectAll} | ||
pageCount={pageCount} | ||
entityWord="key" | ||
> | ||
<KeysBatchDelete /> | ||
</MultiSelectionMenu> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters