diff --git a/src/ui/public/filter_bar/__tests__/push_filter.js b/src/ui/public/filter_bar/__tests__/push_filter.js index 8ed95cdbe3c2a..542eec1a19fec 100644 --- a/src/ui/public/filter_bar/__tests__/push_filter.js +++ b/src/ui/public/filter_bar/__tests__/push_filter.js @@ -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); + }); diff --git a/src/ui/public/filter_bar/push_filter.js b/src/ui/public/filter_bar/push_filter.js index fa750e2a01c56..80fb5ad52eb95 100644 --- a/src/ui/public/filter_bar/push_filter.js +++ b/src/ui/public/filter_bar/push_filter.js @@ -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; }; }; diff --git a/src/ui/public/vislib_vis_type/vislib_renderbot.js b/src/ui/public/vislib_vis_type/vislib_renderbot.js index 956a61a7047ef..161127bb8f1ec 100644 --- a/src/ui/public/vislib_vis_type/vislib_renderbot.js +++ b/src/ui/public/vislib_vis_type/vislib_renderbot.js @@ -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); };