@@ -479,7 +479,6 @@ export const getSuppressionRulesArray = (detector: Detector): string[] => {
479
479
return `Ignore anomalies for feature "${ featureName } " when actual value is below the expected value` ;
480
480
}
481
481
482
-
483
482
let value = condition . value ;
484
483
const isPercentage =
485
484
thresholdType === ThresholdType . ACTUAL_OVER_EXPECTED_RATIO ||
@@ -558,15 +557,14 @@ export const getSuppressionRulesArrayForFeature = (
558
557
export const formikToRules = (
559
558
formikValues ?: RuleFormikValues [ ]
560
559
) : Rule [ ] | undefined => {
561
-
562
560
if ( ! formikValues || formikValues . length === 0 ) {
563
561
return undefined ; // Return undefined for undefined or empty input
564
562
}
565
563
566
- // Flatten the nested array of suppressionRule by feature and filter out null entries
567
- const flattenedSuppressionFormikValues = formikValues . flatMap ( ( nestedArray ) =>
568
- nestedArray || [ ] // If null, replace with an empty array
569
- ) ;
564
+ // Flatten the nested array of suppressionRule by feature and filter out null entries
565
+ const flattenedSuppressionFormikValues = formikValues . flatMap (
566
+ ( nestedArray ) => nestedArray || [ ] // If null, replace with an empty array
567
+ ) ;
570
568
571
569
return flattenedSuppressionFormikValues . map ( ( formikValue ) => {
572
570
const conditions : Condition [ ] = [ ] ;
@@ -592,12 +590,14 @@ export const formikToRules = (
592
590
}
593
591
} ;
594
592
595
-
596
-
597
593
if ( formikValue . directionRule ) {
598
594
conditions . push ( {
599
595
featureName : formikValue . featureName ,
600
- thresholdType : getThresholdType ( formikValue . aboveBelow , true , formikValue . directionRule ) ,
596
+ thresholdType : getThresholdType (
597
+ formikValue . aboveBelow ,
598
+ true ,
599
+ formikValue . directionRule
600
+ ) ,
601
601
operator : undefined ,
602
602
value : undefined ,
603
603
} ) ;
@@ -647,28 +647,26 @@ export const formikToRules = (
647
647
} ) ;
648
648
} ;
649
649
650
- // Convert Rule[] to RuleFormikValues[][]
651
- export const rulesToFormik = ( rules ?: Rule [ ] ) : ( RuleFormikValues [ ] | null ) [ ] => {
650
+ export const rulesToFormik = (
651
+ rules ?: Rule [ ]
652
+ ) : ( RuleFormikValues [ ] | null ) [ ] => {
652
653
if ( ! rules || rules . length === 0 ) {
653
- return [ ] ; // Return empty array for undefined or empty input
654
+ return [ ] ;
654
655
}
655
656
// Group rules by featureName
656
657
const groupedRules : { [ featureName : string ] : RuleFormikValues [ ] } = { } ;
657
658
658
659
rules . forEach ( ( rule ) => {
659
- // Start with default values for each rule
660
- const formikValue : RuleFormikValues = {
661
- featureName : '' ,
662
- absoluteThreshold : undefined ,
663
- relativeThreshold : undefined ,
664
- aboveBelow : 'above' , // Default to 'above', adjust as needed
665
- } ;
666
-
667
- // Loop through conditions to populate formikValue
668
660
rule . conditions . forEach ( ( condition ) => {
669
- formikValue . featureName = condition . featureName ;
661
+ // Create a new formikValue for each condition
662
+ const formikValue : RuleFormikValues = {
663
+ featureName : condition . featureName ,
664
+ absoluteThreshold : undefined ,
665
+ relativeThreshold : undefined ,
666
+ aboveBelow : 'above' , // Default to 'above', adjust as needed
667
+ } ;
670
668
671
- // Determine the value and type of threshold
669
+ // Populate formikValue based on threshold type
672
670
switch ( condition . thresholdType ) {
673
671
case ThresholdType . ACTUAL_OVER_EXPECTED_MARGIN :
674
672
formikValue . absoluteThreshold = condition . value ;
@@ -679,13 +677,11 @@ export const rulesToFormik = (rules?: Rule[]): (RuleFormikValues[] | null)[] =>
679
677
formikValue . aboveBelow = 'below' ;
680
678
break ;
681
679
case ThresholdType . ACTUAL_OVER_EXPECTED_RATIO :
682
- // *100 to convert to percentage
683
- formikValue . relativeThreshold = ( condition . value ?? 1 ) * 100 ;
680
+ formikValue . relativeThreshold = ( condition . value ?? 1 ) * 100 ; // Convert to percentage
684
681
formikValue . aboveBelow = 'above' ;
685
682
break ;
686
683
case ThresholdType . EXPECTED_OVER_ACTUAL_RATIO :
687
- // *100 to convert to percentage
688
- formikValue . relativeThreshold = ( condition . value ?? 1 ) * 100 ;
684
+ formikValue . relativeThreshold = ( condition . value ?? 1 ) * 100 ; // Convert to percentage
689
685
formikValue . aboveBelow = 'below' ;
690
686
break ;
691
687
case ThresholdType . ACTUAL_IS_BELOW_EXPECTED :
@@ -701,21 +697,17 @@ export const rulesToFormik = (rules?: Rule[]): (RuleFormikValues[] | null)[] =>
701
697
default :
702
698
break ;
703
699
}
704
- } ) ;
705
700
706
- // Add the rule to the grouped object based on featureName
707
- if ( ! groupedRules [ formikValue . featureName ] ) {
708
- groupedRules [ formikValue . featureName ] = [ ] ;
709
- }
710
- groupedRules [ formikValue . featureName ] . push ( formikValue ) ;
701
+ if ( ! groupedRules [ formikValue . featureName ] ) {
702
+ groupedRules [ formikValue . featureName ] = [ ] ;
703
+ }
704
+ groupedRules [ formikValue . featureName ] . push ( formikValue ) ;
705
+ } ) ;
711
706
} ) ;
712
707
713
- // Convert grouped object into an array of arrays based on featureList index
714
- const featureList = Object . keys ( groupedRules ) ; // Ensure you have a reference to your feature list somewhere
715
-
708
+ const featureList = Object . keys ( groupedRules ) ;
716
709
const finalRules : ( RuleFormikValues [ ] | null ) [ ] = featureList . map (
717
710
( featureName ) => groupedRules [ featureName ] || null
718
711
) ;
719
-
720
712
return finalRules ;
721
713
} ;
0 commit comments