Skip to content

Commit ab2939b

Browse files
authored
Filter out committed disks (#2262)
1 parent c9f2bba commit ab2939b

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

app/components/form/fields/DisksTableField.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ export function DisksTableField({
117117
onChange([...items, { type: 'attach', ...values }])
118118
setShowDiskAttach(false)
119119
}}
120+
diskNamesToExclude={items.filter((i) => i.type === 'attach').map((i) => i.name)}
120121
/>
121122
)}
122123
</>

app/forms/disk-attach.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type AttachDiskProps = {
1717
/** If defined, this overrides the usual mutation */
1818
onSubmit: (diskAttach: { name: string }) => void
1919
onDismiss: () => void
20+
diskNamesToExclude?: string[]
2021
loading?: boolean
2122
submitError?: ApiError | null
2223
}
@@ -28,6 +29,7 @@ type AttachDiskProps = {
2829
export function AttachDiskSideModalForm({
2930
onSubmit,
3031
onDismiss,
32+
diskNamesToExclude = [],
3133
loading,
3234
submitError = null,
3335
}: AttachDiskProps) {
@@ -39,7 +41,7 @@ export function AttachDiskSideModalForm({
3941
// TODO: error handling
4042
const detachedDisks =
4143
useApiQuery('diskList', { query: projectSelector }).data?.items.filter(
42-
(d) => d.state.state === 'detached'
44+
(d) => d.state.state === 'detached' && !diskNamesToExclude.includes(d.name)
4345
) || []
4446

4547
const form = useForm({ defaultValues })

test/e2e/instance-create.e2e.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,38 @@ test('start with an existing disk, but then switch to a silo image', async ({ pa
291291
await expectNotVisible(page, ['text=disk-7'])
292292
})
293293

294+
test('additional disks do not list committed disks as available', async ({ page }) => {
295+
await page.goto('/projects/mock-project/instances-new')
296+
297+
const attachExistingDiskButton = page.getByRole('button', {
298+
name: 'Attach existing disk',
299+
})
300+
const selectAnOption = page.getByRole('button', { name: 'Select an option' })
301+
const disk2 = page.getByRole('option', { name: 'disk-2' })
302+
const disk3 = page.getByRole('option', { name: 'disk-3' })
303+
const disk4 = page.getByRole('option', { name: 'disk-4' })
304+
305+
await attachExistingDiskButton.click()
306+
await selectAnOption.click()
307+
// disk-2 is already attached, so should not be visible in the list
308+
await expect(disk2).toBeHidden()
309+
// disk-3, though, should be present
310+
await expect(disk3).toBeVisible()
311+
await expect(disk4).toBeVisible()
312+
313+
// select disk-3 and "attach" it to the instance that will be created
314+
await disk3.click()
315+
await page.getByRole('button', { name: 'Attach disk' }).click()
316+
317+
await attachExistingDiskButton.click()
318+
await selectAnOption.click()
319+
// disk-2 should still be hidden
320+
await expect(disk2).toBeHidden()
321+
// now disk-3 should be hidden as well
322+
await expect(disk3).toBeHidden()
323+
await expect(disk4).toBeVisible()
324+
})
325+
294326
test('maintains selected values even when changing tabs', async ({ page }) => {
295327
const instanceName = 'arch-based-instance'
296328
await page.goto('/projects/mock-project/instances-new')

test/e2e/instance-disks.e2e.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ test('Attach disk', async ({ page }) => {
5858
await expectVisible(page, ['role=dialog >> text="Disk name is required"'])
5959

6060
await page.click('role=button[name*="Disk name"]')
61+
// disk-1 is already attached, so should not be visible in the list
62+
await expectNotVisible(page, ['role=option[name="disk-1"]'])
6163
await expectVisible(page, ['role=option[name="disk-3"]', 'role=option[name="disk-4"]'])
6264
await page.click('role=option[name="disk-3"]')
6365

0 commit comments

Comments
 (0)