Skip to content

Commit

Permalink
feat(renterd): bulk rescan hosts
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfreska committed Dec 17, 2024
1 parent e15f47a commit 2540a0e
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/itchy-shoes-lick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'renterd': minor
---

The host and contracts multi-select menus both now include an option to rescan the selected hosts.
12 changes: 12 additions & 0 deletions apps/renterd-e2e/src/specs/contracts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ test('contracts bulk delete', async ({ page }) => {
await expect(page.getByText('3 contracts deleted')).toBeVisible()
})

test('contracts bulk rescan', async ({ page }) => {
await navigateToContracts({ page })
const rows = await getContractRowsAll(page)
rows.at(0).click()
rows.at(-1).click({ modifiers: ['Shift'] })

// Rescan selected hosts.
const menu = page.getByLabel('contract multi-select menu')
await menu.getByLabel('rescan selected hosts').click()
await expect(page.getByText('rescanning 3 hosts')).toBeVisible()
})

test('contracts bulk allowlist', async ({ page }) => {
await navigateToContracts({ page })
const rows = await getContractRowsAll(page)
Expand Down
12 changes: 12 additions & 0 deletions apps/renterd-e2e/src/specs/hosts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ test('hosts bulk allowlist', async ({ page }) => {
).toHaveCount(3)
})

test('hosts bulk rescan', async ({ page }) => {
await navigateToHosts({ page })
const rows = await getHostRowsAll(page)
rows.at(0).click()
rows.at(-1).click({ modifiers: ['Shift'], position: { x: 5, y: 5 } })

// Rescan selected hosts.
const menu = page.getByLabel('host multi-select menu')
await menu.getByLabel('rescan selected hosts').click()
await expect(page.getByText('rescanning 3 hosts')).toBeVisible()
})

test('hosts bulk blocklist', async ({ page }) => {
await navigateToHosts({ page })
const rows = await getHostRowsAll(page)
Expand Down
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} />
}
2 changes: 2 additions & 0 deletions apps/renterd/components/Contracts/ContractsBulkMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ContractsAddBlocklist } from './ContractsAddBlocklist'
import { ContractsAddAllowlist } from './ContractsAddAllowlist'
import { ContractsRemoveBlocklist } from './ContractsRemoveBlocklist'
import { ContractsRemoveAllowlist } from './ContractsRemoveAllowlist'
import { ContractsRescanHosts } from './ContractsRescanHosts'

export function ContractsBulkMenu() {
const { multiSelect } = useContracts()
Expand All @@ -19,6 +20,7 @@ export function ContractsBulkMenu() {
<ContractsRemoveAllowlist />
<ContractsRemoveBlocklist />
</div>
<ContractsRescanHosts />
<ContractsBulkDelete />
</MultiSelectionMenu>
)
Expand Down
15 changes: 15 additions & 0 deletions apps/renterd/components/Hosts/HostsBulkMenu/HostsRescan.tsx
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} />
}
2 changes: 2 additions & 0 deletions apps/renterd/components/Hosts/HostsBulkMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { HostsAddAllowlist } from './HostsAddAllowlist'
import { HostsRemoveBlocklist } from './HostsRemoveBlocklist'
import { HostsRemoveAllowlist } from './HostsRemoveAllowlist'
import { useHosts } from '../../../contexts/hosts'
import { HostsRescan } from './HostsRescan'

export function HostsBulkMenu() {
const { multiSelect } = useHosts()
Expand All @@ -19,6 +20,7 @@ export function HostsBulkMenu() {
<HostsRemoveAllowlist />
<HostsRemoveBlocklist />
</div>
<HostsRescan />
<HostsResetLostSectorCount />
</MultiSelectionMenu>
)
Expand Down
56 changes: 56 additions & 0 deletions apps/renterd/components/bulkActions/BulkRescanHosts.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
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 selected hosts"
tip="Rescan selected hosts"
onClick={scanAll}
>
<DataView16 />
</Button>
)
}

0 comments on commit 2540a0e

Please sign in to comment.