Fix filtering out global time range (#19221)

* Fix filtering out global time range

* Check if timefilter actually was created
This commit is contained in:
Tim Roes 2018-05-20 10:09:40 +02:00 committed by GitHub
parent adcecc08b6
commit 27efde6b6d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 24 deletions

View file

@ -7,7 +7,15 @@ export function RootSearchSourceProvider(Private, $rootScope, timefilter) {
globalSource.inherits(false); // this is the final source, it has no parents
globalSource.filter(function (globalSource) {
// dynamic time filter will be called in the _flatten phase of things
return timefilter.get(globalSource.get('index'));
const filter = timefilter.get(globalSource.get('index'));
// Attach a meta property to it, that we check inside visualizations
// to remove that timefilter again because we use our explicitly passed in one.
// This should be removed as soon as we got rid of inheritance in SearchSource
// across the boundary or visualization.
if (filter) {
filter.meta = { _globalTimefilter: true };
}
return filter;
});
let appSource; // set in setAppSource()

View file

@ -9,32 +9,13 @@ const CourierRequestHandlerProvider = function (Private, courier, timefilter) {
/**
* TODO: This code can be removed as soon as we got rid of inheritance in the
* searchsource and pass down every filter explicitly.
* we're only adding one range filter against the timeFieldName to ensure
* that our filter is the only one applied and override the global filters.
* this does rely on the "implementation detail" that filters are added first
* on the leaf SearchSource and subsequently on the parents.
* We are filtering out the global timefilter by the meta key set by the root
* search source on that filter.
*/
function removeSearchSourceParentTimefilter(searchSource) {
searchSource.addFilterPredicate((filter, state) => {
if (!filter.range) {
return true;
}
const index = searchSource.index() || searchSource.getParent().index();
const timeFieldName = index && index.timeFieldName;
if (!index || !timeFieldName) {
return true;
}
// Only check if we need to filter out this filter if it's actual a range filter
// on our time field and not any other field.
if (!filter.range[timeFieldName]) {
return true;
}
return !(state.filters || []).find(f => f.range && f.range[timeFieldName]);
searchSource.addFilterPredicate((filter) => {
return !_.get(filter, 'meta._globalTimefilter', false);
});
}
return {