Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Map bounding box controls #6863

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/ui/public/filter_bar/__tests__/push_filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,19 @@ describe('Filter Bar pushFilter()', function () {
expect($state.filters[0].meta.negate).to.be(true);
expect($state.filters[0].meta.index).to.be('myIndex');

pushFilter(filter, false, 'myIndex');
expect($state.filters[1].meta.negate).to.be(false);
});



it('should modify the existing filters of the same type instead of making another one', function () {
pushFilter(filter, false, 'myIndex');
expect($state.filters[0].meta).to.be.an(Object);
const sameTypeFilter = {query: { query_string: 'rada'}};
const diffTypeFilter = {foo: { bar: 'foo'}};
pushFilter(diffTypeFilter, false, 'myIndex');
expect($state.filters.length).to.be(2);
pushFilter(sameTypeFilter, false, 'myIndex');
expect($state.filters.length).to.be(2);
expect($state.filters[0].query).to.equal(sameTypeFilter.query);
});
});

});
25 changes: 21 additions & 4 deletions src/ui/public/filter_bar/push_filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,27 @@ export default function () {
// Hierarchical and tabular data set their aggConfigResult parameter
// differently because of how the point is rewritten between the two. So
// we need to check if the point.orig is set, if not use try the point.aggConfigResult
let filters = _.clone($state.filters || []);
let pendingFilter = { meta: { negate: negate, index: index }};
_.extend(pendingFilter, filter);
filters.push(pendingFilter);
const filters = _.clone($state.filters || []);
const pendingFilter = { meta: { negate: negate, index: index }};
_.assign(pendingFilter, filter);
const filterKey = _.keys(filter)[0];
let filterAdded = false;

filters.forEach(function (filt) {
const isDisabled = filt.meta && filt.meta.disabled;
const isSameFilterType = filt.hasOwnProperty(filterKey);
const isSameIndex = filt.meta && (filt.meta.index === index);
if (!isDisabled && isSameFilterType && isSameIndex) {
_.assign(pendingFilter.meta, filt.meta); // be sure to keep any meta data
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately I don't think you can keep all of the meta key as it links to the index pattern, you'll end up with filters referencing the wrong pattern. You can keep all the rest, but you need to replace the index pattern with the right one

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, so should I check and make sure they're the same index pattern?I figured if checking to make sure they're the same doesn't matter, neither does overwriting it.

Also, what do I do in the ui to make it change?

_.assign(filt, pendingFilter);
filterAdded = true;
}
});

if (!filterAdded) {
filters.push(pendingFilter);
}

$state.filters = filters;
};
};
Expand Down