-
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.
- Loading branch information
1 parent
a5daa68
commit a12b167
Showing
5 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
apps/renterd/components/Contracts/ContractsBulkMenu/ContractsRescanHosts.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,15 @@ | ||
import { useMemo } from 'react' | ||
import { useContracts } from '../../../contexts/contracts' | ||
import { BulkRescanHosts } from '../../bulkActions/BulkRescanHosts' | ||
|
||
export function ContractsRescanHosts() { | ||
const { multiSelect } = useContracts() | ||
|
||
const publicKeys = useMemo( | ||
() => | ||
Object.entries(multiSelect.selection).map(([_, item]) => item.hostKey), | ||
[multiSelect.selection] | ||
) | ||
|
||
return <BulkRescanHosts multiSelect={multiSelect} publicKeys={publicKeys} /> | ||
} |
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
15 changes: 15 additions & 0 deletions
15
apps/renterd/components/Hosts/HostsBulkMenu/HostsRescan.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,15 @@ | ||
import { useMemo } from 'react' | ||
import { BulkRescanHosts } from '../../bulkActions/BulkRescanHosts' | ||
import { useHosts } from '../../../contexts/hosts' | ||
|
||
export function HostsRescan() { | ||
const { multiSelect } = useHosts() | ||
|
||
const publicKeys = useMemo( | ||
() => | ||
Object.entries(multiSelect.selection).map(([_, item]) => item.publicKey), | ||
[multiSelect.selection] | ||
) | ||
|
||
return <BulkRescanHosts multiSelect={multiSelect} publicKeys={publicKeys} /> | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { | ||
Button, | ||
handleBatchOperation, | ||
MultiSelect, | ||
MultiSelectRow, | ||
} from '@siafoundation/design-system' | ||
import { DataView16 } from '@siafoundation/react-icons' | ||
import { useHostScan } from '@siafoundation/renterd-react' | ||
import { useCallback } from 'react' | ||
import { pluralize, secondsInMilliseconds } from '@siafoundation/units' | ||
|
||
export function BulkRescanHosts<T extends MultiSelectRow>({ | ||
multiSelect, | ||
publicKeys, | ||
}: { | ||
multiSelect: MultiSelect<T> | ||
publicKeys: string[] | ||
}) { | ||
const scan = useHostScan() | ||
const scanAll = useCallback(async () => { | ||
await handleBatchOperation( | ||
publicKeys.map((publicKey) => | ||
scan.post({ | ||
params: { | ||
hostkey: publicKey, | ||
}, | ||
payload: { | ||
timeout: secondsInMilliseconds(30), | ||
}, | ||
}) | ||
), | ||
{ | ||
toastError: ({ successCount, errorCount, totalCount }) => ({ | ||
title: `Rescanning ${pluralize(successCount, 'host')}`, | ||
body: `Error starting rescan for ${errorCount}/${totalCount} of total hosts.`, | ||
}), | ||
toastSuccess: ({ totalCount }) => ({ | ||
title: `Rescanning ${pluralize(totalCount, 'host')}`, | ||
}), | ||
after: () => { | ||
multiSelect.deselectAll() | ||
}, | ||
} | ||
) | ||
}, [multiSelect, publicKeys, scan]) | ||
|
||
return ( | ||
<Button aria-label="rescan hosts" tip="Rescan hosts" onClick={scanAll}> | ||
<DataView16 /> | ||
</Button> | ||
) | ||
} |