-
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): contract multiselect and batch delete
- Loading branch information
1 parent
a95d6cc
commit 8fa5528
Showing
25 changed files
with
264 additions
and
273 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 contract graphs are now explicitly toggled open with the action button in the navbar. |
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 contracts table now supports multi-select. |
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 hosts graphs no longer include a count metric. |
This file was deleted.
Oops, something went wrong.
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 contracts multi-select menu now supports batch deletion. |
This file was deleted.
Oops, something went wrong.
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
63 changes: 63 additions & 0 deletions
63
apps/renterd/components/Contracts/ContractsBatchMenu/ContractsBatchDelete.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,63 @@ | ||
import { Button, Paragraph } from '@siafoundation/design-system' | ||
import { Delete16 } from '@siafoundation/react-icons' | ||
import { useContractDelete } from '@siafoundation/renterd-react' | ||
import { useCallback, useMemo } from 'react' | ||
import { useDialog } from '../../../contexts/dialog' | ||
import { useContracts } from '../../../contexts/contracts' | ||
import { handleBatchOperation } from '../../../lib/handleBatchOperation' | ||
import { pluralize } from '@siafoundation/units' | ||
|
||
export function ContractsBatchDelete() { | ||
const { multiSelect } = useContracts() | ||
|
||
const ids = useMemo( | ||
() => Object.entries(multiSelect.selectionMap).map(([_, item]) => item.id), | ||
[multiSelect.selectionMap] | ||
) | ||
const { openConfirmDialog } = useDialog() | ||
const deleteContract = useContractDelete() | ||
const deleteAll = useCallback(async () => { | ||
await handleBatchOperation( | ||
ids.map((id) => deleteContract.delete({ params: { id } })), | ||
{ | ||
toastError: ({ successCount, errorCount, totalCount }) => ({ | ||
title: `${pluralize(successCount, 'contract')} deleted`, | ||
body: `Error deleting ${errorCount}/${totalCount} total contracts.`, | ||
}), | ||
toastSuccess: ({ totalCount }) => ({ | ||
title: `${pluralize(totalCount, 'contract')} deleted`, | ||
}), | ||
after: () => { | ||
multiSelect.deselectAll() | ||
}, | ||
} | ||
) | ||
}, [multiSelect, ids, deleteContract]) | ||
|
||
return ( | ||
<Button | ||
aria-label="delete selected contracts" | ||
tip="Delete selected contracts" | ||
onClick={() => { | ||
openConfirmDialog({ | ||
title: `Delete contracts`, | ||
action: 'Delete', | ||
variant: 'red', | ||
body: ( | ||
<div className="flex flex-col gap-1"> | ||
<Paragraph size="14"> | ||
Are you sure you would like to delete the{' '} | ||
{pluralize(multiSelect.selectionCount, 'selected contract')}? | ||
</Paragraph> | ||
</div> | ||
), | ||
onConfirm: async () => { | ||
deleteAll() | ||
}, | ||
}) | ||
}} | ||
> | ||
<Delete16 /> | ||
</Button> | ||
) | ||
} |
13 changes: 13 additions & 0 deletions
13
apps/renterd/components/Contracts/ContractsBatchMenu/index.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,13 @@ | ||
import { MultiSelectionMenu } from '@siafoundation/design-system' | ||
import { useContracts } from '../../../contexts/contracts' | ||
import { ContractsBatchDelete } from './ContractsBatchDelete' | ||
|
||
export function ContractsBatchMenu() { | ||
const { multiSelect } = useContracts() | ||
|
||
return ( | ||
<MultiSelectionMenu multiSelect={multiSelect} entityWord="contract"> | ||
<ContractsBatchDelete /> | ||
</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
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
Oops, something went wrong.