@@ -9,7 +9,7 @@ import { useController, type Control } from 'react-hook-form'
99
1010import type { Image } from '@oxide/api'
1111import type { ListboxItem } from '@oxide/ui'
12- import { GiB } from '@oxide/util'
12+ import { bytesToGiB , GiB } from '@oxide/util'
1313
1414import type { InstanceCreateInput } from 'app/forms/instance-create'
1515
@@ -41,22 +41,43 @@ export function ImageSelectField({ images, control }: ImageSelectFieldProps) {
4141 )
4242}
4343
44- const Slash = ( ) => < span className = "mx-0.5 text-quinary" > /</ span >
44+ const Slash = ( ) => (
45+ < span className = "mx-1 text-quinary selected:text-accent-disabled" > /</ span >
46+ )
4547
4648export function toListboxItem ( i : Image , includeProjectSiloIndicator = false ) : ListboxItem {
47- const projectSiloIndicator = includeProjectSiloIndicator ? (
48- < >
49- < Slash /> { i . projectId ? 'Project image' : 'Silo image' }
50- </ >
51- ) : null
49+ const { name, os, projectId, size, version } = i
50+ const formattedSize = `${ bytesToGiB ( size , 1 ) } GiB`
51+
52+ // filter out any undefined metadata and create a comma-separated list
53+ // for the selected listbox item (shown in labelString)
54+ const condensedImageMetadata = [ os , version , formattedSize ] . filter ( ( i ) => ! ! i ) . join ( ', ' )
55+ const metadataForLabelString = condensedImageMetadata . length
56+ ? ` (${ condensedImageMetadata } )`
57+ : ''
58+
59+ // for metadata showing in the dropdown's options, include the project / silo indicator if requested
60+ const projectSiloIndicator = includeProjectSiloIndicator
61+ ? `${ projectId ? 'Project' : 'Silo' } image`
62+ : null
63+ // filter out undefined metadata here, as well, and create a `<Slash />`-separated list
64+ // for the listbox item (shown for each item in the dropdown)
65+ const metadataForLabel = [ os , version , formattedSize , projectSiloIndicator ]
66+ . filter ( ( i ) => ! ! i )
67+ . map ( ( i , index ) => (
68+ < span key = { `${ i } ` } >
69+ { index > 0 ? < Slash /> : '' }
70+ { i }
71+ </ span >
72+ ) )
5273 return {
5374 value : i . id ,
54- labelString : `${ i . name } ( ${ i . os } , ${ i . version } ) ` ,
75+ labelString : `${ name } ${ metadataForLabelString } ` ,
5576 label : (
5677 < >
57- < div > { i . name } </ div >
58- < div className = "text-secondary" >
59- { i . os } < Slash /> { i . version } { projectSiloIndicator }
78+ < div > { name } </ div >
79+ < div className = "text-tertiary selected:text-accent- secondary" >
80+ { metadataForLabel }
6081 </ div >
6182 </ >
6283 ) ,
0 commit comments