Skip to content

Commit 1dd25f6

Browse files
Add confirmation modal for disk detachment (#2615)
* Add confirmation modal for disk detachment * add in a few confirmation clicks in tests * danger, will robinson * save 4 lines --------- Co-authored-by: David Crespo <david.crespo@oxidecomputer.com>
1 parent 11486f8 commit 1dd25f6

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

app/pages/project/instances/instance/tabs/StorageTab.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export function Component() {
8787
[instanceName, project]
8888
)
8989

90-
const { mutate: detachDisk } = useApiMutation('instanceDiskDetach', {
90+
const { mutateAsync: detachDisk } = useApiMutation('instanceDiskDetach', {
9191
onSuccess(disk) {
9292
queryClient.invalidateQueries('instanceDiskList')
9393
addToast(<>Disk <HL>{disk.name}</HL> detached</>) // prettier-ignore
@@ -262,9 +262,15 @@ export function Component() {
262262
detached
263263
</>
264264
),
265-
onActivate() {
266-
detachDisk({ body: { disk: disk.name }, path: { instance: instance.id } })
267-
},
265+
onActivate: () =>
266+
confirmAction({
267+
doAction: () =>
268+
detachDisk({ body: { disk: disk.name }, path: { instance: instance.id } }),
269+
errorTitle: 'Could not detach disk',
270+
modalTitle: 'Confirm detach disk',
271+
modalContent: <p>Are you sure you want to detach <HL>{disk.name}</HL>?</p>, // prettier-ignore
272+
actionType: 'danger',
273+
}),
268274
},
269275
],
270276
[

test/e2e/instance-disks.e2e.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ test('Detach disk', async ({ page }) => {
140140
await expect(successMsg).toBeHidden()
141141

142142
await clickRowAction(page, 'disk-2', 'Detach')
143+
await page.getByRole('button', { name: 'Confirm' }).click()
143144
await expect(successMsg).toBeVisible()
144145
await expect(row).toBeHidden() // disk row goes away
145146
})
@@ -204,6 +205,7 @@ test('Change boot disk', async ({ page }) => {
204205

205206
// detach disk so there's only one
206207
await clickRowAction(page, 'disk-2', 'Detach')
208+
await page.getByRole('button', { name: 'Confirm' }).click()
207209

208210
await expect(page.getByText('Instance will boot from disk-1')).toBeVisible()
209211

@@ -221,6 +223,8 @@ test('Change boot disk', async ({ page }) => {
221223
await expectRowVisible(otherDisksTable, disk1)
222224

223225
await clickRowAction(page, 'disk-1', 'Detach')
226+
await page.getByRole('button', { name: 'Confirm' }).click()
227+
224228
await expect(noBootDisk).toBeVisible()
225229
await expect(noOtherDisks).toBeVisible()
226230

0 commit comments

Comments
 (0)