[ML] Update Anomaly Explorer and SMV on the "Refresh" button click (#48773) (#48869)

* [ML] update on Refresh button click

* [ML] reset cache on Refresh
This commit is contained in:
Dima Arnautov 2019-10-22 14:27:08 +02:00 committed by GitHub
parent a6a8911e0b
commit 495dacadc8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 2 deletions

View file

@ -13,7 +13,7 @@ import PropTypes from 'prop-types';
import React, { Fragment } from 'react';
import { FormattedMessage, injectI18n } from '@kbn/i18n/react';
import DragSelect from 'dragselect/dist/ds.min.js';
import { map } from 'rxjs/operators';
import { map, takeUntil } from 'rxjs/operators';
import { i18n } from '@kbn/i18n';
import {
@ -99,6 +99,9 @@ import { AnomaliesTable } from '../components/anomalies_table/anomalies_table';
import { timefilter } from 'ui/timefilter';
import { toastNotifications } from 'ui/notify';
import { mlTimefilterRefresh$ } from '../services/timefilter_refresh_service';
import { Subject } from 'rxjs';
function getExplorerDefaultState() {
return {
annotationsData: [],
@ -163,6 +166,8 @@ export const Explorer = injectI18n(injectObservablesAsProps(
TimeBuckets: PropTypes.func.isRequired,
};
_unsubscribeAll = new Subject();
state = getExplorerDefaultState();
// make sure dragSelect is only available if the mouse pointer is actually over a swimlane
@ -224,6 +229,24 @@ export const Explorer = injectI18n(injectObservablesAsProps(
}
});
});
mlTimefilterRefresh$.pipe(takeUntil(this._unsubscribeAll)).subscribe(() => {
this.resetCache();
this.updateExplorer();
});
}
componentWillUnmount() {
this._unsubscribeAll.next();
this._unsubscribeAll.complete();
}
resetCache() {
this.loadOverallDataPreviousArgs = null;
this.loadViewBySwimlanePreviousArgs = null;
this.topFieldsPreviousArgs = null;
this.annotationsTablePreviousArgs = null;
this.anomaliesTablePreviousArgs = null;
}
// based on the pattern described here:

View file

@ -835,7 +835,9 @@ export class TimeSeriesExplorer extends React.Component {
this.subscriptions.add(annotationsRefresh$.subscribe(this.refresh));
this.subscriptions.add(interval$.subscribe(tableControlsListener));
this.subscriptions.add(severity$.subscribe(tableControlsListener));
this.subscriptions.add(mlTimefilterRefresh$.subscribe(() => this.refresh(false)));
this.subscriptions.add(mlTimefilterRefresh$.subscribe(() => {
this.refresh(true);
}));
// Listen for changes to job selection.
this.subscriptions.add(this.jobSelectService.subscribe(({ selection: selectedJobIds }) => {