Skip to content

Commit c008d36

Browse files
authored
Fix instance delete success callback (#2165)
* fix instance delete success callback * obviously we should make sure the instance isn't there anymore
1 parent 6334f0d commit c008d36

File tree

5 files changed

+25
-19
lines changed

5 files changed

+25
-19
lines changed

app/pages/project/instances/InstancesPage.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ export function InstancesPage() {
5959
const queryClient = useApiQueryClient()
6060
const refetchInstances = () => queryClient.invalidateQueries('instanceList')
6161

62-
const makeActions = useMakeInstanceActions({ project }, { onSuccess: refetchInstances })
62+
const makeActions = useMakeInstanceActions(
63+
{ project },
64+
{ onSuccess: refetchInstances, onDelete: refetchInstances }
65+
)
6366

6467
const { data: instances } = usePrefetchedApiQuery('instanceList', {
6568
query: { project, limit: PAGE_SIZE },

app/pages/project/instances/actions.tsx

+5-14
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ export const useMakeInstanceActions = (
4040
const startInstance = useApiMutation('instanceStart', opts)
4141
const stopInstance = useApiMutation('instanceStop', opts)
4242
const rebootInstance = useApiMutation('instanceReboot', opts)
43-
const deleteInstance = useApiMutation('instanceDelete', opts)
43+
// delete has its own
44+
const deleteInstance = useApiMutation('instanceDelete', { onSuccess: options.onDelete })
4445

4546
return useCallback(
4647
(instance) => {
@@ -123,10 +124,8 @@ export const useMakeInstanceActions = (
123124
onActivate: confirmDelete({
124125
doDelete: () =>
125126
deleteInstance.mutateAsync(instanceParams, {
126-
onSuccess: () => {
127-
options.onDelete?.()
128-
addToast({ title: `Deleting instance '${instance.name}'` })
129-
},
127+
onSuccess: () =>
128+
addToast({ title: `Deleting instance '${instance.name}'` }),
130129
}),
131130
label: instance.name,
132131
resourceKind: 'instance',
@@ -138,14 +137,6 @@ export const useMakeInstanceActions = (
138137
},
139138
]
140139
},
141-
[
142-
projectSelector,
143-
deleteInstance,
144-
navigate,
145-
options,
146-
rebootInstance,
147-
startInstance,
148-
stopInstance,
149-
]
140+
[projectSelector, deleteInstance, navigate, rebootInstance, startInstance, stopInstance]
150141
)
151142
}

test/e2e/instance/disks.e2e.ts renamed to test/e2e/instance-disks.e2e.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
expectVisible,
1414
stopInstance,
1515
test,
16-
} from '../utils'
16+
} from './utils'
1717

1818
test('Attach disk', async ({ page }) => {
1919
await page.goto('/projects/mock-project/instances/db1')

test/e2e/instance/networking.e2e.ts renamed to test/e2e/instance-networking.e2e.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import {
1313
expectRowVisible,
1414
expectVisible,
1515
stopInstance,
16-
} from '../utils'
16+
} from './utils'
1717

18-
test('Instance networking tab — NIC table', async ({ page }) => {
18+
test('Instance networking tab — NIC table', async ({ page }) => {
1919
await page.goto('/projects/mock-project/instances/db1')
2020

2121
// links to VPC and external IPs appear in table

test/e2e/instance/list.e2e.ts renamed to test/e2e/instance.e2e.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* Copyright Oxide Computer Company
77
*/
8-
import { expect, test } from '../utils'
8+
import { expect, test } from './utils'
99

1010
test('can delete a failed instance', async ({ page }) => {
1111
await page.goto('/projects/mock-project/instances')
@@ -60,3 +60,15 @@ test('can stop a starting instance', async ({ page }) => {
6060

6161
await expect(row.getByRole('cell', { name: /stopped/ })).toBeVisible()
6262
})
63+
64+
test('delete from instance detail', async ({ page }) => {
65+
await page.goto('/projects/mock-project/instances/you-fail')
66+
67+
await page.getByRole('button', { name: 'Instance actions' }).click()
68+
await page.getByRole('menuitem', { name: 'Delete' }).click()
69+
await page.getByRole('button', { name: 'Confirm' }).click()
70+
71+
await expect(page).toHaveURL('/projects/mock-project/instances')
72+
await expect(page.getByRole('cell', { name: 'db1' })).toBeVisible()
73+
await expect(page.getByRole('cell', { name: 'you-fail' })).toBeHidden()
74+
})

0 commit comments

Comments
 (0)