From 38c5cde8003d7272b1e401515cf8abdca932c99e Mon Sep 17 00:00:00 2001 From: Marta Bondyra Date: Fri, 18 Dec 2020 17:19:10 +0100 Subject: [PATCH] [Lens] fix transition date_histogram/last_value -> top values/last_value (#86429) (#86457) --- .../operations/definitions/terms/index.tsx | 3 +- .../definitions/terms/terms.test.tsx | 33 ++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/terms/index.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/terms/index.tsx index 1e2d800cb3e8..5d96efa8f68c 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/terms/index.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/terms/index.tsx @@ -90,7 +90,8 @@ export const termsOperation: OperationDefinition column && !column.isBucketed && !isReferenced(layer, columnId) + ([columnId, column]) => + column && !isReferenced(layer, columnId) && isSortableByColumn(column) ) .map(([id]) => id)[0]; diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/terms/terms.test.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/terms/terms.test.tsx index dfca730c004d..fc8f8534bcfb 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/terms/terms.test.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/terms/terms.test.tsx @@ -305,7 +305,7 @@ describe('terms', () => { expect(termsColumn.params.otherBucket).toEqual(false); }); - it('should use existing metric column as order column', () => { + it('should use existing sortable metric column as order column', () => { const termsColumn = termsOperation.buildColumn({ indexPattern: createMockedIndexPattern(), layer: { @@ -335,6 +335,37 @@ describe('terms', () => { }) ); }); + it('should set alphabetical order type if metric column is of type last value', () => { + const termsColumn = termsOperation.buildColumn({ + indexPattern: createMockedIndexPattern(), + layer: { + columns: { + col1: { + label: 'Last value of a', + dataType: 'number', + isBucketed: false, + sourceField: 'a', + operationType: 'last_value', + params: { + sortField: 'datefield', + }, + }, + }, + columnOrder: [], + indexPatternId: '', + }, + field: { + aggregatable: true, + searchable: true, + type: 'boolean', + name: 'test', + displayName: 'test', + }, + }); + expect(termsColumn.params).toEqual( + expect.objectContaining({ orderBy: { type: 'alphabetical' } }) + ); + }); it('should use the default size when there is an existing bucket', () => { const termsColumn = termsOperation.buildColumn({