@@ -17,7 +17,7 @@ export const durationOptions: { value: CostDuration; label: string }[] = [
1717 { value : "annually" , label : "Annually" } ,
1818] as const ;
1919
20- export const reservedTermOptions = [
20+ const sharedReservedTermOptions = [
2121 { value : "yrTerm1Standard.noUpfront" , label : "1-year - No Upfront" } ,
2222 {
2323 value : "yrTerm1Standard.partialUpfront" ,
@@ -55,3 +55,36 @@ export const reservedTermOptions = [
5555 label : "3-year convertible - Full Upfront" ,
5656 } ,
5757] ;
58+
59+ const savingsPlanExtras = {
60+ "yrTerm1Savings.noUpfront" : "1-year Savings Plan - No Upfront" ,
61+ "yrTerm1Savings.partialUpfront" : "1-year Savings Plan - Partial Upfront" ,
62+ "yrTerm1Savings.allUpfront" : "1-year Savings Plan - Full Upfront" ,
63+ "yrTerm3Savings.noUpfront" : "3-year Savings Plan - No Upfront" ,
64+ "yrTerm3Savings.partialUpfront" : "3-year Savings Plan - Partial Upfront" ,
65+ "yrTerm3Savings.allUpfront" : "3-year Savings Plan - Full Upfront" ,
66+ } ;
67+
68+ const savingsPlanCache = new Map < string , { value : string ; label : string } [ ] > ( ) ;
69+
70+ export type SupportedSavingsPlanOptions = keyof typeof savingsPlanExtras ;
71+
72+ export const reservedTermOptions = (
73+ savingsPlanSupported : SupportedSavingsPlanOptions [ ] | undefined ,
74+ ) => {
75+ if ( ! savingsPlanSupported ) return sharedReservedTermOptions ;
76+ const key = savingsPlanSupported . join ( "," ) ;
77+ const cached = savingsPlanCache . get ( key ) ;
78+ if ( cached ) return cached ;
79+
80+ const extras : { value : string ; label : string } [ ] = [ ] ;
81+ for ( const sp of savingsPlanSupported ) {
82+ const label = savingsPlanExtras [ sp ] ;
83+ if ( label ) {
84+ extras . push ( { value : sp , label } ) ;
85+ }
86+ }
87+ const options = [ ...extras , ...sharedReservedTermOptions ] ;
88+ savingsPlanCache . set ( key , options ) ;
89+ return options ;
90+ } ;
0 commit comments