Skip to content

Commit 4f1ba37

Browse files
authored
Instance create: fix for disk size updating on image tab switch (#3394)
Noticed while working on #3391. When you switch from project images to silo images (or vice versa), the disk size value is now updated to fit the disk from the tab you're landing on. Before it was checked against the image from the previous tab.
1 parent 14ec752 commit 4f1ba37

2 files changed

Lines changed: 31 additions & 3 deletions

File tree

‎app/forms/instance-create.tsx‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -703,9 +703,19 @@ export default function CreateInstanceForm() {
703703
// default to the project images tab if there are only project images
704704
defaultValue={defaultSource}
705705
onValueChange={(val) => {
706-
setValue('bootDiskSourceType', val as BootDiskSourceType)
707-
if (imageSizeGiB && imageSizeGiB > bootDiskSize) {
708-
setValue('bootDiskSize', diskSizeNearest10(imageSizeGiB))
706+
const sourceType = val as BootDiskSourceType
707+
setValue('bootDiskSourceType', sourceType)
708+
// size the disk for the image selected on the new tab, not the old one
709+
const newImageId = match(sourceType)
710+
.with('siloImage', () => siloImageSource)
711+
.with('projectImage', () => projectImageSource)
712+
.with('disk', () => undefined)
713+
.exhaustive()
714+
const newImage = allImages.find((i) => i.id === newImageId)
715+
if (!newImage) return
716+
const newImageSizeGiB = newImage.size / GiB
717+
if (newImageSizeGiB > bootDiskSize) {
718+
setValue('bootDiskSize', diskSizeNearest10(newImageSizeGiB))
709719
}
710720
}}
711721
>

‎test/e2e/instance-create.e2e.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,24 @@ test('duplicate instance name produces visible error', async ({ page }) => {
192192
await expect(page.getByText('Instance name already exists')).toBeVisible()
193193
})
194194

195+
test('switching image tabs sizes boot disk for the new tab', async ({ page }) => {
196+
await page.goto('/projects/mock-project/instances-new')
197+
const diskSizeInput = page.getByRole('textbox', { name: 'Disk size (GiB)' })
198+
199+
// 6 GiB image gets rounded up
200+
await selectAProjectImage(page, 'image-3')
201+
await expect(diskSizeInput).toHaveValue('10')
202+
203+
// 1 GiB image leaves the size alone, but we can now shrink it
204+
await selectASiloImage(page, 'ubuntu-22-04')
205+
await expect(diskSizeInput).toHaveValue('10')
206+
await fillNumberInput(diskSizeInput, '2')
207+
208+
// back on the project tab, image-3 is still selected and 2 GiB is too small
209+
await page.getByRole('tab', { name: 'Project images' }).click()
210+
await expect(diskSizeInput).toHaveValue('10')
211+
})
212+
195213
test('can create an instance with custom hardware', async ({ page }) => {
196214
await page.goto('/projects/mock-project/instances-new')
197215

0 commit comments

Comments
 (0)