Skip to content

Commit

Permalink
Update existing filters when negated via a visualization (elastic#10850)
Browse files Browse the repository at this point in the history
Backports PR elastic#10778

**Commit 1:**
Handle single filter scenario

* Original sha: ccd24cb
* Authored by Matthew Bargar <[email protected]> on 2017-03-16T21:03:42Z

**Commit 2:**
Handle the multi filter scenario

* Original sha: c90535d
* Authored by Matthew Bargar <[email protected]> on 2017-03-16T21:26:28Z
  • Loading branch information
elastic-jasper authored and Bargs committed Mar 22, 2017
1 parent b9dd016 commit ce7908c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
23 changes: 20 additions & 3 deletions src/ui/public/filter_bar/filter_bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import FilterBarLibExtractTimeFilterProvider from 'ui/filter_bar/lib/extract_tim
import FilterBarLibFilterOutTimeBasedFilterProvider from 'ui/filter_bar/lib/filter_out_time_based_filter';
import FilterBarLibChangeTimeFilterProvider from 'ui/filter_bar/lib/change_time_filter';
import FilterBarQueryFilterProvider from 'ui/filter_bar/query_filter';
import compareFilters from './lib/compare_filters';
import uiModules from 'ui/modules';
const module = uiModules.get('kibana');

Expand Down Expand Up @@ -52,8 +53,7 @@ module.directive('filterBar', function (Private, Promise, getAppState) {
};

$scope.applyFilters = function (filters) {
// add new filters
$scope.addFilters(filterAppliedAndUnwrap(filters));
addAndInvertFilters(filterAppliedAndUnwrap(filters));
$scope.newFilters = [];

// change time filter
Expand Down Expand Up @@ -128,10 +128,27 @@ module.directive('filterBar', function (Private, Promise, getAppState) {
return filters;
})
.then(filterOutTimeBasedFilter)
.then($scope.addFilters);
.then(addAndInvertFilters);
}
});

function addAndInvertFilters(filters) {
const existingFilters = queryFilter.getFilters();
const inversionFilters = _.filter(existingFilters, (existingFilter) => {
const newMatchingFilter = _.find(filters, _.partial(compareFilters, existingFilter));
return newMatchingFilter
&& newMatchingFilter.meta
&& existingFilter.meta
&& existingFilter.meta.negate !== newMatchingFilter.meta.negate;
});
const newFilters = _.reject(filters, (filter) => {
return _.find(inversionFilters, _.partial(compareFilters, filter));
});

_.forEach(inversionFilters, $scope.invertFilter);
$scope.addFilters(newFilters);
}

function convertToEditableFilter(filter) {
return _.omit(_.cloneDeep(filter), function (val, key) {
return key.match(privateFilterFieldRegex);
Expand Down
2 changes: 1 addition & 1 deletion src/ui/public/filter_bar/filter_bar_click_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default function (Notifier) {
});
}

filters = dedupFilters($state.filters, uniqFilters(filters));
filters = dedupFilters($state.filters, uniqFilters(filters), { negate: true });
// We need to add a bunch of filter deduping here.
if (!simulate) {
$state.$newFilters = filters;
Expand Down

0 comments on commit ce7908c

Please sign in to comment.