-
Notifications
You must be signed in to change notification settings - Fork 15
Replace Listbox in Create Disk side modal with Combobox #2829
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
48a317d
b3a0a7d
a01a795
7f6b651
19621a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,10 +20,10 @@ import { | |
type Image, | ||
} from '@oxide/api' | ||
|
||
import { ComboboxField } from '~/components/form/fields/ComboboxField' | ||
import { DescriptionField } from '~/components/form/fields/DescriptionField' | ||
import { DiskSizeField } from '~/components/form/fields/DiskSizeField' | ||
import { toImageComboboxItem } from '~/components/form/fields/ImageSelectField' | ||
import { ListboxField } from '~/components/form/fields/ListboxField' | ||
import { NameField } from '~/components/form/fields/NameField' | ||
import { RadioField } from '~/components/form/fields/RadioField' | ||
import { SideModalForm } from '~/components/form/SideModalForm' | ||
|
@@ -171,6 +171,7 @@ const DiskSourceField = ({ | |
field: { value, onChange }, | ||
} = useController({ control, name: 'diskSource' }) | ||
const diskSizeField = useController({ control, name: 'size' }).field | ||
const diskImageIdField = useController({ control, name: 'diskSource.imageId' }).field | ||
|
||
return ( | ||
<> | ||
|
@@ -210,14 +211,17 @@ const DiskSourceField = ({ | |
/> | ||
)} | ||
{value.type === 'image' && ( | ||
<ListboxField | ||
<ComboboxField | ||
control={control} | ||
name="diskSource.imageId" | ||
label="Source image" | ||
placeholder="Select an image" | ||
placeholder="Select an image or enter an image name" | ||
isLoading={areImagesLoading} | ||
items={images.map((i) => toImageComboboxItem(i, true))} | ||
required | ||
onInputChange={() => { | ||
diskImageIdField.onChange() | ||
}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does this do? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It allows the modification of the underlying text value after the selection of one item, otherwise, the text value changes only by selecting another item in the list and not by input events. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense, and good catch. I think you can move this fix to the ComboboxField component by adding an It does seem like there's a funny interaction where selecting an option, then deleting some of the contents, then blurring the field by clicking outside the component then erases the selected option. Would there be a way to prevent that selected option from getting lost? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good, I'll prepare a change for this. For the first item: I'm guessing we should destructure There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for dropping this; yes, good call! Adding onInput Change to the ComboboxField props and calling something like
makes sense to me so we don't swallow anything passed through. Is that about what you were thinking? |
||
onChange={(id) => { | ||
const image = images.find((i) => i.id === id)! // if it's selected, it must be present | ||
const imageSizeGiB = image.size / GiB | ||
|
@@ -252,13 +256,17 @@ const SnapshotSelectField = ({ control }: { control: Control<DiskCreate> }) => { | |
|
||
const snapshots = snapshotsQuery.data?.items || [] | ||
const diskSizeField = useController({ control, name: 'size' }).field | ||
const diskSnapshotIdField = useController({ | ||
control, | ||
name: 'diskSource.snapshotId', | ||
}).field | ||
|
||
return ( | ||
<ListboxField | ||
<ComboboxField | ||
control={control} | ||
name="diskSource.snapshotId" | ||
label="Source snapshot" | ||
placeholder="Select a snapshot" | ||
placeholder="Select a snapshot or enter a snapshot name" | ||
items={snapshots.map((i) => { | ||
const formattedSize = filesize(i.size, { base: 2, output: 'object' }) | ||
return { | ||
|
@@ -278,6 +286,9 @@ const SnapshotSelectField = ({ control }: { control: Control<DiskCreate> }) => { | |
})} | ||
isLoading={snapshotsQuery.isPending} | ||
required | ||
onInputChange={() => { | ||
diskSnapshotIdField.onChange() | ||
}} | ||
onChange={(id) => { | ||
const snapshot = snapshots.find((i) => i.id === id)! // if it's selected, it must be present | ||
const snapshotSizeGiB = snapshot.size / GiB | ||
|
Uh oh!
There was an error while loading. Please reload this page.