Skip to content

Commit 60ca75e

Browse files
committed
helper to avoid instance update mistakes
1 parent 2c6de5d commit 60ca75e

File tree

5 files changed

+26
-19
lines changed

5 files changed

+26
-19
lines changed

app/api/util.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import type {
1515
DiskState,
1616
Instance,
1717
InstanceState,
18+
InstanceUpdate,
1819
Measurement,
1920
SiloUtilization,
2021
Sled,
@@ -281,3 +282,5 @@ export function synthesizeData(
281282
}
282283

283284
export const OXQL_GROUP_BY_ERROR = 'Input tables to a `group_by` must be aligned'
285+
286+
export const instanceUpdateBody = (body: Required<InstanceUpdate>): InstanceUpdate => body

app/pages/project/instances/AutoRestartCard.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
useApiMutation,
1818
usePrefetchedApiQuery,
1919
} from '~/api'
20+
import { instanceUpdateBody } from '~/api/util'
2021
import { ListboxField } from '~/components/form/fields/ListboxField'
2122
import { useInstanceSelector } from '~/hooks/use-params'
2223
import { addToast } from '~/stores/toast'
@@ -75,18 +76,18 @@ export function AutoRestartCard() {
7576
instanceUpdate.mutate({
7677
path: { instance: instanceSelector.instance },
7778
query: { project: instanceSelector.project },
78-
body: {
79+
body: instanceUpdateBody({
7980
autoRestartPolicy: match(values.autoRestartPolicy)
80-
.with('default', () => undefined)
81+
.with('default', () => null)
8182
.with('never', () => 'never' as const)
8283
.with('best_effort', () => 'best_effort' as const)
8384
.exhaustive(),
8485
ncpus: instance.ncpus,
8586
memory: instance.memory,
8687
// optional ones would be unset if we left them out
87-
cpuPlatform: instance.cpuPlatform,
88-
bootDisk: instance.bootDiskId,
89-
},
88+
cpuPlatform: instance.cpuPlatform || null,
89+
bootDisk: instance.bootDiskId || null,
90+
}),
9091
})
9192
})
9293

app/pages/project/instances/InstancePage.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
instanceAutoRestartingSoon,
2727
instanceCan,
2828
instanceTransitioning,
29+
instanceUpdateBody,
2930
} from '~/api/util'
3031
import { CopyIdItem } from '~/components/CopyIdItem'
3132
import { ExternalIps } from '~/components/ExternalIps'
@@ -341,14 +342,14 @@ export function ResizeInstanceModal({
341342
instanceUpdate.mutate({
342343
path: { instance: instance.name },
343344
query: { project },
344-
body: {
345+
body: instanceUpdateBody({
345346
ncpus,
346347
memory: memory * GiB,
347348
// these need to be passed in or they'll be unset
348-
bootDisk: instance.bootDiskId,
349-
cpuPlatform: instance.cpuPlatform,
350-
autoRestartPolicy: instance.autoRestartPolicy,
351-
},
349+
bootDisk: instance.bootDiskId || null,
350+
cpuPlatform: instance.cpuPlatform || null,
351+
autoRestartPolicy: instance.autoRestartPolicy || null,
352+
}),
352353
})
353354
})
354355
const formId = useId()

app/pages/project/instances/StorageTab.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
} from '@oxide/api'
2424
import { Storage24Icon } from '@oxide/design-system/icons/react'
2525

26+
import { instanceUpdateBody } from '~/api/util'
2627
import { HL } from '~/components/HL'
2728
import { DiskStateBadge } from '~/components/StateBadge'
2829
import { AttachDiskModalForm } from '~/forms/disk-attach'
@@ -163,14 +164,14 @@ export default function StorageTab() {
163164
doAction: () =>
164165
instanceUpdate({
165166
path: { instance: instance.id },
166-
body: {
167-
bootDisk: undefined,
167+
body: instanceUpdateBody({
168+
bootDisk: null,
168169
ncpus: instance.ncpus,
169170
memory: instance.memory,
170171
// optional ones would be unset if we left them out
171-
autoRestartPolicy: instance.autoRestartPolicy,
172-
cpuPlatform: instance.cpuPlatform,
173-
},
172+
autoRestartPolicy: instance.autoRestartPolicy || null,
173+
cpuPlatform: instance.cpuPlatform || null,
174+
}),
174175
}),
175176
errorTitle: 'Could not unset boot disk',
176177
modalTitle: 'Confirm unset boot disk',
@@ -229,14 +230,14 @@ export default function StorageTab() {
229230
doAction: () =>
230231
instanceUpdate({
231232
path: { instance: instance.id },
232-
body: {
233+
body: instanceUpdateBody({
233234
bootDisk: disk.id,
234235
ncpus: instance.ncpus,
235236
memory: instance.memory,
236237
// optional ones would be unset if we left them out
237-
autoRestartPolicy: instance.autoRestartPolicy,
238-
cpuPlatform: instance.cpuPlatform,
239-
},
238+
autoRestartPolicy: instance.autoRestartPolicy || null,
239+
cpuPlatform: instance.cpuPlatform || null,
240+
}),
240241
}),
241242
errorTitle: `Could not ${verb} boot disk`,
242243
modalTitle: `Confirm ${verb} boot disk`,

mock-api/msw/handlers.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,7 @@ export const handlers = makeHandlers({
643643

644644
// Undefined or missing is meaningful: it unsets the value
645645
instance.auto_restart_policy = body.auto_restart_policy
646+
instance.cpu_platform = body.cpu_platform
646647

647648
// We depart here from nexus in that nexus does both of the following
648649
// calculations at view time (when converting model to view). We can't

0 commit comments

Comments
 (0)