Merge pull request #8760 from elastic/jasper/backport/8740/5.0

[backport] PR #8740 to 5.0
This commit is contained in:
Matt Bargar 2016-10-19 16:49:00 -04:00 committed by GitHub
commit 5e1ac9d66e
3 changed files with 20 additions and 6 deletions

View file

@ -41,7 +41,7 @@ describe('AggConfig Filters', function () {
});
let aggConfig = vis.aggs.byTypeName.ip_range[0];
let filter = createFilter(aggConfig, '0.0.0.0-1.1.1.1');
let filter = createFilter(aggConfig, '0.0.0.0 to 1.1.1.1');
expect(filter).to.have.property('range');
expect(filter).to.have.property('meta');
expect(filter.meta).to.have.property('index', indexPattern.id);

View file

@ -6,10 +6,10 @@ export default function createIpRangeFilterProvider() {
if (aggConfig.params.ipRangeType === 'mask') {
range = new CidrMask(key).getRange();
} else {
let addresses = key.split(/\-/);
let [from, to] = key.split(/\s+to\s+/);
range = {
from: addresses[0],
to: addresses[1]
from: from === '-Infinity' ? -Infinity : from,
to: to === 'Infinity' ? Infinity : to
};
}

View file

@ -13,6 +13,12 @@ export default function RangeAggDefinition(Private) {
name: 'ip_range',
title: 'IPv4 Range',
createFilter: createFilter,
getKey: function (bucket, key, agg) {
if (key) return key;
const from = _.get(bucket, 'from', '-Infinity');
const to = _.get(bucket, 'to', 'Infinity');
return `${from} to ${to}`;
},
makeLabel: function (aggConfig) {
return aggConfig.params.field.displayName + ' IP ranges';
},
@ -38,8 +44,16 @@ export default function RangeAggDefinition(Private) {
},
editor: ipRangesTemplate,
write: function (aggConfig, output) {
let ipRangeType = aggConfig.params.ipRangeType;
output.params.ranges = aggConfig.params.ranges[ipRangeType];
const ipRangeType = aggConfig.params.ipRangeType;
let ranges = aggConfig.params.ranges[ipRangeType];
if (ipRangeType === 'fromTo') {
ranges = _.map(ranges, (range) => {
return _.omit(range, _.isNull);
});
}
output.params.ranges = ranges;
}
}
]