-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(renterd): contracts batch manage blocklist and allowlist
- Loading branch information
1 parent
4eba392
commit 4d06550
Showing
14 changed files
with
378 additions
and
28 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 contracts multi-select menu now supports bulk adding and removing to both the allowlist and blocklists. |
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
54 changes: 54 additions & 0 deletions
54
apps/renterd/components/Contracts/ContractsBatchMenu/ContractsAddAllowlist.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,54 @@ | ||
import { Button, Paragraph } from '@siafoundation/design-system' | ||
import { ListChecked16 } from '@siafoundation/react-icons' | ||
import { useCallback, useMemo } from 'react' | ||
import { useDialog } from '../../../contexts/dialog' | ||
import { useContracts } from '../../../contexts/contracts' | ||
import { pluralize } from '@siafoundation/units' | ||
import { useAllowlistUpdate } from '../../../hooks/useAllowlistUpdate' | ||
|
||
export function ContractsAddAllowlist() { | ||
const { multiSelect } = useContracts() | ||
|
||
const publicKeys = useMemo( | ||
() => | ||
Object.entries(multiSelect.selectionMap).map(([_, item]) => item.hostKey), | ||
[multiSelect.selectionMap] | ||
) | ||
const { openConfirmDialog } = useDialog() | ||
const allowlistUpdate = useAllowlistUpdate() | ||
|
||
const add = useCallback(async () => { | ||
allowlistUpdate(publicKeys, []) | ||
multiSelect.deselectAll() | ||
}, [allowlistUpdate, multiSelect, publicKeys]) | ||
|
||
return ( | ||
<Button | ||
aria-label="add host public keys to allowlist" | ||
tip="Add host public keys to allowlist" | ||
onClick={() => { | ||
openConfirmDialog({ | ||
title: `Add ${pluralize( | ||
multiSelect.selectionCount, | ||
'host' | ||
)} to allowlist`, | ||
action: 'Add to allowlist', | ||
variant: 'accent', | ||
body: ( | ||
<div className="flex flex-col gap-1"> | ||
<Paragraph size="14"> | ||
Are you sure you would like to add{' '} | ||
{pluralize(multiSelect.selectionCount, 'host public key')} to | ||
the allowlist? | ||
</Paragraph> | ||
</div> | ||
), | ||
onConfirm: add, | ||
}) | ||
}} | ||
> | ||
<ListChecked16 /> | ||
Add to allowlist | ||
</Button> | ||
) | ||
} |
58 changes: 58 additions & 0 deletions
58
apps/renterd/components/Contracts/ContractsBatchMenu/ContractsAddBlocklist.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,58 @@ | ||
import { Button, Paragraph } from '@siafoundation/design-system' | ||
import { ListChecked16 } from '@siafoundation/react-icons' | ||
import { useCallback, useMemo } from 'react' | ||
import { useDialog } from '../../../contexts/dialog' | ||
import { useContracts } from '../../../contexts/contracts' | ||
import { pluralize } from '@siafoundation/units' | ||
import { useBlocklistUpdate } from '../../../hooks/useBlocklistUpdate' | ||
|
||
export function ContractsAddBlocklist() { | ||
const { multiSelect } = useContracts() | ||
|
||
const hostAddresses = useMemo( | ||
() => | ||
Object.entries(multiSelect.selectionMap).map(([_, item]) => item.hostIp), | ||
[multiSelect.selectionMap] | ||
) | ||
const { openConfirmDialog } = useDialog() | ||
const blocklistUpdate = useBlocklistUpdate() | ||
|
||
const add = useCallback(async () => { | ||
blocklistUpdate(hostAddresses, []) | ||
multiSelect.deselectAll() | ||
}, [blocklistUpdate, multiSelect, hostAddresses]) | ||
|
||
return ( | ||
<Button | ||
aria-label="add host addresses to blocklist" | ||
tip="Add host addresses to blocklist" | ||
onClick={() => { | ||
openConfirmDialog({ | ||
title: `Add ${pluralize( | ||
multiSelect.selectionCount, | ||
'host' | ||
)} to blocklist`, | ||
action: 'Add to blocklist', | ||
variant: 'red', | ||
body: ( | ||
<div className="flex flex-col gap-1"> | ||
<Paragraph size="14"> | ||
Are you sure you would like to add{' '} | ||
{pluralize( | ||
multiSelect.selectionCount, | ||
'host address', | ||
'host addresses' | ||
)}{' '} | ||
to the blocklist? | ||
</Paragraph> | ||
</div> | ||
), | ||
onConfirm: add, | ||
}) | ||
}} | ||
> | ||
<ListChecked16 /> | ||
Add to blocklist | ||
</Button> | ||
) | ||
} |
54 changes: 54 additions & 0 deletions
54
apps/renterd/components/Contracts/ContractsBatchMenu/ContractsRemoveAllowlist.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,54 @@ | ||
import { Button, Paragraph } from '@siafoundation/design-system' | ||
import { ListChecked16 } from '@siafoundation/react-icons' | ||
import { useCallback, useMemo } from 'react' | ||
import { useDialog } from '../../../contexts/dialog' | ||
import { useContracts } from '../../../contexts/contracts' | ||
import { pluralize } from '@siafoundation/units' | ||
import { useAllowlistUpdate } from '../../../hooks/useAllowlistUpdate' | ||
|
||
export function ContractsRemoveAllowlist() { | ||
const { multiSelect } = useContracts() | ||
|
||
const publicKeys = useMemo( | ||
() => | ||
Object.entries(multiSelect.selectionMap).map(([_, item]) => item.hostKey), | ||
[multiSelect.selectionMap] | ||
) | ||
const { openConfirmDialog } = useDialog() | ||
const allowlistUpdate = useAllowlistUpdate() | ||
|
||
const remove = useCallback(async () => { | ||
await allowlistUpdate([], publicKeys) | ||
multiSelect.deselectAll() | ||
}, [allowlistUpdate, multiSelect, publicKeys]) | ||
|
||
return ( | ||
<Button | ||
aria-label="remove host public keys from allowlist" | ||
tip="Remove host public keys from allowlist" | ||
onClick={() => { | ||
openConfirmDialog({ | ||
title: `Remove ${pluralize( | ||
multiSelect.selectionCount, | ||
'host' | ||
)} from allowlist`, | ||
action: 'Remove from allowlist', | ||
variant: 'accent', | ||
body: ( | ||
<div className="flex flex-col gap-1"> | ||
<Paragraph size="14"> | ||
Are you sure you would like to remove{' '} | ||
{pluralize(multiSelect.selectionCount, 'host public key')} from | ||
the allowlist? | ||
</Paragraph> | ||
</div> | ||
), | ||
onConfirm: remove, | ||
}) | ||
}} | ||
> | ||
<ListChecked16 /> | ||
Remove from allowlist | ||
</Button> | ||
) | ||
} |
58 changes: 58 additions & 0 deletions
58
apps/renterd/components/Contracts/ContractsBatchMenu/ContractsRemoveBlocklist.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,58 @@ | ||
import { Button, Paragraph } from '@siafoundation/design-system' | ||
import { ListChecked16 } from '@siafoundation/react-icons' | ||
import { useCallback, useMemo } from 'react' | ||
import { useDialog } from '../../../contexts/dialog' | ||
import { useContracts } from '../../../contexts/contracts' | ||
import { pluralize } from '@siafoundation/units' | ||
import { useBlocklistUpdate } from '../../../hooks/useBlocklistUpdate' | ||
|
||
export function ContractsRemoveBlocklist() { | ||
const { multiSelect } = useContracts() | ||
|
||
const hostAddresses = useMemo( | ||
() => | ||
Object.entries(multiSelect.selectionMap).map(([_, item]) => item.hostIp), | ||
[multiSelect.selectionMap] | ||
) | ||
const { openConfirmDialog } = useDialog() | ||
const blocklistUpdate = useBlocklistUpdate() | ||
|
||
const remove = useCallback(async () => { | ||
blocklistUpdate([], hostAddresses) | ||
multiSelect.deselectAll() | ||
}, [blocklistUpdate, multiSelect, hostAddresses]) | ||
|
||
return ( | ||
<Button | ||
aria-label="remove host addresses from blocklist" | ||
tip="Remove host addresses from blocklist" | ||
onClick={() => { | ||
openConfirmDialog({ | ||
title: `Remove ${pluralize( | ||
multiSelect.selectionCount, | ||
'host' | ||
)} from blocklist`, | ||
action: 'Remove from blocklist', | ||
variant: 'red', | ||
body: ( | ||
<div className="flex flex-col gap-1"> | ||
<Paragraph size="14"> | ||
Are you sure you would like to remove{' '} | ||
{pluralize( | ||
multiSelect.selectionCount, | ||
'host address', | ||
'host addresses' | ||
)}{' '} | ||
from the blocklist? | ||
</Paragraph> | ||
</div> | ||
), | ||
onConfirm: remove, | ||
}) | ||
}} | ||
> | ||
<ListChecked16 /> | ||
Remove from blocklist | ||
</Button> | ||
) | ||
} |
12 changes: 12 additions & 0 deletions
12
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
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.