Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ML] Add debounce to the severity control update #101581

Merged
merged 2 commits into from
Jun 9, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 ?? 0);

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}
onChange={useCallback((update) => {
explorerService.setSwimLaneSeverity(update);
setSeverityUpdate(update);
}, [])}
/>
</EuiFlexItem>
Expand Down