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

No reload on changes to disabled filters in dashboard #41144

Merged
merged 11 commits into from
Jul 29, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/legacy/core_plugins/kibana/public/visualize/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ uiModules
};
});

function getEnabledFilters(filters) {
return filters ? filters.filter(filter => !filter.meta.disabled) : undefined;
}

function VisEditor(
$scope,
$element,
Expand Down Expand Up @@ -305,7 +309,7 @@ function VisEditor(
return appState;
}());

$scope.filters = queryFilter.getFilters();
$scope.filters = getEnabledFilters(queryFilter.getFilters());

$scope.onFiltersUpdated = filters => {
// The filters will automatically be set when the queryFilter emits an update event (see below)
Expand Down Expand Up @@ -418,8 +422,11 @@ function VisEditor(
// update the searchSource when filters update
const filterUpdateSubscription = subscribeWithScope($scope, queryFilter.getUpdates$(), {
next: () => {
$scope.filters = queryFilter.getFilters();
$scope.fetch();
const oldFilters = $scope.filters;
$scope.filters = getEnabledFilters(queryFilter.getFilters());
if (!_.isEqual(oldFilters, $scope.filters)) {
$scope.fetch();
}
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ export interface VisualizeOutput extends EmbeddableOutput {
savedObjectId: string;
}

function getEnabledFilters(filters?: Filter[]) {
return filters ? filters.filter(filter => !filter.meta.disabled) : undefined;
}

export class VisualizeEmbeddable extends Embeddable<VisualizeInput, VisualizeOutput> {
private savedVisualization: VisSavedObject;
private loader: VisualizeLoader;
Expand Down Expand Up @@ -112,7 +116,6 @@ export class VisualizeEmbeddable extends Embeddable<VisualizeInput, VisualizeOut
this.uiState.on('change', this.uiStateChangeHandler);

this.subscription = Rx.merge(this.getOutput$(), this.getInput$()).subscribe(() => {
this.reload();
this.handleChanges();
});
}
Expand Down Expand Up @@ -157,19 +160,20 @@ export class VisualizeEmbeddable extends Embeddable<VisualizeInput, VisualizeOut
const updatedParams: VisualizeUpdateParams = {};

// Check if timerange has changed
if (this.input.timeRange !== this.timeRange) {
if (!_.isEqual(this.input.timeRange, this.timeRange)) {
this.timeRange = _.cloneDeep(this.input.timeRange);
updatedParams.timeRange = this.timeRange;
}

// Check if filters has changed
if (this.input.filters !== this.filters) {
updatedParams.filters = this.input.filters;
this.filters = this.input.filters;
const enabledFilters = getEnabledFilters(this.input.filters);
if (!_.isEqual(enabledFilters, this.filters)) {
updatedParams.filters = enabledFilters;
this.filters = enabledFilters;
}

// Check if query has changed
if (this.input.query !== this.query) {
if (!_.isEqual(this.input.query, this.query)) {
updatedParams.query = this.input.query;
this.query = this.input.query;
}
Expand All @@ -183,6 +187,7 @@ export class VisualizeEmbeddable extends Embeddable<VisualizeInput, VisualizeOut

if (this.handler && !_.isEmpty(updatedParams)) {
this.handler.update(updatedParams);
this.handler.reload();
}
}

Expand All @@ -194,7 +199,7 @@ export class VisualizeEmbeddable extends Embeddable<VisualizeInput, VisualizeOut
public render(domNode: HTMLElement) {
this.timeRange = _.cloneDeep(this.input.timeRange);
this.query = this.input.query;
this.filters = this.input.filters;
this.filters = getEnabledFilters(this.input.filters);

this.transferCustomizationsToUiState();

Expand All @@ -211,8 +216,8 @@ export class VisualizeEmbeddable extends Embeddable<VisualizeInput, VisualizeOut
// Append visualization to container instead of replacing its content
append: true,
timeRange: _.cloneDeep(this.input.timeRange),
query: this.input.query,
filters: this.input.filters,
query: this.query,
filters: this.filters,
cssClass: `panel-content panel-content--fullWidth`,
dataAttrs,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class MapEmbeddable extends Embeddable {
onContainerStateChanged(containerState) {
if (!_.isEqual(containerState.timeRange, this._prevTimeRange) ||
!_.isEqual(containerState.query, this._prevQuery) ||
!_.isEqual(containerState.filters, this._prevFilters)) {
!_.isEqual(containerState.filters.filter(filter => !filter.meta.disabled), this._prevFilters)) {
this._dispatchSetQuery(containerState);
}

Expand All @@ -74,9 +74,9 @@ export class MapEmbeddable extends Embeddable {
_dispatchSetQuery({ query, timeRange, filters }) {
this._prevTimeRange = timeRange;
this._prevQuery = query;
this._prevFilters = filters;
this._prevFilters = filters.filter(filter => !filter.meta.disabled);
this._store.dispatch(setQuery({
filters: filters.filter(filter => !filter.meta.disabled),
filters: this._prevFilters,
query,
timeFilters: timeRange,
}));
Expand Down