@@ -84,23 +84,29 @@ export const useKubeFlavors = (projectId: string, region: string) =>
8484 enabled : ! ! projectId && ! ! region ,
8585 } ) ;
8686
87- export const hasEnoughQuota = ( flavor : TFlavor , quota : TQuota ) => {
87+ export const hasEnoughQuota = ( flavor : Partial < TFlavor > , quota : TQuota ) => {
8888 if ( ! quota ?. instance ) return true ;
8989 const { instance } = quota ;
9090 if ( instance . usedInstances + 1 > ( instance . maxInstances || 0 ) ) return false ;
91- if ( instance . usedRAM + flavor . ram > ( instance . maxRam || 0 ) ) return false ;
92- if ( instance . usedCores + flavor . vcpus > ( instance . maxCores || 0 ) ) return false ;
91+ if ( instance . usedRAM + ( flavor . ram ?? 0 ) > ( instance . maxRam || 0 ) ) return false ;
92+ if ( instance . usedCores + ( flavor . vcpus ?? 0 ) > ( instance . maxCores || 0 ) ) return false ;
9393 return true ;
9494} ;
9595
9696export const useMergedKubeFlavors = ( projectId : string , region : string | null ) => {
97- const { data : flavors , isPending : isFlavorsPending } = useFlavors ( projectId , region ) ;
98- const { data : kubeFlavors , isPending : isKubeFlavorsPending } = useKubeFlavors ( projectId , region ) ;
97+ const { data : flavors , isPending : isFlavorsPending } = useFlavors ( projectId , region ?? '' ) ;
98+ const { data : kubeFlavors , isPending : isKubeFlavorsPending } = useKubeFlavors (
99+ projectId ,
100+ region ?? '' ,
101+ ) ;
99102 const { data : catalog , isPending : isCatalogPending } = useCatalog ( ) ;
100103 const { data : availability , isPending : isAvailabilityPending } =
101104 useProductAvailability ( projectId ) ;
102105
103- const { data : quota , isPending : isQuotaPending } = useProjectQuotaByRegion ( projectId , region ) ;
106+ const { data : quota , isPending : isQuotaPending } = useProjectQuotaByRegion (
107+ projectId ,
108+ region ?? '' ,
109+ ) ;
104110
105111 const isPending =
106112 isFlavorsPending ||
@@ -118,11 +124,12 @@ export const useMergedKubeFlavors = (projectId: string, region: string | null) =
118124 } ) ) ;
119125 return result
120126 . map ( ( flavor ) => {
121- const addon = catalog . addons . find ( ( _addon ) => _addon . planCode === flavor . planCodes . hourly ) ;
127+ const addon = catalog . addons . find ( ( _addon ) => _addon . planCode === flavor . planCodes ? .hourly ) ;
122128 const addonMonthly = catalog . addons . find (
123- ( _addon ) => _addon . planCode === flavor . planCodes . monthly ,
129+ ( _addon ) => _addon . planCode === flavor . planCodes ? .monthly ,
124130 ) ;
125- const plan = availability . plans ?. find ( ( _plan ) => _plan . code === flavor . planCodes . hourly ) ;
131+ const plan = availability . plans ?. find ( ( _plan ) => _plan . code === flavor . planCodes ?. hourly ) ;
132+ const planRegionTypes = new Set ( plan ?. regions ?. map ( ( _region ) => _region . type ) ) ;
126133
127134 // Bugfix: Issue with selecting the correct monthly price in the US
128135 // -----------------------------------------------------------
@@ -144,27 +151,25 @@ export const useMergedKubeFlavors = (projectId: string, region: string | null) =
144151 ...flavor ,
145152 blobs : addon ?. blobs ,
146153 compatibility : Object . values ( DeploymentMode ) . reduce (
147- ( acc , value ) => ( {
148- ...acc ,
149- [ value ] : plan ?. regions ?. some ( ( _region ) => _region . type === value ) ,
150- } ) ,
154+ ( acc , value ) => ( { ...acc , [ value ] : planRegionTypes . has ( value ) } ) ,
151155 { } ,
152156 ) as Record < DeploymentMode , boolean > ,
153157
154158 pricingsHourly : addon ?. pricings ?. [ 0 ] ,
155159 pricingsMonthly : priceMonthly ,
156160 isNew : addon ?. blobs . tags . includes ( 'is_new' ) ,
157- flavorCategory : FLAVOR_CATEGORIES . find ( ( cat ) => cat . pattern . test ( flavor . type ) ) ?. category ,
158- isFlex : / f l e x $ / . test ( flavor . name ) ,
159- isLegacy : / e g | s p | h g | v p s - s s d / . test ( flavor . name ) ,
161+ flavorCategory : FLAVOR_CATEGORIES . find ( ( cat ) => cat . pattern . test ( flavor . type ?? '' ) )
162+ ?. category ,
163+ isFlex : / f l e x $ / . test ( flavor . name ?? '' ) ,
164+ isLegacy : / e g | s p | h g | v p s - s s d / . test ( flavor . name ?? '' ) ,
160165 hasEnoughQuota : hasEnoughQuota ( flavor , quota ) ,
161166 } ;
162167 } )
163168 . sort ( ( a , b ) => {
164- const aGroup = Number ( ( a . name . match ( / [ 0 - 9 ] + / ) || [ ] ) [ 0 ] ) ;
165- const bGroup = Number ( ( b . name . match ( / [ 0 - 9 ] + / ) || [ ] ) [ 0 ] ) ;
166- const aRank = Number ( ( a . name . match ( / - ( [ ^ - ] + ) $ / ) || [ ] ) [ 1 ] ) ;
167- const bRank = Number ( ( b . name . match ( / - ( [ ^ - ] + ) $ / ) || [ ] ) [ 1 ] ) ;
169+ const aGroup = Number ( ( a . name ? .match ( / [ 0 - 9 ] + / ) || [ ] ) [ 0 ] ) ;
170+ const bGroup = Number ( ( b . name ? .match ( / [ 0 - 9 ] + / ) || [ ] ) [ 0 ] ) ;
171+ const aRank = Number ( ( a . name ? .match ( / - ( [ ^ - ] + ) $ / ) || [ ] ) [ 1 ] ) ;
172+ const bRank = Number ( ( b . name ? .match ( / - ( [ ^ - ] + ) $ / ) || [ ] ) [ 1 ] ) ;
168173 if ( aGroup === bGroup ) return aRank - bRank ;
169174 return bGroup - aGroup ;
170175 } ) ;
0 commit comments