From f982bc97a0aa09558959ee02e83ed40948fdcc99 Mon Sep 17 00:00:00 2001 From: Lukas Olson Date: Tue, 25 Aug 2015 13:28:53 -0700 Subject: [PATCH] Fix issue with mislabeled scripted field filters from histogram --- .../buckets/create_filter/histogram.js | 3 +-- .../__tests__/buckets/create_filter/range.js | 2 +- .../buckets/create_filter/histogram.js | 10 +++++---- .../public/filter_bar/__tests__/mapScript.js | 21 +++++++++++++++++++ 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/ui/public/agg_types/__tests__/buckets/create_filter/histogram.js b/src/ui/public/agg_types/__tests__/buckets/create_filter/histogram.js index 206fe3ff19f96..076386dd4ed69 100644 --- a/src/ui/public/agg_types/__tests__/buckets/create_filter/histogram.js +++ b/src/ui/public/agg_types/__tests__/buckets/create_filter/histogram.js @@ -38,8 +38,7 @@ describe('AggConfig Filters', function () { expect(filter.range).to.have.property('bytes'); expect(filter.range.bytes).to.have.property('gte', 2048); expect(filter.range.bytes).to.have.property('lt', 3072); - + expect(filter.meta).to.have.property('formattedValue', '2,048'); }); - }); }); diff --git a/src/ui/public/agg_types/__tests__/buckets/create_filter/range.js b/src/ui/public/agg_types/__tests__/buckets/create_filter/range.js index 2a78530ac5e98..ca5b8eff5f745 100644 --- a/src/ui/public/agg_types/__tests__/buckets/create_filter/range.js +++ b/src/ui/public/agg_types/__tests__/buckets/create_filter/range.js @@ -41,7 +41,7 @@ describe('AggConfig Filters', function () { expect(filter.range).to.have.property('bytes'); expect(filter.range.bytes).to.have.property('gte', 1024.0); expect(filter.range.bytes).to.have.property('lt', 2048.0); + expect(filter.meta).to.have.property('formattedValue', '1,024 to 2,048'); }); - }); }); diff --git a/src/ui/public/agg_types/buckets/create_filter/histogram.js b/src/ui/public/agg_types/buckets/create_filter/histogram.js index 4b314b90d08ca..c84883a8fd5b4 100644 --- a/src/ui/public/agg_types/buckets/create_filter/histogram.js +++ b/src/ui/public/agg_types/buckets/create_filter/histogram.js @@ -5,10 +5,12 @@ define(function (require) { return function (aggConfig, key) { var value = parseInt(key, 10); - return buildRangeFilter(aggConfig.params.field, { - gte: value, - lt: value + aggConfig.params.interval - }, aggConfig.vis.indexPattern); + return buildRangeFilter( + aggConfig.params.field, + {gte: value, lt: value + aggConfig.params.interval}, + aggConfig.vis.indexPattern, + aggConfig.fieldFormatter()(key) + ); }; }; }); diff --git a/src/ui/public/filter_bar/__tests__/mapScript.js b/src/ui/public/filter_bar/__tests__/mapScript.js index a5c4646c3804b..2c2876aa03883 100644 --- a/src/ui/public/filter_bar/__tests__/mapScript.js +++ b/src/ui/public/filter_bar/__tests__/mapScript.js @@ -42,5 +42,26 @@ describe('Filter Bar Directive', function () { $rootScope.$apply(); }); + it('should return a value for a range/histogram filter from a scripted field', (done) => { + let filter = { + meta: { + index: 'logstash-*', + formattedValue: '1,000.00 to 2,000.00', + field: 'script number' + }, + script: { + params: { + gte: 1000, + lt: 2000, + value: '>=1,000.00 <2,000.00' + } + } + }; + mapScript(filter).then((result) => { + expect(result).to.have.property('value', filter.meta.formattedValue); + done(); + }); + $rootScope.$apply(); + }); }); });