-
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(hostd): contracts multi-select and bulk integrity check
- Loading branch information
1 parent
b591ebf
commit 0171d92
Showing
18 changed files
with
288 additions
and
19 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 @@ | ||
--- | ||
'@siafoundation/clusterd': minor | ||
--- | ||
|
||
Added distinct renterdWaitForContracts and hostdWaitForContracts methods. |
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 @@ | ||
--- | ||
'hostd': minor | ||
--- | ||
|
||
The contracts table now supports bulk integrity checks. |
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 @@ | ||
--- | ||
'hostd': minor | ||
--- | ||
|
||
The contracts table now support 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
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,45 @@ | ||
import { Page } from '@playwright/test' | ||
import { maybeExpectAndReturn, step } from '@siafoundation/e2e' | ||
|
||
export const getContractRowById = step( | ||
'get contract row by ID', | ||
async (page: Page, id: string) => { | ||
return page.getByTestId('contractsTable').getByTestId(id) | ||
} | ||
) | ||
|
||
export const getContractsSummaryRow = step( | ||
'get contracts summary row', | ||
async (page: Page) => { | ||
return page | ||
.getByTestId('contractsTable') | ||
.locator('thead') | ||
.getByRole('row') | ||
.nth(1) | ||
} | ||
) | ||
|
||
export const getContractRowByIndex = step( | ||
'get contract row by index', | ||
async (page: Page, index: number, shouldExpect?: boolean) => { | ||
return maybeExpectAndReturn( | ||
page | ||
.getByTestId('contractsTable') | ||
.locator('tbody') | ||
.getByRole('row') | ||
.nth(index), | ||
shouldExpect | ||
) | ||
} | ||
) | ||
|
||
export function getContractRows(page: Page) { | ||
return page.getByTestId('contractsTable').locator('tbody').getByRole('row') | ||
} | ||
|
||
export const getContractRowsAll = step( | ||
'get contract rows', | ||
async (page: Page) => { | ||
return getContractRows(page).all() | ||
} | ||
) |
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,30 @@ | ||
import { test, expect } from '@playwright/test' | ||
import { navigateToContracts } from '../fixtures/navigate' | ||
import { afterTest, beforeTest } from '../fixtures/beforeTest' | ||
import { getContractRowsAll } from '../fixtures/contracts' | ||
|
||
test.beforeEach(async ({ page }) => { | ||
await beforeTest(page, { | ||
renterdCount: 2, | ||
}) | ||
}) | ||
|
||
test.afterEach(async () => { | ||
await afterTest() | ||
}) | ||
|
||
test('contracts bulk integrity check', async ({ page }) => { | ||
await navigateToContracts(page) | ||
const rows = await getContractRowsAll(page) | ||
for (const row of rows) { | ||
await row.click() | ||
} | ||
|
||
const menu = page.getByLabel('contract multi-select menu') | ||
|
||
// Run check for each contract. | ||
await menu.getByLabel('run integrity check for each contract').click() | ||
await expect( | ||
page.getByText('Integrity checks started for 2 contracts') | ||
).toBeVisible() | ||
}) |
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
70 changes: 70 additions & 0 deletions
70
apps/hostd/components/Contracts/ContractsBulkMenu/ContractsBulkIntegrityCheck.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,70 @@ | ||
import { | ||
Button, | ||
Code, | ||
handleBatchOperation, | ||
Link, | ||
} from '@siafoundation/design-system' | ||
import { DataCheck16 } from '@siafoundation/react-icons' | ||
import { useCallback, useMemo } from 'react' | ||
import { pluralize } from '@siafoundation/units' | ||
import { useContracts } from '../../../contexts/contracts' | ||
import { useContractsIntegrityCheck } from '@siafoundation/hostd-react' | ||
import { useDialog } from '../../../contexts/dialog' | ||
|
||
export function ContractsBulkIntegrityCheck() { | ||
const { openDialog } = useDialog() | ||
const { multiSelect } = useContracts() | ||
const integrityCheck = useContractsIntegrityCheck() | ||
|
||
const ids = useMemo( | ||
() => Object.entries(multiSelect.selectionMap).map(([_, item]) => item.id), | ||
[multiSelect.selectionMap] | ||
) | ||
const checkAll = useCallback(async () => { | ||
await handleBatchOperation( | ||
ids.map((id) => | ||
integrityCheck.put({ | ||
params: { | ||
id, | ||
}, | ||
}) | ||
), | ||
{ | ||
toastError: ({ successCount, errorCount, totalCount }) => ({ | ||
title: `Integrity checks started for ${pluralize( | ||
successCount, | ||
'contract' | ||
)}`, | ||
body: `Error starting integrity checks for ${errorCount}/${totalCount} total contracts.`, | ||
}), | ||
toastSuccess: ({ totalCount }) => ({ | ||
title: `Integrity checks started for ${pluralize( | ||
totalCount, | ||
'contract' | ||
)}`, | ||
body: ( | ||
<> | ||
Depending on contract data size this operation can take a while. | ||
Check <Code>hostd</Code>{' '} | ||
<Link onClick={() => openDialog('alerts')}>alerts</Link> for | ||
status updates. | ||
</> | ||
), | ||
}), | ||
after: () => { | ||
multiSelect.deselectAll() | ||
}, | ||
} | ||
) | ||
}, [multiSelect, ids, integrityCheck, openDialog]) | ||
|
||
return ( | ||
<Button | ||
aria-label="run integrity check for each contract" | ||
tip="Run integrity check for each contract" | ||
onClick={checkAll} | ||
> | ||
<DataCheck16 /> | ||
</Button> | ||
) | ||
} |
13 changes: 13 additions & 0 deletions
13
apps/hostd/components/Contracts/ContractsBulkMenu/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 { ContractsBulkIntegrityCheck } from './ContractsBulkIntegrityCheck' | ||
|
||
export function ContractsBulkMenu() { | ||
const { multiSelect } = useContracts() | ||
|
||
return ( | ||
<MultiSelectionMenu multiSelect={multiSelect} entityWord="contract"> | ||
<ContractsBulkIntegrityCheck /> | ||
</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
Oops, something went wrong.