Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visualize: Reload on ui state change and fix ui state for tsvb #63699

Merged
merged 9 commits into from
May 5, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,9 @@ function VisualizeAppController($scope, $route, $injector, $timeout, kbnUrlState
stateContainer
);
vis.uiState = persistedState;
vis.uiState.on('reload', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is making sure the reload is picked up when visualize embeddable is used in visualize editor

embeddableHandler.reload();
});
$scope.uiState = persistedState;
$scope.savedVis = savedVis;
$scope.query = initialState.query;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ export class VisEditor extends Component {

handleUiState = (field, value) => {
this.props.vis.uiState.set(field, value);
// reload visualization because data might need to be re-fetched
this.props.vis.uiState.emit('reload');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is re-running the expression when ui state changes in TSVB

};

updateVisState = debounce(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export interface VisualizeInput extends EmbeddableInput {
vis?: {
colors?: { [key: string]: string };
};
table?: unknown;
}

export interface VisualizeOutput extends EmbeddableOutput {
Expand All @@ -76,7 +77,7 @@ export class VisualizeEmbeddable extends Embeddable<VisualizeInput, VisualizeOut
private query?: Query;
private title?: string;
private filters?: Filter[];
private visCustomizations: VisualizeInput['vis'];
private visCustomizations?: Pick<VisualizeInput, 'vis' | 'table'>;
private subscriptions: Subscription[] = [];
private expression: string = '';
private vis: Vis;
Expand Down Expand Up @@ -105,6 +106,7 @@ export class VisualizeEmbeddable extends Embeddable<VisualizeInput, VisualizeOut
this.timefilter = timefilter;
this.vis = vis;
this.vis.uiState.on('change', this.uiStateChangeHandler);
this.vis.uiState.on('reload', this.reload);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is making sure the reload is picked up when visualize embeddable is used on the dashboard


this.autoRefreshFetchSubscription = timefilter
.getAutoRefreshFetch$()
Expand Down Expand Up @@ -141,17 +143,22 @@ export class VisualizeEmbeddable extends Embeddable<VisualizeInput, VisualizeOut
// Check for changes that need to be forwarded to the uiState
// Since the vis has an own listener on the uiState we don't need to
// pass anything from here to the handler.update method
const visCustomizations = this.input.vis;
if (visCustomizations) {
const visCustomizations = { vis: this.input.vis, table: this.input.table };
if (visCustomizations.vis || visCustomizations.table) {
if (!_.isEqual(visCustomizations, this.visCustomizations)) {
this.visCustomizations = visCustomizations;
// Turn this off or the uiStateChangeHandler will fire for every modification.
this.vis.uiState.off('change', this.uiStateChangeHandler);
this.vis.uiState.clearAllKeys();
this.vis.uiState.set('vis', visCustomizations);
getKeys(visCustomizations).forEach(key => {
this.vis.uiState.set(key, visCustomizations[key]);
});
if (visCustomizations.vis) {
this.vis.uiState.set('vis', visCustomizations.vis);
getKeys(visCustomizations).forEach(key => {
this.vis.uiState.set(key, visCustomizations[key]);
});
}
if (visCustomizations.table) {
this.vis.uiState.set('table', visCustomizations.table);
}
this.vis.uiState.on('change', this.uiStateChangeHandler);
}
} else if (this.parent) {
Expand Down