mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
parent
1dae5950af
commit
a9083312a8
7 changed files with 45 additions and 16 deletions
|
@ -86,7 +86,7 @@ describe('Terms Agg', function () {
|
|||
expect($rootScope.agg.params.orderBy).to.be('agg5');
|
||||
});
|
||||
|
||||
it('defaults to the _term metric if no agg is compatible', function () {
|
||||
it('defaults to the _key metric if no agg is compatible', function () {
|
||||
init({
|
||||
responseValueAggs: [
|
||||
{
|
||||
|
@ -97,15 +97,15 @@ describe('Terms Agg', function () {
|
|||
}
|
||||
]
|
||||
});
|
||||
expect($rootScope.agg.params.orderBy).to.be('_term');
|
||||
expect($rootScope.agg.params.orderBy).to.be('_key');
|
||||
});
|
||||
|
||||
it('selects _term if there are no metric aggs', function () {
|
||||
it('selects _key if there are no metric aggs', function () {
|
||||
init({});
|
||||
expect($rootScope.agg.params.orderBy).to.be('_term');
|
||||
expect($rootScope.agg.params.orderBy).to.be('_key');
|
||||
});
|
||||
|
||||
it('selects _term if the selected metric becomes incompatible', function () {
|
||||
it('selects _key if the selected metric becomes incompatible', function () {
|
||||
init({
|
||||
responseValueAggs: [
|
||||
{
|
||||
|
@ -126,7 +126,7 @@ describe('Terms Agg', function () {
|
|||
}
|
||||
];
|
||||
$rootScope.$digest();
|
||||
expect($rootScope.agg.params.orderBy).to.be('_term');
|
||||
expect($rootScope.agg.params.orderBy).to.be('_key');
|
||||
});
|
||||
|
||||
it('selects first metric if it is avg', function () {
|
||||
|
@ -144,7 +144,7 @@ describe('Terms Agg', function () {
|
|||
expect($rootScope.agg.params.orderBy).to.be('agg1');
|
||||
});
|
||||
|
||||
it('selects _term if the first metric is avg_bucket', function () {
|
||||
it('selects _key if the first metric is avg_bucket', function () {
|
||||
$rootScope.responseValueAggs = [
|
||||
{
|
||||
id: 'agg1',
|
||||
|
@ -155,10 +155,10 @@ describe('Terms Agg', function () {
|
|||
}
|
||||
];
|
||||
$rootScope.$digest();
|
||||
expect($rootScope.agg.params.orderBy).to.be('_term');
|
||||
expect($rootScope.agg.params.orderBy).to.be('_key');
|
||||
});
|
||||
|
||||
it('selects _term if the selected metric is removed', function () {
|
||||
it('selects _key if the selected metric is removed', function () {
|
||||
init({
|
||||
responseValueAggs: [
|
||||
{
|
||||
|
@ -172,7 +172,7 @@ describe('Terms Agg', function () {
|
|||
expect($rootScope.agg.params.orderBy).to.be('agg1');
|
||||
$rootScope.responseValueAggs = [];
|
||||
$rootScope.$digest();
|
||||
expect($rootScope.agg.params.orderBy).to.be('_term');
|
||||
expect($rootScope.agg.params.orderBy).to.be('_key');
|
||||
});
|
||||
|
||||
it('adds "custom metric" option');
|
||||
|
|
|
@ -132,7 +132,7 @@ export const termsBucketAgg = new BucketAggType({
|
|||
if (!orderBy && prevOrderBy === INIT) {
|
||||
let respAgg = _($scope.responseValueAggs).filter((agg) => !$scope.rejectAgg(agg)).first();
|
||||
if (!respAgg) {
|
||||
respAgg = { id: '_term' };
|
||||
respAgg = { id: '_key' };
|
||||
}
|
||||
params.orderBy = respAgg.id;
|
||||
return;
|
||||
|
@ -147,7 +147,7 @@ export const termsBucketAgg = new BucketAggType({
|
|||
// ensure that orderBy is set to a valid agg
|
||||
const respAgg = _($scope.responseValueAggs).filter((agg) => !$scope.rejectAgg(agg)).find({ id: orderBy });
|
||||
if (!respAgg) {
|
||||
params.orderBy = '_term';
|
||||
params.orderBy = '_key';
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
<option value="custom" ng-selected="agg.params.orderBy === 'custom'">
|
||||
Custom Metric
|
||||
</option>
|
||||
<option value="_term" ng-selected="agg.params.orderBy === '_term'">
|
||||
Term
|
||||
<option value="_key" ng-selected="agg.params.orderBy === '_key'">
|
||||
Alphabetical
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
|
|
|
@ -51,4 +51,16 @@ describe('updateOldState', () => {
|
|||
|
||||
});
|
||||
|
||||
describe('terms agg conversion', () => {
|
||||
it('should update _term to _key', () => {
|
||||
const oldState = {
|
||||
aggs: [
|
||||
{ type: 'terms', params: { orderBy: '_term' } }
|
||||
]
|
||||
};
|
||||
const state = updateOldState(oldState);
|
||||
expect(state.aggs[0].params.orderBy).to.be('_key');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -15,6 +15,21 @@ function convertHeatmapLabelColor(visState) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update old terms aggregation format to new terms aggregation format. This will
|
||||
* update the following things:
|
||||
* - Rewrite orderBy: _term to orderBy: _key (new API in Elasticsearch)
|
||||
*/
|
||||
function convertTermAggregation(visState) {
|
||||
if (visState.aggs) {
|
||||
visState.aggs.forEach(agg => {
|
||||
if (agg.type === 'terms' && agg.params && agg.params.orderBy === '_term') {
|
||||
agg.params.orderBy = '_key';
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is responsible for updating old visStates - the actual saved object
|
||||
* object - into the format, that will be required by the current Kibana version.
|
||||
|
@ -26,6 +41,8 @@ export const updateOldState = (visState) => {
|
|||
if (!visState) return visState;
|
||||
const newState = _.cloneDeep(visState);
|
||||
|
||||
convertTermAggregation(newState);
|
||||
|
||||
if (visState.type === 'gauge' && visState.fontSize) {
|
||||
delete newState.fontSize;
|
||||
_.set(newState, 'gauge.style.fontSize', visState.fontSize);
|
||||
|
|
|
@ -87,7 +87,7 @@ export default function ({ getService, getPageObjects }) {
|
|||
const expectedChartData = ['png 1,373', 'php 445', 'jpg 9,109', 'gif 918', 'css 2,159'];
|
||||
|
||||
log.debug('Order By = Term');
|
||||
return PageObjects.visualize.selectOrderBy('_term')
|
||||
return PageObjects.visualize.selectOrderBy('_key')
|
||||
.then(function clickGo() {
|
||||
return PageObjects.visualize.clickGo();
|
||||
})
|
||||
|
|
|
@ -43,7 +43,7 @@ export default function ({ getService, getPageObjects }) {
|
|||
});
|
||||
})
|
||||
.then(function () {
|
||||
return PageObjects.visualize.selectOrderBy('_term');
|
||||
return PageObjects.visualize.selectOrderBy('_key');
|
||||
})
|
||||
.then(function () {
|
||||
return PageObjects.visualize.clickGo();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue