Skip to content

Commit 2cfc8ee

Browse files
benjaminleonarddavid-crespocharliepark
authored
Create instance from existing boot disk (#2076)
* Create instance from existing boot disk * Remove setting undefined on tab change (for now) * Improve descriptions * copy tweaks * tweak empty states copy, fix diskList prefetch * Fix issue with sourceType overload on project vs silo images and disks (#2097) * Fix issue with sourceType collision on project vs silo images and disks * refactor * Refactoring, and updating types * Maintain state of fields across tab navigation (#2100) * Simplify test; make it work for Safari * Clean up and add comments * verify in test that correct image used * clean up comment * imageSize -> imageSizeGiB --------- Co-authored-by: David Crespo <david.crespo@oxidecomputer.com> Co-authored-by: Charlie Park <charlie@oxidecomputer.com>
1 parent 11411bb commit 2cfc8ee

File tree

6 files changed

+295
-98
lines changed

6 files changed

+295
-98
lines changed

app/api/util.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ export const diskCan = mapValues(
118118
delete: ['detached', 'creating', 'faulted'],
119119
// TODO: link to API source
120120
snapshot: ['attached', 'detached'],
121+
// https://github.com/oxidecomputer/omicron/blob/4970c71e/nexus/db-queries/src/db/datastore/disk.rs#L169-L172
122+
attach: ['creating', 'detached'],
121123
},
122124
(states: DiskState['state'][]) => {
123125
// only have to Pick because we want this to work for both Disk and

app/components/form/fields/ImageSelectField.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type { Image } from '@oxide/api'
1111

1212
import type { InstanceCreateInput } from '~/forms/instance-create'
1313
import type { ListboxItem } from '~/ui/lib/Listbox'
14+
import { nearest10 } from '~/util/math'
1415
import { bytesToGiB, GiB } from '~/util/units'
1516

1617
import { ListboxField } from './ListboxField'
@@ -19,24 +20,30 @@ type ImageSelectFieldProps = {
1920
images: Image[]
2021
control: Control<InstanceCreateInput>
2122
disabled?: boolean
23+
name: 'siloImageSource' | 'projectImageSource'
2224
}
2325

24-
export function ImageSelectField({ images, control, disabled }: ImageSelectFieldProps) {
26+
export function BootDiskImageSelectField({
27+
images,
28+
control,
29+
disabled,
30+
name,
31+
}: ImageSelectFieldProps) {
2532
const diskSizeField = useController({ control, name: 'bootDiskSize' }).field
2633
return (
2734
<ListboxField
2835
disabled={disabled}
2936
control={control}
30-
name="image"
37+
name={name}
38+
label="Image"
3139
placeholder="Select an image"
3240
items={images.map((i) => toListboxItem(i))}
3341
required
3442
onChange={(id) => {
3543
const image = images.find((i) => i.id === id)! // if it's selected, it must be present
3644
const imageSizeGiB = image.size / GiB
3745
if (diskSizeField.value < imageSizeGiB) {
38-
const nearest10 = Math.ceil(imageSizeGiB / 10) * 10
39-
diskSizeField.onChange(nearest10)
46+
diskSizeField.onChange(nearest10(imageSizeGiB))
4047
}
4148
}}
4249
/>

0 commit comments

Comments
 (0)