1- import {
2- Avatar ,
3- Box ,
4- BoxProps ,
5- Dropdown ,
6- DropdownDetailedOption ,
7- DropdownGroup ,
8- Text ,
9- Toggletip ,
10- TypeIconName ,
11- } from '@bitrise/bitkit' ;
12- import { ReactNode , useMemo } from 'react' ;
1+ import { Avatar , Box , Dropdown , DropdownDetailedOption , DropdownGroup , Toggletip , TypeIconName } from '@bitrise/bitkit' ;
2+ import { ReactNode } from 'react' ;
133
14- import { MachineRegionName , MachineTypeOption , MachineTypeOptionGroup } from '@/core/models/StackAndMachine' ;
15- import { doesHardwareVaryByRegion , MachineTypeWithValue } from '@/core/services/StackAndMachineService' ;
4+ import { MachineTypeOption , MachineTypeOptionGroup } from '@/core/models/StackAndMachine' ;
5+ import { MachineTypeWithValue } from '@/core/services/StackAndMachineService' ;
166
177const getIconName = ( osId ?: string ) : TypeIconName | undefined => {
188 switch ( osId ) {
@@ -26,62 +16,34 @@ const getIconName = (osId?: string): TypeIconName | undefined => {
2616 }
2717} ;
2818
29- const renderOptions = ( machineTypeOptions : MachineTypeOption [ ] ) => {
30- return machineTypeOptions . map ( ( { isDisabled, label, os, subtitle, value } ) => {
31- const iconName = getIconName ( os ) ;
32-
19+ const renderOptions = ( machines : MachineTypeOption [ ] , isDisabled ?: boolean ) => {
20+ return machines . map ( ( machine ) => {
21+ const iconName = getIconName ( machine . os ) ;
3322 return (
3423 < DropdownDetailedOption
35- key = { value }
36- value = { value }
37- title = { label }
38- subtitle = { subtitle }
24+ key = { machine . value }
25+ value = { machine . value }
26+ title = { machine . label }
27+ subtitle = ""
3928 isDisabled = { isDisabled }
40- icon = { iconName && < Avatar variant = "brand" size = "32 " iconName = { iconName } /> }
29+ icon = { iconName && < Avatar variant = "brand" size = "24 " iconName = { iconName } /> }
4130 />
4231 ) ;
4332 } ) ;
4433} ;
4534
46- const renderFormLabel = ( machineTypeOption : MachineTypeOption ) => {
47- const { label, os } = machineTypeOption ;
48- const iconName = getIconName ( os ) ;
49-
50- return (
51- < Box display = "flex" gap = { 12 } alignItems = "center" >
52- { iconName && < Avatar variant = "brand" size = "24" iconName = { iconName } /> }
53- { label }
54- </ Box >
55- ) ;
56- } ;
57-
58- type Props = Pick < BoxProps , 'width' > & {
35+ type Props = {
5936 isLoading : boolean ;
6037 isInvalid : boolean ;
6138 isDisabled : boolean ;
6239 machineType : MachineTypeWithValue ;
6340 optionGroups : MachineTypeOptionGroup [ ] ;
6441 onChange : ( machineId : string ) => void ;
65- selectedRegion ?: MachineRegionName ;
6642} ;
6743
68- const MachineTypeSelector = ( {
69- isLoading,
70- isInvalid,
71- isDisabled,
72- machineType,
73- optionGroups,
74- onChange,
75- selectedRegion,
76- ...boxProps
77- } : Props ) => {
78- const doesHardwareVaryByRegionForSelectedMachineType = useMemo (
79- ( ) => doesHardwareVaryByRegion ( machineType ) ,
80- [ machineType ] ,
81- ) ;
82-
44+ const MachineTypeSelector = ( { isLoading, isInvalid, isDisabled, machineType, optionGroups, onChange } : Props ) => {
8345 const toggletip = ( icon : ReactNode ) => {
84- if ( ! optionGroups . find ( ( group ) => group . options . find ( ( option ) => option . isDisabled ) ) ) {
46+ if ( ! optionGroups . find ( ( group ) => group . status === 'promoted' ) ) {
8547 return null ;
8648 }
8749
@@ -97,48 +59,9 @@ const MachineTypeSelector = ({
9759 ) ;
9860 } ;
9961
100- const helperText = ( ) => {
101- if ( doesHardwareVaryByRegionForSelectedMachineType && ! selectedRegion ) {
102- return (
103- < Box as = "span" display = "flex" flexDir = "column" gap = { 8 } >
104- < Text as = "span" > Machine types may vary depending on high demand.</ Text >
105- { Object . entries ( machineType . availableInRegions ) . map ( ( [ regionName , machineTypeInfoText ] ) => {
106- return (
107- < Text as = "span" color = "input/text/helper" key = { regionName } textStyle = "body/sm/regular" >
108- < Text as = "span" fontWeight = "bold" >
109- { regionName } :
110- </ Text > { ' ' }
111- { machineTypeInfoText }
112- </ Text >
113- ) ;
114- } ) }
115- </ Box >
116- ) ;
117- }
118-
119- const region = selectedRegion || ( Object . keys ( machineType . availableInRegions ) [ 0 ] as MachineRegionName ) ;
120-
121- return (
122- < Text as = "span" color = "input/text/helper" textStyle = "body/sm/regular" >
123- { machineType . availableInRegions [ region ] }
124- </ Text >
125- ) ;
126- } ;
127-
128- let selectedOption : MachineTypeOption | null = null ;
129- optionGroups . find ( ( group ) => {
130- const option = group . options . find ( ( { value } ) => value === machineType . value ) ;
131- if ( option ) {
132- selectedOption = option ;
133- return true ;
134- }
135- } ) ;
136-
13762 return (
13863 < Dropdown
139- { ...boxProps }
14064 flex = "1"
141- formLabel = { selectedOption && renderFormLabel ( selectedOption ) }
14265 required
14366 search = { false }
14467 label = "Machine type"
@@ -147,7 +70,7 @@ const MachineTypeSelector = ({
14770 disabled = { isLoading || isDisabled }
14871 isError = { isInvalid }
14972 errorText = { isInvalid ? 'Invalid machine type' : undefined }
150- helperText = { helperText ( ) }
73+ helperText = { machineType . creditPerMinute ? ` ${ machineType . creditPerMinute } credits/min` : undefined }
15174 value = { machineType . value }
15275 onChange = { ( e ) => onChange ( e . target . value ?? '' ) }
15376 >
@@ -156,7 +79,7 @@ const MachineTypeSelector = ({
15679 < >
15780 { optionGroups . map ( ( group ) => (
15881 < DropdownGroup key = { group . label } label = { group . label } labelProps = { { whiteSpace : 'nowrap' } } >
159- { renderOptions ( group . options ) }
82+ { renderOptions ( group . options , group . status === 'promoted' ) }
16083 </ DropdownGroup >
16184 ) ) }
16285 </ >
0 commit comments