Don't trigger autorefresh when autofetch false (#30405) (#30424)

This commit is contained in:
Luke Elmers 2019-02-07 19:18:56 -07:00 committed by GitHub
parent 0b1edae636
commit e34b0fbb39
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 5 deletions

View file

@ -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);

View file

@ -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;
}
/**