diff --git a/src/core_plugins/kibana/public/visualize/editor/editor.html b/src/core_plugins/kibana/public/visualize/editor/editor.html index c73805e4eb678..06c058d37da5a 100644 --- a/src/core_plugins/kibana/public/visualize/editor/editor.html +++ b/src/core_plugins/kibana/public/visualize/editor/editor.html @@ -73,6 +73,7 @@ saved-obj="savedVis" ui-state="uiState" time-range="timeRange" + filters="globalFilters" class="visEditor__content" /> diff --git a/src/core_plugins/kibana/public/visualize/editor/editor.js b/src/core_plugins/kibana/public/visualize/editor/editor.js index 5e4ec07ff5e83..fa0a679c459d5 100644 --- a/src/core_plugins/kibana/public/visualize/editor/editor.js +++ b/src/core_plugins/kibana/public/visualize/editor/editor.js @@ -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 = { @@ -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(); }; diff --git a/src/core_plugins/kibana/public/visualize/editor/visualization_editor.js b/src/core_plugins/kibana/public/visualize/editor/visualization_editor.js index 1f8426386613c..a2ed44df2f5b0 100644 --- a/src/core_plugins/kibana/public/visualize/editor/visualization_editor.js +++ b/src/core_plugins/kibana/public/visualize/editor/visualization_editor.js @@ -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'; @@ -31,7 +32,8 @@ uiModules scope: { savedObj: '=', uiState: '=?', - timeRange: '=' + timeRange: '=', + filters: '=', }, link: function ($scope, element) { const editorType = $scope.savedObj.vis.type.editor; @@ -43,6 +45,7 @@ uiModules editor.render({ uiState: $scope.uiState, timeRange: $scope.timeRange, + filters: $scope.filters, appState: getAppState(), }); }; @@ -56,8 +59,9 @@ uiModules editor.destroy(); }); - $scope.$watch('timeRange', $scope.renderFunction); - + $scope.$watchGroup(['timeRange', 'filters'], debounce(() => { + $scope.renderFunction(); + }, 100)); } }; }); diff --git a/src/ui/public/vis/editors/default/default.js b/src/ui/public/vis/editors/default/default.js index e1802960eb2a0..b21dd52bc7bfe 100644 --- a/src/ui/public/vis/editors/default/default.js +++ b/src/ui/public/vis/editors/default/default.js @@ -53,7 +53,7 @@ const defaultEditor = function ($rootScope, $compile, i18n) { } } - render({ uiState, timeRange, appState }) { + render({ uiState, timeRange, filters, appState }) { let $scope; const updateScope = () => { @@ -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, }); }