mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
migrate terms include/exclude to new format (#10193)
* fixing test migrate terms import/export to new format * fixing based on review
This commit is contained in:
parent
c247124148
commit
77778eb10e
2 changed files with 78 additions and 6 deletions
|
@ -7,7 +7,7 @@ describe('Terms Agg', function () {
|
|||
|
||||
let $rootScope;
|
||||
|
||||
function init({ responseValueAggs = [] }) {
|
||||
function init({ responseValueAggs = [], aggParams = {} }) {
|
||||
ngMock.module('kibana');
|
||||
ngMock.inject(function (Private, $controller, _$rootScope_) {
|
||||
const terms = Private(AggTypesIndexProvider).byName.terms;
|
||||
|
@ -16,7 +16,7 @@ describe('Terms Agg', function () {
|
|||
$rootScope = _$rootScope_;
|
||||
$rootScope.agg = {
|
||||
id: 'test',
|
||||
params: {},
|
||||
params: aggParams,
|
||||
type: terms,
|
||||
vis: {
|
||||
aggs: []
|
||||
|
@ -152,5 +152,60 @@ describe('Terms Agg', function () {
|
|||
it('displays a metric editor if "custom metric" is selected');
|
||||
it('saves the "custom metric" to state and refreshes from it');
|
||||
it('invalidates the form if the metric agg form is not complete');
|
||||
|
||||
describe('convert import/export from old format', function () {
|
||||
|
||||
it('it doesnt do anything with string type', function () {
|
||||
init({
|
||||
aggParams: {
|
||||
include: '404',
|
||||
exclude: '400',
|
||||
}
|
||||
});
|
||||
|
||||
const aggConfig = $rootScope.agg;
|
||||
const includeArg = $rootScope.agg.type.params.byName.include;
|
||||
const excludeArg = $rootScope.agg.type.params.byName.exclude;
|
||||
|
||||
expect(includeArg.serialize(aggConfig.params.include)).to.equal('404');
|
||||
expect(excludeArg.serialize(aggConfig.params.exclude)).to.equal('400');
|
||||
|
||||
const output = { params: {} };
|
||||
|
||||
includeArg.write(aggConfig, output);
|
||||
excludeArg.write(aggConfig, output);
|
||||
|
||||
expect(output.params.include).to.equal('404');
|
||||
expect(output.params.exclude).to.equal('400');
|
||||
});
|
||||
|
||||
it('converts object to string type', function () {
|
||||
init({
|
||||
aggParams: {
|
||||
include: {
|
||||
pattern: '404'
|
||||
}, exclude: {
|
||||
pattern: '400'
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
const aggConfig = $rootScope.agg;
|
||||
const includeArg = $rootScope.agg.type.params.byName.include;
|
||||
const excludeArg = $rootScope.agg.type.params.byName.exclude;
|
||||
|
||||
expect(includeArg.serialize(aggConfig.params.include)).to.equal('404');
|
||||
expect(excludeArg.serialize(aggConfig.params.exclude)).to.equal('400');
|
||||
|
||||
const output = { params: {} };
|
||||
|
||||
includeArg.write(aggConfig, output);
|
||||
excludeArg.write(aggConfig, output);
|
||||
|
||||
expect(output.params.include).to.equal('404');
|
||||
expect(output.params.exclude).to.equal('400');
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -33,6 +33,21 @@ export default function TermsAggDefinition(Private) {
|
|||
};
|
||||
}
|
||||
|
||||
const migrateIncludeExcludeFormat = {
|
||||
serialize: function (value) {
|
||||
if (!value || _.isString(value)) return value;
|
||||
else return value.pattern;
|
||||
},
|
||||
write: function (aggConfig, output) {
|
||||
const value = aggConfig.params[this.name];
|
||||
if (_.isObject(value)) {
|
||||
output.params[this.name] = value.pattern;
|
||||
} else if (value) {
|
||||
output.params[this.name] = value;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return new BucketAggType({
|
||||
name: 'terms',
|
||||
title: 'Terms',
|
||||
|
@ -48,15 +63,17 @@ export default function TermsAggDefinition(Private) {
|
|||
},
|
||||
{
|
||||
name: 'exclude',
|
||||
type: 'regex',
|
||||
type: 'string',
|
||||
advanced: true,
|
||||
disabled: isNotType('string')
|
||||
disabled: isNotType('string'),
|
||||
...migrateIncludeExcludeFormat
|
||||
},
|
||||
{
|
||||
name: 'include',
|
||||
type: 'regex',
|
||||
type: 'string',
|
||||
advanced: true,
|
||||
disabled: isNotType('string')
|
||||
disabled: isNotType('string'),
|
||||
...migrateIncludeExcludeFormat
|
||||
},
|
||||
{
|
||||
name: 'size',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue