Skip to content

Commit 6976890

Browse files
authored
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
1 parent 86453aa commit 6976890

File tree

5 files changed

+236
-113
lines changed

5 files changed

+236
-113
lines changed

app/components/form/fields/ImageSelectField.tsx

Lines changed: 5 additions & 3 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,19 +20,21 @@ type ImageSelectFieldProps = {
1920
images: Image[]
2021
control: Control<InstanceCreateInput>
2122
disabled?: boolean
23+
name: 'siloImageSource' | 'projectImageSource'
2224
}
2325

2426
export function BootDiskImageSelectField({
2527
images,
2628
control,
2729
disabled,
30+
name,
2831
}: ImageSelectFieldProps) {
2932
const diskSizeField = useController({ control, name: 'bootDiskSize' }).field
3033
return (
3134
<ListboxField
3235
disabled={disabled}
3336
control={control}
34-
name="bootDiskSource"
37+
name={name}
3538
label="Image"
3639
placeholder="Select an image"
3740
items={images.map((i) => toListboxItem(i))}
@@ -40,8 +43,7 @@ export function BootDiskImageSelectField({
4043
const image = images.find((i) => i.id === id)! // if it's selected, it must be present
4144
const imageSizeGiB = image.size / GiB
4245
if (diskSizeField.value < imageSizeGiB) {
43-
const nearest10 = Math.ceil(imageSizeGiB / 10) * 10
44-
diskSizeField.onChange(nearest10)
46+
diskSizeField.onChange(nearest10(imageSizeGiB))
4547
}
4648
}}
4749
/>

0 commit comments

Comments
 (0)