pass global filters from editor (#26009)

This commit is contained in:
Peter Pisljar 2018-11-22 04:27:13 +01:00 committed by GitHub
parent 5e247f506c
commit 854757cb6f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 19 deletions

View file

@ -73,6 +73,7 @@
saved-obj="savedVis"
ui-state="uiState"
time-range="timeRange"
filters="globalFilters"
class="visEditor__content"
/>

View file

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

View file

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

View file

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