Skip to content

Commit

Permalink
Don't trigger autorefresh when autofetch false (#30405) (#30424)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeelmers authored Feb 8, 2019
1 parent 0b1edae commit e34b0fb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/ui/public/visualize/loader/embedded_visualize_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export class EmbeddedVisualizeHandler {
timeRange,
filters,
query,
autoFetch,
autoFetch = true,
Private,
} = params;

Expand All @@ -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);
Expand All @@ -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) {
Expand All @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions src/ui/public/visualize/loader/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down

0 comments on commit e34b0fb

Please sign in to comment.