Fix migrate significant terms include exclude format (#34392)
* Fix migrate significant terms include/exclude * update ref to expect, update test initialization * created function to encapsulate duplicated code * commented seemingly extraneous code in test * Removed extraneous initialization code from sig terms test, updated migrate_include_exclude_format.js to use named import from lodash, added localized displayName to sig terms
This commit is contained in:
parent
cca14121cc
commit
2361d5e8b3
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import ngMock from 'ng_mock';
|
||||
import { aggTypes } from '../..';
|
||||
|
||||
describe('Significant Terms Agg', function () {
|
||||
|
||||
describe('order agg editor UI', function () {
|
||||
|
||||
describe('convert include/exclude from old format', function () {
|
||||
|
||||
let $rootScope;
|
||||
|
||||
function init({ aggParams = {} }) {
|
||||
ngMock.module('kibana');
|
||||
ngMock.inject(function (_$rootScope_) {
|
||||
const significantTerms = aggTypes.byName.significant_terms;
|
||||
|
||||
$rootScope = _$rootScope_;
|
||||
$rootScope.agg = {
|
||||
id: 'test',
|
||||
params: aggParams,
|
||||
type: significantTerms
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function testSerializeAndWrite(aggConfig) {
|
||||
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('it doesnt do anything with string type', function () {
|
||||
init({
|
||||
aggParams: {
|
||||
include: '404',
|
||||
exclude: '400',
|
||||
}
|
||||
});
|
||||
|
||||
testSerializeAndWrite($rootScope.agg);
|
||||
});
|
||||
|
||||
it('converts object to string type', function () {
|
||||
init({
|
||||
aggParams: {
|
||||
include: {
|
||||
pattern: '404'
|
||||
}, exclude: {
|
||||
pattern: '400'
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
testSerializeAndWrite($rootScope.agg);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -231,7 +231,7 @@ describe('Terms Agg', function () {
|
|||
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 () {
|
||||
describe('convert include/exclude from old format', function () {
|
||||
|
||||
it('it doesnt do anything with string type', function () {
|
||||
init({
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import { isString, isObject } from 'lodash';
|
||||
|
||||
function isNotType(type) {
|
||||
return function (agg) {
|
||||
const field = agg.params.field;
|
||||
return !field || field.type !== type;
|
||||
};
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export {
|
||||
isNotType,
|
||||
migrateIncludeExcludeFormat
|
||||
};
|
|
@ -21,6 +21,7 @@ import { BucketAggType } from './_bucket_agg_type';
|
|||
import { createFilterTerms } from './create_filter/terms';
|
||||
import orderAndSizeTemplate from '../controls/order_and_size.html';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import { isNotType, migrateIncludeExcludeFormat } from './migrate_include_exclude_format';
|
||||
|
||||
export const significantTermsBucketAgg = new BucketAggType({
|
||||
name: 'significant_terms',
|
||||
|
@ -50,13 +51,23 @@ export const significantTermsBucketAgg = new BucketAggType({
|
|||
},
|
||||
{
|
||||
name: 'exclude',
|
||||
type: 'regex',
|
||||
advanced: true
|
||||
displayName: i18n.translate('common.ui.aggTypes.buckets.significantTerms.excludeLabel', {
|
||||
defaultMessage: 'Exclude'
|
||||
}),
|
||||
type: 'string',
|
||||
advanced: true,
|
||||
disabled: isNotType('string'),
|
||||
...migrateIncludeExcludeFormat
|
||||
},
|
||||
{
|
||||
name: 'include',
|
||||
type: 'regex',
|
||||
advanced: true
|
||||
displayName: i18n.translate('common.ui.aggTypes.buckets.significantTerms.includeLabel', {
|
||||
defaultMessage: 'Include'
|
||||
}),
|
||||
type: 'string',
|
||||
advanced: true,
|
||||
disabled: isNotType('string'),
|
||||
...migrateIncludeExcludeFormat
|
||||
}
|
||||
]
|
||||
});
|
||||
|
|
|
@ -30,6 +30,7 @@ import { i18n } from '@kbn/i18n';
|
|||
|
||||
import { getRequestInspectorStats, getResponseInspectorStats } from '../../courier/utils/courier_inspector_utils';
|
||||
import { buildOtherBucketAgg, mergeOtherBucketAggResponse, updateMissingBucket } from './_terms_other_bucket_helper';
|
||||
import { isNotType, migrateIncludeExcludeFormat } from './migrate_include_exclude_format';
|
||||
|
||||
const aggFilter = [
|
||||
'!top_hits', '!percentiles', '!median', '!std_dev',
|
||||
|
@ -48,28 +49,6 @@ const orderAggSchema = (new Schemas([
|
|||
}
|
||||
])).all[0];
|
||||
|
||||
function isNotType(type) {
|
||||
return function (agg) {
|
||||
const field = agg.params.field;
|
||||
return !field || field.type !== type;
|
||||
};
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const termsBucketAgg = new BucketAggType({
|
||||
name: 'terms',
|
||||
title: i18n.translate('common.ui.aggTypes.buckets.termsTitle', {
|
||||
|
|
Loading…
Reference in a new issue