Skip to content

Commit

Permalink
[PushFilters] simplified the push filters function, also added tests for
Browse files Browse the repository at this point in the history
the new features
  • Loading branch information
panda01 committed Apr 13, 2016
1 parent 6b6d15f commit 4217434
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
12 changes: 11 additions & 1 deletion src/ui/public/filter_bar/__tests__/push_filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,18 @@ describe('Filter Bar pushFilter()', function () {
expect($state.filters[0].meta.negate).to.be(true);
expect($state.filters[0].meta.index).to.be('myIndex');

});
it('should modify the existing filters of the same type instead of making another one', function () {
pushFilter(filter, false, 'myIndex');
expect($state.filters[1].meta.negate).to.be(false);
expect($state.filters[0].meta).to.be.an(Object);
const sameTypeFilter = {query: { quiery_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);

});


Expand Down
24 changes: 14 additions & 10 deletions src/ui/public/filter_bar/push_filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,23 @@ 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
var filters = _.clone($state.filters || []);
var pendingFilter = { meta: { negate: negate, index: index }};
const filters = _.clone($state.filters || []);
const pendingFilter = { meta: { negate: negate, index: index }};
_.extend(pendingFilter, filter);
if (!filters.length) {
const filterKey = _.keys(filter)[0];
let filterAdded = false;

filters.forEach(function (filt) {
if (filt.hasOwnProperty(filterKey)) {
_.assign(filt, pendingFilter);
filterAdded = true;
}
});

if (!filterAdded) {
filters.push(pendingFilter);
} else {
const filterKey = _.keys(filter)[0];
filters.forEach(function (filt) {
if (filt.hasOwnProperty(filterKey)) {
_.assign(filt, pendingFilter);
}
});
}

$state.filters = filters;
};
};
Expand Down
1 change: 1 addition & 0 deletions src/ui/public/vislib_vis_type/vislib_renderbot.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ module.exports = function VislibRenderbotFactory(Private) {
VislibRenderbot.prototype.buildChartData = buildChartData;
VislibRenderbot.prototype.render = function (esResponse) {
this.chartData = this.buildChartData(esResponse);
this.chartData.title = this.vis.title || '';
this.vislibVis.render(this.chartData, this.uiState);
};

Expand Down

0 comments on commit 4217434

Please sign in to comment.