From 930c60a64de7b029f00df9dd535eedf84906df8c Mon Sep 17 00:00:00 2001 From: Tim Roes Date: Thu, 7 Feb 2019 20:25:25 +0100 Subject: [PATCH] Don't trigger autorefresh when autofetch false (#30405) --- .../visualize/loader/embedded_visualize_handler.ts | 13 ++++++++----- src/ui/public/visualize/loader/types.ts | 6 ++++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/ui/public/visualize/loader/embedded_visualize_handler.ts b/src/ui/public/visualize/loader/embedded_visualize_handler.ts index 7d69db737c4e..9dd91bba80c4 100644 --- a/src/ui/public/visualize/loader/embedded_visualize_handler.ts +++ b/src/ui/public/visualize/loader/embedded_visualize_handler.ts @@ -112,7 +112,7 @@ export class EmbeddedVisualizeHandler { timeRange, filters, query, - autoFetch, + autoFetch = true, Private, } = params; @@ -127,8 +127,6 @@ export class EmbeddedVisualizeHandler { forceFetch: false, }; - this.autoFetch = !(autoFetch === false); - // Listen to the first RENDER_COMPLETE_EVENT to resolve this promise this.firstRenderComplete = new Promise(resolve => { this.listeners.once(RENDER_COMPLETE_EVENT, resolve); @@ -138,6 +136,7 @@ export class EmbeddedVisualizeHandler { element.setAttribute(RENDERING_COUNT_ATTRIBUTE, '0'); element.addEventListener('renderComplete', this.onRenderCompleteListener); + this.autoFetch = autoFetch; this.appState = appState; this.vis = vis; if (uiState) { @@ -154,7 +153,9 @@ export class EmbeddedVisualizeHandler { this.vis.on('update', this.handleVisUpdate); this.vis.on('reload', this.reload); this.uiState.on('change', this.onUiStateChange); - timefilter.on('autoRefreshFetch', this.reload); + if (autoFetch) { + timefilter.on('autoRefreshFetch', this.reload); + } this.dataLoader = EmbeddedVisualizeHandler.__ENABLE_PIPELINE_DATA_LOADER__ ? new PipelineDataLoader(vis) @@ -236,7 +237,9 @@ export class EmbeddedVisualizeHandler { public destroy(): void { this.destroyed = true; this.debouncedFetchAndRender.cancel(); - timefilter.off('autoRefreshFetch', this.reload); + if (this.autoFetch) { + timefilter.off('autoRefreshFetch', this.reload); + } this.vis.removeListener('reload', this.reload); this.vis.removeListener('update', this.handleVisUpdate); this.element.removeEventListener('renderComplete', this.onRenderCompleteListener); diff --git a/src/ui/public/visualize/loader/types.ts b/src/ui/public/visualize/loader/types.ts index 3c37fac30b8d..ac7fd14de9ab 100644 --- a/src/ui/public/visualize/loader/types.ts +++ b/src/ui/public/visualize/loader/types.ts @@ -115,6 +115,12 @@ export interface VisualizeLoaderParams { * global AppState. */ appState?: AppState; + /** + * Whether or not the visualization should fetch its data automatically. If this is + * set to `false` the loader won't trigger a fetch on embedding or when an auto refresh + * cycle happens. Default value: `true` + */ + autoFetch?: boolean; } /**