Skip to content

Commit

Permalink
pass global filters from editor (#26009) (#26064)
Browse files Browse the repository at this point in the history
  • Loading branch information
ppisljar authored Nov 22, 2018
1 parent 1d662e5 commit 0bdafcf
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
saved-obj="savedVis"
ui-state="uiState"
time-range="timeRange"
filters="globalFilters"
class="visEditor__content"
/>

Expand Down
15 changes: 1 addition & 14 deletions src/core_plugins/kibana/public/visualize/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,6 @@ function VisEditor(
// SearchSource is a promise-based stream of search results that can inherit from other search sources.
const { vis, searchSource } = savedVis;

// adds top level search source to the stack to which global filters are applied
const getTopLevelSearchSource = (searchSource) => {
if (searchSource.getParent()) return getTopLevelSearchSource(searchSource.getParent());
return searchSource;
};

const topLevelSearchSource = getTopLevelSearchSource(searchSource);
const globalFiltersSearchSource = searchSource.create();
globalFiltersSearchSource.setField('index', searchSource.getField('index'));
topLevelSearchSource.setParent(globalFiltersSearchSource);


$scope.vis = vis;

const $appStatus = this.appStatus = {
Expand Down Expand Up @@ -338,10 +326,9 @@ function VisEditor(
// update the searchSource when query updates
$scope.fetch = function () {
$state.save();
const globalFilters = queryFilter.getGlobalFilters();
savedVis.searchSource.setField('query', $state.query);
savedVis.searchSource.setField('filter', $state.filters);
globalFiltersSearchSource.setField('filter', globalFilters);
$scope.globalFilters = queryFilter.getGlobalFilters();
$scope.vis.forceReload();
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/

import { debounce } from 'lodash';
import { uiModules } from 'ui/modules';
import 'angular-sanitize';
import { VisEditorTypesRegistryProvider } from 'ui/registry/vis_editor_types';
Expand All @@ -31,7 +32,8 @@ uiModules
scope: {
savedObj: '=',
uiState: '=?',
timeRange: '='
timeRange: '=',
filters: '=',
},
link: function ($scope, element) {
const editorType = $scope.savedObj.vis.type.editor;
Expand All @@ -43,6 +45,7 @@ uiModules
editor.render({
uiState: $scope.uiState,
timeRange: $scope.timeRange,
filters: $scope.filters,
appState: getAppState(),
});
};
Expand All @@ -56,8 +59,9 @@ uiModules
editor.destroy();
});

$scope.$watch('timeRange', $scope.renderFunction);

$scope.$watchGroup(['timeRange', 'filters'], debounce(() => {
$scope.renderFunction();
}, 100));
}
};
});
6 changes: 4 additions & 2 deletions src/ui/public/vis/editors/default/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const defaultEditor = function ($rootScope, $compile, i18n) {
}
}

render({ uiState, timeRange, appState }) {
render({ uiState, timeRange, filters, appState }) {
let $scope;

const updateScope = () => {
Expand Down Expand Up @@ -166,12 +166,14 @@ const defaultEditor = function ($rootScope, $compile, i18n) {
uiState: uiState,
listenOnChange: false,
timeRange: timeRange,
filters: filters,
appState: appState,
});
});
} else {
this._handler.update({
timeRange: timeRange
timeRange: timeRange,
filters: filters,
});
}

Expand Down

0 comments on commit 0bdafcf

Please sign in to comment.