Co-authored-by: Stratoula Kalafateli <efstratia.kalafateli@elastic.co>
This commit is contained in:
Joe Reuter 2022-11-08 10:22:08 +01:00 committed by GitHub
parent f436d936e3
commit a897698860
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View file

@ -271,7 +271,7 @@ export const termsOperation: OperationDefinition<
const orderColumn = layer.columns[column.params.orderBy.columnId];
orderBy = String(orderedColumnIds.indexOf(column.params.orderBy.columnId));
// percentile rank with non integer value should default to alphabetical order
if (!isPercentileRankSortable(orderColumn)) {
if (!orderColumn || !isPercentileRankSortable(orderColumn)) {
orderBy = '_key';
}
}

View file

@ -352,6 +352,29 @@ describe('terms', () => {
);
});
it('should default to alphabetical sort when the referenced column does not exist anymore', () => {
const termsColumn = layer.columns.col1 as TermsIndexPatternColumn;
const esAggsFn = termsOperation.toEsAggsFn(
{
...termsColumn,
params: { ...termsColumn.params, orderBy: { type: 'column', columnId: 'unknownCol' } },
},
'col1',
{} as IndexPattern,
layer,
uiSettingsMock,
['col1', 'col2']
);
expect(esAggsFn).toEqual(
expect.objectContaining({
function: 'aggTerms',
arguments: expect.objectContaining({
orderBy: ['_key'],
}),
})
);
});
it('should not enable missing bucket if other bucket is not set', () => {
const termsColumn = layer.columns.col1 as TermsIndexPatternColumn;
const esAggsFn = termsOperation.toEsAggsFn(