mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
Refactor nested ternary logic into useMemo fns
It would be painful to try to write a pure function that captures this same logic (see the deps lists), but as a compromise we can at least encapsulate these in functions and use more expressive implementation.
This commit is contained in:
parent
3df635ef4a
commit
a5fcf4d0cc
1 changed files with 23 additions and 10 deletions
|
@ -483,17 +483,30 @@ const StepDefineRuleComponent: FC<StepDefineRuleProps> = ({
|
|||
isEsqlSuppressionLoading ||
|
||||
(isMlRule(ruleType) && (noMlJobsStarted || mlFieldsLoading || !mlSuppressionFields.length));
|
||||
|
||||
const suppressionGroupByDisabledText = areSuppressionFieldsDisabledBySequence
|
||||
? i18n.EQL_SEQUENCE_SUPPRESSION_DISABLE_TOOLTIP
|
||||
: isMlRule(ruleType) && noMlJobsStarted
|
||||
? i18n.MACHINE_LEARNING_SUPPRESSION_DISABLED_LABEL
|
||||
: alertSuppressionUpsellingMessage;
|
||||
const suppressionGroupByDisabledText = useMemo(() => {
|
||||
if (areSuppressionFieldsDisabledBySequence) {
|
||||
return i18n.EQL_SEQUENCE_SUPPRESSION_DISABLE_TOOLTIP;
|
||||
} else if (isMlRule(ruleType) && noMlJobsStarted) {
|
||||
return i18n.MACHINE_LEARNING_SUPPRESSION_DISABLED_LABEL;
|
||||
} else {
|
||||
return alertSuppressionUpsellingMessage;
|
||||
}
|
||||
}, [
|
||||
alertSuppressionUpsellingMessage,
|
||||
areSuppressionFieldsDisabledBySequence,
|
||||
noMlJobsStarted,
|
||||
ruleType,
|
||||
]);
|
||||
|
||||
const suppressionGroupByFields = isEsqlRule(ruleType)
|
||||
? esqlSuppressionFields
|
||||
: isMlRule(ruleType)
|
||||
? mlSuppressionFields
|
||||
: termsAggregationFields;
|
||||
const suppressionGroupByFields = useMemo(() => {
|
||||
if (isEsqlRule(ruleType)) {
|
||||
return esqlSuppressionFields;
|
||||
} else if (isMlRule(ruleType)) {
|
||||
return mlSuppressionFields;
|
||||
} else {
|
||||
return termsAggregationFields;
|
||||
}
|
||||
}, [esqlSuppressionFields, mlSuppressionFields, ruleType, termsAggregationFields]);
|
||||
|
||||
/**
|
||||
* Component that allows selection of suppression intervals disabled:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue