Skip to content

Commit

Permalink
[ML] Add debounce to the severity control update (#101581)
Browse files Browse the repository at this point in the history
  • Loading branch information
darnautov authored Jun 9, 2021
1 parent 58eb0d4 commit 97b952b
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions x-pack/plugins/ml/public/application/explorer/anomaly_timeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@
import React, { FC, useCallback, useMemo, useState } from 'react';
import { isEqual } from 'lodash';
import {
EuiPanel,
EuiPopover,
EuiContextMenuPanel,
EuiButtonEmpty,
EuiButtonIcon,
EuiContextMenuItem,
EuiContextMenuPanel,
EuiFlexGroup,
EuiFlexItem,
EuiPanel,
EuiPopover,
EuiSelect,
EuiTitle,
EuiSpacer,
EuiContextMenuItem,
EuiButtonEmpty,
EuiTitle,
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import useDebounce from 'react-use/lib/useDebounce';
import { OVERALL_LABEL, SWIMLANE_TYPE, VIEW_BY_JOB_LABEL } from './explorer_constants';
import { AddSwimlaneToDashboardControl } from './dashboard_controls/add_swimlane_to_dashboard_controls';
import { useMlKibana } from '../contexts/kibana';
Expand Down Expand Up @@ -93,6 +94,18 @@ export const AnomalyTimeline: FC<AnomalyTimelineProps> = React.memo(
viewBySwimlaneData,
} = explorerState;

const [severityUpdate, setSeverityUpdate] = useState(swimLaneSeverity);

useDebounce(
() => {
if (severityUpdate === swimLaneSeverity) return;

explorerService.setSwimLaneSeverity(severityUpdate!);
},
500,
[severityUpdate, swimLaneSeverity]
);

const annotations = useMemo(() => overallAnnotations.annotationsData, [overallAnnotations]);

const menuItems = useMemo(() => {
Expand Down Expand Up @@ -194,9 +207,9 @@ export const AnomalyTimeline: FC<AnomalyTimelineProps> = React.memo(

<EuiFlexItem grow={true}>
<SeverityControl
value={swimLaneSeverity ?? 0}
value={severityUpdate ?? 0}
onChange={useCallback((update) => {
explorerService.setSwimLaneSeverity(update);
setSeverityUpdate(update);
}, [])}
/>
</EuiFlexItem>
Expand Down

0 comments on commit 97b952b

Please sign in to comment.