Skip to content

Commit

Permalink
[Custom threshold] Fix bug with deleting conditions (#172187)
Browse files Browse the repository at this point in the history
Fixes #171623

## Summary

This PR fixes custom threshold updates by making sure that aggregation
and equation will re-render if the expression changes. The chart and
threshold updates were correct during deletion.
  • Loading branch information
maryam-saeidi authored Dec 11, 2023
1 parent cb41301 commit 75b52e8
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
EuiExpression,
EuiPopover,
} from '@elastic/eui';
import React, { useState, useCallback, useMemo } from 'react';
import React, { useState, useCallback, useMemo, useEffect } from 'react';
import { range, first, xor, debounce } from 'lodash';
import { IErrorObject } from '@kbn/triggers-actions-ui-plugin/public';
import { FormattedMessage } from '@kbn/i18n-react';
Expand Down Expand Up @@ -64,9 +64,14 @@ export function CustomEquationEditor({
expression?.metrics ?? [NEW_METRIC]
);
const [customEqPopoverOpen, setCustomEqPopoverOpen] = useState(false);
const [equation, setEquation] = useState<string | undefined>(expression?.equation || undefined);
const [equation, setEquation] = useState<string | undefined>(expression?.equation);
const debouncedOnChange = useMemo(() => debounce(onChange, 500), [onChange]);

useEffect(() => {
setCustomMetrics(expression?.metrics ?? [NEW_METRIC]);
setEquation(expression?.equation);
}, [expression?.metrics, expression?.equation]);

const handleAddNewRow = useCallback(() => {
setCustomMetrics((previous) => {
const currentVars = previous?.map((m) => m.name) ?? [];
Expand Down

0 comments on commit 75b52e8

Please sign in to comment.