Skip to content

Commit

Permalink
fix bug (#144716)
Browse files Browse the repository at this point in the history
Co-authored-by: Stratoula Kalafateli <[email protected]>
  • Loading branch information
flash1293 and stratoula authored Nov 8, 2022
1 parent f436d93 commit a897698
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit a897698

Please sign in to comment.