@@ -79,11 +79,13 @@ const Utils = Object.assign({}, require('./base/_utils'), {
7979 const variation =
8080 variations &&
8181 variations . find ( ( env ) => env . multivariate_feature_option === v . id )
82- total += variation
83- ? variation . percentage_allocation
84- : typeof v . default_percentage_allocation === 'number'
85- ? v . default_percentage_allocation
86- : ( v as any ) . percentage_allocation
82+ if ( variation ) {
83+ total += variation . percentage_allocation
84+ } else if ( typeof v . default_percentage_allocation === 'number' ) {
85+ total += v . default_percentage_allocation
86+ } else {
87+ total += ( v as any ) . percentage_allocation
88+ }
8789 return null
8890 } )
8991 return 100 - total
@@ -157,15 +159,21 @@ const Utils = Object.assign({}, require('./base/_utils'), {
157159 displayLimitAlert ( type : string , percentage : number | undefined ) {
158160 const envOrProject =
159161 type === 'segment overrides' ? 'environment' : 'project'
160- return percentage >= 100 ? (
161- < ErrorMessage
162- error = { `Your ${ envOrProject } reached the limit of ${ type } , please contact support to discuss increasing this limit.` }
163- />
164- ) : percentage ? (
165- < WarningMessage
166- warningMessage = { `Your ${ envOrProject } is using ${ percentage } % of the total allowance of ${ type } .` }
167- />
168- ) : null
162+ if ( percentage >= 100 ) {
163+ return (
164+ < ErrorMessage
165+ error = { `Your ${ envOrProject } reached the limit of ${ type } , please contact support to discuss increasing this limit.` }
166+ />
167+ )
168+ }
169+ if ( percentage ) {
170+ return (
171+ < WarningMessage
172+ warningMessage = { `Your ${ envOrProject } is using ${ percentage } % of the total allowance of ${ type } .` }
173+ />
174+ )
175+ }
176+ return null
169177 } ,
170178 escapeHtml ( html : string ) {
171179 const text = document . createTextNode ( html )
@@ -477,11 +485,13 @@ const Utils = Object.assign({}, require('./base/_utils'), {
477485 } ,
478486 getPlansPermission : ( feature : PaidFeature ) => {
479487 const isOrgPermission = feature !== '2FA'
480- const plans = isOrgPermission
481- ? AccountStore . getActiveOrgPlan ( )
482- ? [ AccountStore . getActiveOrgPlan ( ) ]
483- : null
484- : AccountStore . getPlans ( )
488+ let plans : string [ ] | null
489+ if ( isOrgPermission ) {
490+ const activeOrgPlan = AccountStore . getActiveOrgPlan ( )
491+ plans = activeOrgPlan ? [ activeOrgPlan ] : null
492+ } else {
493+ plans = AccountStore . getPlans ( )
494+ }
485495
486496 if ( ! plans || ! plans . length ) {
487497 return false
@@ -669,7 +679,23 @@ const Utils = Object.assign({}, require('./base/_utils'), {
669679 head . appendChild ( script )
670680 } )
671681 } ,
672-
682+ mapMvOptionsToStateValues (
683+ mvOptions : MultivariateOption [ ] ,
684+ existingMvFeatureStateValues : MultivariateFeatureStateValue [ ] ,
685+ ) : MultivariateFeatureStateValue [ ] {
686+ return mvOptions ?. map ( ( mvOption ) => {
687+ const existing = existingMvFeatureStateValues ?. find (
688+ ( e ) => e . multivariate_feature_option === mvOption . id ,
689+ )
690+ return {
691+ id : mvOption . id ,
692+ multivariate_feature_option : mvOption . id ,
693+ percentage_allocation :
694+ existing ?. percentage_allocation ??
695+ mvOption . default_percentage_allocation ,
696+ }
697+ } )
698+ } ,
673699 numberWithCommas ( x : number ) {
674700 if ( typeof x !== 'number' ) return ''
675701 return x . toString ( ) . replace ( / \B (? = ( \d { 3 } ) + (? ! \d ) ) / g, ',' )
0 commit comments