From f9ca6dca65b2566aa3d0af8b56991019e18f6394 Mon Sep 17 00:00:00 2001 From: igoristic Date: Mon, 29 Mar 2021 12:21:15 -0400 Subject: [PATCH] [Monitoring] Removed timefilter refresh override (#94648) * Removed refresh override * Changed default behavior Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- x-pack/plugins/monitoring/public/plugin.ts | 28 ++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/monitoring/public/plugin.ts b/x-pack/plugins/monitoring/public/plugin.ts index b950b064774b..a597754d6c40 100644 --- a/x-pack/plugins/monitoring/public/plugin.ts +++ b/x-pack/plugins/monitoring/public/plugin.ts @@ -27,7 +27,6 @@ import { ALERT_THREAD_POOL_WRITE_REJECTIONS, ALERT_DETAILS, } from '../common/constants'; - import { createCpuUsageAlertType } from './alerts/cpu_usage_alert'; import { createMissingMonitoringDataAlertType } from './alerts/missing_monitoring_data_alert'; import { createLegacyAlertTypes } from './alerts/legacy_alert'; @@ -44,6 +43,8 @@ interface MonitoringSetupPluginDependencies { usageCollection: UsageCollectionSetup; } +const HASH_CHANGE = 'hashchange'; + export class MonitoringPlugin implements Plugin { @@ -106,7 +107,6 @@ export class MonitoringPlugin usageCollection: plugins.usageCollection, }; - this.setInitialTimefilter(deps); const monitoringApp = new AngularApp(deps); const removeHistoryListener = params.history.listen((location) => { if (location.pathname === '' && location.hash === '') { @@ -114,7 +114,11 @@ export class MonitoringPlugin } }); + const removeHashChange = this.setInitialTimefilter(deps); return () => { + if (removeHashChange) { + removeHashChange(); + } removeHistoryListener(); monitoringApp.destroy(); }; @@ -131,8 +135,24 @@ export class MonitoringPlugin private setInitialTimefilter({ data }: MonitoringStartPluginDependencies) { const { timefilter } = data.query.timefilter; - const refreshInterval = { value: 10000, pause: false }; - timefilter.setRefreshInterval(refreshInterval); + const { pause: pauseByDefault } = timefilter.getRefreshIntervalDefaults(); + if (pauseByDefault) { + return; + } + /** + * We can't use timefilter.getRefreshIntervalUpdate$ last value, + * since it's not a BehaviorSubject. This means we need to wait for + * hash change because of angular's applyAsync + */ + const onHashChange = () => { + const { value, pause } = timefilter.getRefreshInterval(); + if (!value && pause) { + window.removeEventListener(HASH_CHANGE, onHashChange); + timefilter.setRefreshInterval({ value: 10000, pause: false }); + } + }; + window.addEventListener(HASH_CHANGE, onHashChange, false); + return () => window.removeEventListener(HASH_CHANGE, onHashChange); } private getExternalConfig() {