From d71093dd06ac4abe5be91d6bb8abe0ce974525a9 Mon Sep 17 00:00:00 2001 From: Joe Reuter Date: Thu, 27 Jan 2022 10:00:32 +0100 Subject: [PATCH 1/3] fix records field name and migrate --- x-pack/plugins/lens/common/constants.ts | 3 + .../indexpattern_datasource/document_field.ts | 5 +- .../make_lens_embeddable_factory.ts | 7 +- .../server/migrations/common_migrations.ts | 25 +++++- .../saved_object_migrations.test.ts | 80 ++++++++++++++++++- .../migrations/saved_object_migrations.ts | 16 ++-- 6 files changed, 121 insertions(+), 15 deletions(-) diff --git a/x-pack/plugins/lens/common/constants.ts b/x-pack/plugins/lens/common/constants.ts index edf7654deb7b7..f0db3385cefc1 100644 --- a/x-pack/plugins/lens/common/constants.ts +++ b/x-pack/plugins/lens/common/constants.ts @@ -22,6 +22,9 @@ export const layerTypes: Record = { REFERENCELINE: 'referenceLine', }; +// might collide with user-supplied field names, try to make as unique as possible +export const DOCUMENT_FIELD_NAME = '___records___'; + export function getBasePath() { return `#/`; } diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/document_field.ts b/x-pack/plugins/lens/public/indexpattern_datasource/document_field.ts index fef78b1d5c6de..1f69d1df5602a 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/document_field.ts +++ b/x-pack/plugins/lens/public/indexpattern_datasource/document_field.ts @@ -6,6 +6,7 @@ */ import { i18n } from '@kbn/i18n'; +import { DOCUMENT_FIELD_NAME } from '../../common'; import { IndexPatternField } from './types'; /** @@ -16,9 +17,7 @@ export const documentField: IndexPatternField = { displayName: i18n.translate('xpack.lens.indexPattern.records', { defaultMessage: 'Records', }), - name: i18n.translate('xpack.lens.indexPattern.records', { - defaultMessage: 'Records', - }), + name: DOCUMENT_FIELD_NAME, type: 'document', aggregatable: true, searchable: true, diff --git a/x-pack/plugins/lens/server/embeddable/make_lens_embeddable_factory.ts b/x-pack/plugins/lens/server/embeddable/make_lens_embeddable_factory.ts index f516a99b078f2..332f20a00f66d 100644 --- a/x-pack/plugins/lens/server/embeddable/make_lens_embeddable_factory.ts +++ b/x-pack/plugins/lens/server/embeddable/make_lens_embeddable_factory.ts @@ -17,6 +17,7 @@ import { commonRemoveTimezoneDateHistogramParam, commonRenameFilterReferences, commonRenameOperationsForFormula, + commonRenameRecordsField, commonUpdateVisLayerType, getLensFilterMigrations, } from '../migrations/common_migrations'; @@ -68,8 +69,10 @@ export const makeLensEmbeddableFactory = } as unknown as SerializableRecord; }, '8.1.0': (state) => { - const lensState = state as unknown as { attributes: LensDocShape715 }; - const migratedLensState = commonRenameFilterReferences(lensState.attributes); + const lensState = state as unknown as { attributes: LensDocShape715 }; + const migratedLensState = commonRenameRecordsField( + commonRenameFilterReferences(lensState.attributes) + ); return { ...lensState, attributes: migratedLensState, diff --git a/x-pack/plugins/lens/server/migrations/common_migrations.ts b/x-pack/plugins/lens/server/migrations/common_migrations.ts index 82cde025e31ed..5f3ea4d57fa2c 100644 --- a/x-pack/plugins/lens/server/migrations/common_migrations.ts +++ b/x-pack/plugins/lens/server/migrations/common_migrations.ts @@ -22,8 +22,9 @@ import { VisStatePost715, VisStatePre715, VisState716, + LensDocShape810, } from './types'; -import { CustomPaletteParams, layerTypes } from '../../common'; +import { CustomPaletteParams, DOCUMENT_FIELD_NAME, layerTypes } from '../../common'; import { LensDocShape } from './saved_object_migrations'; export const commonRenameOperationsForFormula = ( @@ -162,13 +163,31 @@ export const commonMakeReversePaletteAsCustom = ( return newAttributes; }; -export const commonRenameFilterReferences = (attributes: LensDocShape715) => { +export const commonRenameRecordsField = (attributes: LensDocShape810) => { + const newAttributes = cloneDeep(attributes); + Object.keys(newAttributes.state?.datasourceStates?.indexpattern?.layers || {}).forEach( + (layerId) => { + newAttributes.state.datasourceStates.indexpattern.layers[layerId].columnOrder.forEach( + (columnId) => { + const column = + newAttributes.state.datasourceStates.indexpattern.layers[layerId].columns[columnId]; + if (column && column.operationType === 'count') { + column.sourceField = DOCUMENT_FIELD_NAME; + } + } + ); + } + ); + return newAttributes; +}; + +export const commonRenameFilterReferences = (attributes: LensDocShape715): LensDocShape810 => { const newAttributes = cloneDeep(attributes); for (const filter of newAttributes.state.filters) { filter.meta.index = filter.meta.indexRefName; delete filter.meta.indexRefName; } - return newAttributes; + return newAttributes as LensDocShape810; }; const getApplyFilterMigrationToLens = (filterMigration: MigrateFunction) => { diff --git a/x-pack/plugins/lens/server/migrations/saved_object_migrations.test.ts b/x-pack/plugins/lens/server/migrations/saved_object_migrations.test.ts index 9a6407ae30552..a78cfa5e72237 100644 --- a/x-pack/plugins/lens/server/migrations/saved_object_migrations.test.ts +++ b/x-pack/plugins/lens/server/migrations/saved_object_migrations.test.ts @@ -12,7 +12,13 @@ import { SavedObjectMigrationFn, SavedObjectUnsanitizedDoc, } from 'src/core/server'; -import { LensDocShape715, VisState716, VisStatePost715, VisStatePre715 } from './types'; +import { + LensDocShape715, + LensDocShape810, + VisState716, + VisStatePost715, + VisStatePre715, +} from './types'; import { CustomPaletteParams, layerTypes } from '../../common'; import { PaletteOutput } from 'src/plugins/charts/common'; import { Filter } from '@kbn/es-query'; @@ -1513,6 +1519,78 @@ describe('Lens migrations', () => { }); }); + describe('8.1.0 rename records field', () => { + const context = { log: { warning: () => {} } } as unknown as SavedObjectMigrationContext; + const example = { + type: 'lens', + id: 'mocked-saved-object-id', + attributes: { + savedObjectId: '1', + title: 'MyRenamedOps', + description: '', + visualizationType: null, + state: { + datasourceMetaData: { + filterableIndexPatterns: [], + }, + datasourceStates: { + indexpattern: { + currentIndexPatternId: 'logstash-*', + layers: { + '2': { + columns: { + '3': { + label: '@timestamp', + dataType: 'date', + operationType: 'date_histogram', + sourceField: '@timestamp', + isBucketed: true, + scale: 'interval', + params: { interval: 'auto', timeZone: 'Europe/Berlin' }, + }, + '4': { + label: 'Anzahl der Aufnahmen', + dataType: 'number', + operationType: 'count', + sourceField: 'Aufnahmen', + isBucketed: false, + scale: 'ratio', + }, + '5': { + label: 'Sum of bytes', + dataType: 'numver', + operationType: 'sum', + sourceField: 'bytes', + isBucketed: false, + scale: 'ratio', + }, + }, + columnOrder: ['3', '4', '5'], + }, + }, + }, + }, + visualization: {}, + query: { query: '', language: 'kuery' }, + filters: [], + }, + }, + } as unknown as SavedObjectUnsanitizedDoc; + + it('should change field for count operations but not for others, not changing the vis', () => { + const result = migrations['8.1.0'](example, context) as ReturnType< + SavedObjectMigrationFn + >; + + expect( + Object.values( + result.attributes.state.datasourceStates.indexpattern.layers['2'].columns + ).map((column) => column.sourceField) + ).toEqual(['@timestamp', '___records___', 'bytes']); + expect(example.attributes.state.visualization).toEqual(result.attributes.state.visualization); + }); + }); + test('should properly apply a filter migration within a lens visualization', () => { const migrationVersion = 'some-version'; diff --git a/x-pack/plugins/lens/server/migrations/saved_object_migrations.ts b/x-pack/plugins/lens/server/migrations/saved_object_migrations.ts index fc1718c1df2fa..d3efb4df44575 100644 --- a/x-pack/plugins/lens/server/migrations/saved_object_migrations.ts +++ b/x-pack/plugins/lens/server/migrations/saved_object_migrations.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { cloneDeep, mergeWith } from 'lodash'; +import { cloneDeep, flow, mergeWith } from 'lodash'; import { fromExpression, toExpression, Ast, AstFunction } from '@kbn/interpreter'; import { SavedObjectMigrationMap, @@ -27,6 +27,7 @@ import { VisStatePost715, VisStatePre715, VisState716, + LensDocShape810, } from './types'; import { commonRenameOperationsForFormula, @@ -35,6 +36,7 @@ import { commonMakeReversePaletteAsCustom, commonRenameFilterReferences, getLensFilterMigrations, + commonRenameRecordsField, } from './common_migrations'; interface LensDocShapePre710 { @@ -444,14 +446,16 @@ const moveDefaultReversedPaletteToCustom: SavedObjectMigrationFn< return { ...newDoc, attributes: commonMakeReversePaletteAsCustom(newDoc.attributes) }; }; -const renameFilterReferences: SavedObjectMigrationFn< - LensDocShape715, - LensDocShape715 -> = (doc) => { +const renameFilterReferences: SavedObjectMigrationFn = (doc) => { const newDoc = cloneDeep(doc); return { ...newDoc, attributes: commonRenameFilterReferences(newDoc.attributes) }; }; +const renameRecordsField: SavedObjectMigrationFn = (doc) => { + const newDoc = cloneDeep(doc); + return { ...newDoc, attributes: commonRenameRecordsField(newDoc.attributes) }; +}; + const lensMigrations: SavedObjectMigrationMap = { '7.7.0': removeInvalidAccessors, // The order of these migrations matter, since the timefield migration relies on the aggConfigs @@ -465,7 +469,7 @@ const lensMigrations: SavedObjectMigrationMap = { '7.14.0': removeTimezoneDateHistogramParam, '7.15.0': addLayerTypeToVisualization, '7.16.0': moveDefaultReversedPaletteToCustom, - '8.1.0': renameFilterReferences, + '8.1.0': flow(renameFilterReferences, renameRecordsField), }; export const mergeSavedObjectMigrationMaps = ( From 856b3d4cb0a316b7b25aeebc2af22a944e82d404 Mon Sep 17 00:00:00 2001 From: Joe Reuter Date: Thu, 27 Jan 2022 11:37:11 +0100 Subject: [PATCH 2/3] fix tests --- .../datapanel.test.tsx | 3 +- .../dimension_panel/dimension_panel.test.tsx | 16 +++---- .../droppable/droppable.test.ts | 20 ++++----- .../dimension_panel/field_input.test.tsx | 2 +- .../field_item.test.tsx | 3 +- .../indexpattern.test.ts | 32 +++++++------- .../indexpattern_suggestions.test.tsx | 14 +++---- .../operations/definitions.test.ts | 2 +- .../definitions/filters/filters.test.tsx | 2 +- .../formula/editor/math_completion.test.ts | 2 +- .../definitions/formula/formula.test.tsx | 2 +- .../definitions/last_value.test.tsx | 8 ++-- .../definitions/ranges/ranges.test.tsx | 2 +- .../definitions/terms/helpers.test.ts | 2 +- .../definitions/terms/terms.test.tsx | 10 ++--- .../operations/layer_helpers.test.ts | 42 +++++++++---------- .../operations/time_scale_utils.test.ts | 2 +- 17 files changed, 83 insertions(+), 81 deletions(-) diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/datapanel.test.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/datapanel.test.tsx index 27d03a1e3edc8..71cc3a5052080 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/datapanel.test.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/datapanel.test.tsx @@ -27,6 +27,7 @@ import { indexPatternFieldEditorPluginMock } from '../../../../../src/plugins/da import { getFieldByNameFactory } from './pure_helpers'; import { uiActionsPluginMock } from '../../../../../src/plugins/ui_actions/public/mocks'; import { TermsIndexPatternColumn } from './operations'; +import { DOCUMENT_FIELD_NAME } from '../../common'; const fieldsOne = [ { @@ -813,7 +814,7 @@ describe('IndexPattern Data Panel', () => { wrapper.find('[data-test-subj="typeFilter-document"]').first().simulate('click'); expect(wrapper.find(FieldItem).map((fieldItem) => fieldItem.prop('field').name)).toEqual([ - 'Records', + DOCUMENT_FIELD_NAME, ]); expect(wrapper.find(NoFieldsCallout).length).toEqual(3); }); diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/dimension_panel.test.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/dimension_panel.test.tsx index dd16b0be6ce61..fca45488fd2c2 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/dimension_panel.test.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/dimension_panel.test.tsx @@ -481,7 +481,7 @@ describe('IndexPatternDimensionEditorPanel', () => { dataType: 'number', isBucketed: false, operationType: 'count', - sourceField: 'Records', + sourceField: '___records___', }, })} /> @@ -991,7 +991,7 @@ describe('IndexPatternDimensionEditorPanel', () => { const newColumnState = setState.mock.calls[0][0](state).layers.first.columns.col2; expect(newColumnState.operationType).toEqual('count'); - expect(newColumnState.sourceField).toEqual('Records'); + expect(newColumnState.sourceField).toEqual('___records___'); }); it('should indicate document and field compatibility with selected document operation', () => { @@ -1004,7 +1004,7 @@ describe('IndexPatternDimensionEditorPanel', () => { isBucketed: false, label: '', operationType: 'count', - sourceField: 'Records', + sourceField: '___records___', }, })} columnId="col2" @@ -1090,7 +1090,7 @@ describe('IndexPatternDimensionEditorPanel', () => { isBucketed: false, label: 'Count of records', operationType: 'count', - sourceField: 'Records', + sourceField: '___records___', ...colOverrides, } as GenericIndexPatternColumn, }), @@ -1320,7 +1320,7 @@ describe('IndexPatternDimensionEditorPanel', () => { isBucketed: false, label: 'Count of records', operationType: 'count', - sourceField: 'Records', + sourceField: '___records___', ...colOverrides, } as GenericIndexPatternColumn, }), @@ -1337,7 +1337,7 @@ describe('IndexPatternDimensionEditorPanel', () => { isBucketed: false, label: 'Count of records', operationType: 'count', - sourceField: 'Records', + sourceField: '___records___', } as GenericIndexPatternColumn, }), columnId: 'col2', @@ -1524,7 +1524,7 @@ describe('IndexPatternDimensionEditorPanel', () => { isBucketed: false, label: 'Count of records', operationType: 'count', - sourceField: 'Records', + sourceField: '___records___', ...colOverrides, } as GenericIndexPatternColumn, }), @@ -1871,7 +1871,7 @@ describe('IndexPatternDimensionEditorPanel', () => { isBucketed: false, label: '', operationType: 'count', - sourceField: 'Records', + sourceField: '___records___', }, })} columnId={'col2'} diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/droppable/droppable.test.ts b/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/droppable/droppable.test.ts index fab431e886d8e..3871715cf31e5 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/droppable/droppable.test.ts +++ b/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/droppable/droppable.test.ts @@ -713,7 +713,7 @@ describe('IndexPatternDimensionEditorPanel', () => { label: 'Count of records', dataType: 'number', isBucketed: false, - sourceField: 'Records', + sourceField: '___records___', operationType: 'count', }, }, @@ -1186,7 +1186,7 @@ describe('IndexPatternDimensionEditorPanel', () => { label: 'Count of records', dataType: 'number', isBucketed: false, - sourceField: 'Records', + sourceField: '___records___', operationType: 'count', }, }, @@ -1249,7 +1249,7 @@ describe('IndexPatternDimensionEditorPanel', () => { label: 'Count of records', dataType: 'number', isBucketed: false, - sourceField: 'Records', + sourceField: '___records___', operationType: 'count', }, ref2: { @@ -1329,7 +1329,7 @@ describe('IndexPatternDimensionEditorPanel', () => { label: 'Count of records', dataType: 'number', isBucketed: false, - sourceField: 'Records', + sourceField: '___records___', operationType: 'count', }, ref2: { @@ -1415,7 +1415,7 @@ describe('IndexPatternDimensionEditorPanel', () => { label: 'Count of records', dataType: 'number', isBucketed: false, - sourceField: 'Records', + sourceField: '___records___', operationType: 'count', }, col2: { @@ -1605,7 +1605,7 @@ describe('IndexPatternDimensionEditorPanel', () => { // Private operationType: 'count', - sourceField: 'Records', + sourceField: '___records___', customLabel: true, }, }, @@ -1822,7 +1822,7 @@ describe('IndexPatternDimensionEditorPanel', () => { operationType: 'count', label: '', isBucketed: false, - sourceField: 'Records', + sourceField: '___records___', customLabel: true, }, col6: { @@ -1830,7 +1830,7 @@ describe('IndexPatternDimensionEditorPanel', () => { operationType: 'count', label: '', isBucketed: false, - sourceField: 'Records', + sourceField: '___records___', customLabel: true, }, }, @@ -1862,14 +1862,14 @@ describe('IndexPatternDimensionEditorPanel', () => { operationType: 'count', label: '', isBucketed: false, - sourceField: 'Records', + sourceField: '___records___', }), col6: expect.objectContaining({ dataType: 'number', operationType: 'count', label: '', isBucketed: false, - sourceField: 'Records', + sourceField: '___records___', }), }, }, diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/field_input.test.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/field_input.test.tsx index cf409ebfd680d..730342ae694e8 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/field_input.test.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/field_input.test.tsx @@ -98,7 +98,7 @@ function getCountOperationColumn(): GenericIndexPatternColumn { label: 'Count', dataType: 'number', isBucketed: false, - sourceField: 'Records', + sourceField: '___records___', operationType: 'count', }; } diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/field_item.test.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/field_item.test.tsx index 868c5864a6730..cb721416a1df9 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/field_item.test.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/field_item.test.tsx @@ -18,6 +18,7 @@ import { chartPluginMock } from '../../../../../src/plugins/charts/public/mocks' import { documentField } from './document_field'; import { uiActionsPluginMock } from '../../../../../src/plugins/ui_actions/public/mocks'; import { FieldFormatsStart } from '../../../../../src/plugins/field_formats/public'; +import { DOCUMENT_FIELD_NAME } from '../../common'; const chartsThemeService = chartPluginMock.createSetupContract().theme; @@ -254,7 +255,7 @@ describe('IndexPattern Field Item', () => { it('should not request field stats for document field', async () => { const wrapper = mountWithIntl(); - clickField(wrapper, 'Records'); + clickField(wrapper, DOCUMENT_FIELD_NAME); expect(core.http.post).not.toHaveBeenCalled(); expect(wrapper.find(EuiPopover).prop('isOpen')).toEqual(true); diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/indexpattern.test.ts b/x-pack/plugins/lens/public/indexpattern_datasource/indexpattern.test.ts index 4e358564c9f76..f906bc6046bc0 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/indexpattern.test.ts +++ b/x-pack/plugins/lens/public/indexpattern_datasource/indexpattern.test.ts @@ -224,7 +224,7 @@ describe('IndexPattern Data Source', () => { isBucketed: false, label: 'Foo', operationType: 'count', - sourceField: 'Records', + sourceField: '___records___', }; const map = indexPatternDatasource.uniqueLabels({ layers: { @@ -353,7 +353,7 @@ describe('IndexPattern Data Source', () => { label: 'Count of records', dataType: 'number', isBucketed: false, - sourceField: 'Records', + sourceField: '___records___', operationType: 'count', }, col2: { @@ -503,7 +503,7 @@ describe('IndexPattern Data Source', () => { label: 'Count of records', dataType: 'number', isBucketed: false, - sourceField: 'Records', + sourceField: '___records___', operationType: 'count', }, col2: { @@ -549,7 +549,7 @@ describe('IndexPattern Data Source', () => { label: 'Count of records', dataType: 'number', isBucketed: false, - sourceField: 'Records', + sourceField: '___records___', operationType: 'count', timeShift: '1d', }, @@ -586,7 +586,7 @@ describe('IndexPattern Data Source', () => { label: 'Count of records', dataType: 'number', isBucketed: false, - sourceField: 'Records', + sourceField: '___records___', operationType: 'count', timeScale: 'h', filter: { @@ -716,7 +716,7 @@ describe('IndexPattern Data Source', () => { label: 'Count of records', dataType: 'number', isBucketed: false, - sourceField: 'Records', + sourceField: '___records___', operationType: 'count', timeScale: 'h', }, @@ -809,7 +809,7 @@ describe('IndexPattern Data Source', () => { label: 'Count of records', dataType: 'number', isBucketed: false, - sourceField: 'Records', + sourceField: '___records___', operationType: 'count', timeScale: 'h', }, @@ -848,7 +848,7 @@ describe('IndexPattern Data Source', () => { label: 'Count of records', dataType: 'number', isBucketed: false, - sourceField: 'Records', + sourceField: '___records___', operationType: 'count', }, bucket1: { @@ -1025,7 +1025,7 @@ describe('IndexPattern Data Source', () => { operationType: 'count', isBucketed: false, scale: 'ratio', - sourceField: 'Records', + sourceField: '___records___', customLabel: true, }, date: { @@ -1057,7 +1057,7 @@ describe('IndexPattern Data Source', () => { operationType: 'count', isBucketed: false, scale: 'ratio', - sourceField: 'Records', + sourceField: '___records___', customLabel: true, }, math: { @@ -1589,7 +1589,7 @@ describe('IndexPattern Data Source', () => { label: 'Count of records2', dataType: 'number', isBucketed: false, - sourceField: 'Records', + sourceField: '___records___', operationType: 'count', }, }, @@ -1602,7 +1602,7 @@ describe('IndexPattern Data Source', () => { label: 'Count of records', dataType: 'number', isBucketed: false, - sourceField: 'Records', + sourceField: '___records___', operationType: 'count', }, bucket1: { @@ -1645,7 +1645,7 @@ describe('IndexPattern Data Source', () => { label: 'Count of records', dataType: 'number', isBucketed: false, - sourceField: 'Records', + sourceField: '___records___', operationType: 'count', }, }, @@ -1669,7 +1669,7 @@ describe('IndexPattern Data Source', () => { label: 'Count of records', dataType: 'number', isBucketed: false, - sourceField: 'Records', + sourceField: '___records___', operationType: 'count', }, }, @@ -1698,7 +1698,7 @@ describe('IndexPattern Data Source', () => { label: 'Count of records', dataType: 'number', isBucketed: false, - sourceField: 'Records', + sourceField: '___records___', operationType: 'count', }, }, @@ -1753,7 +1753,7 @@ describe('IndexPattern Data Source', () => { operationType: 'count', isBucketed: false, scale: 'ratio', - sourceField: 'Records', + sourceField: '___records___', }, }, columnOrder: ['fa649155-d7f5-49d9-af26-508287431244'], diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/indexpattern_suggestions.test.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/indexpattern_suggestions.test.tsx index f9f720cfa922a..ab7801d0d8760 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/indexpattern_suggestions.test.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/indexpattern_suggestions.test.tsx @@ -1063,7 +1063,7 @@ describe('IndexPattern Data Source suggestions', () => { isBucketed: false, operationType: 'count', - sourceField: 'Records', + sourceField: '___records___', }, }, }, @@ -2483,7 +2483,7 @@ describe('IndexPattern Data Source suggestions', () => { dataType: 'number', isBucketed: false, operationType: 'count', - sourceField: 'Records', + sourceField: '___records___', }, ref: { label: '', @@ -2665,7 +2665,7 @@ describe('IndexPattern Data Source suggestions', () => { dataType: 'number', isBucketed: false, operationType: 'count', - sourceField: 'Records', + sourceField: '___records___', }, ref: { label: '', @@ -2679,21 +2679,21 @@ describe('IndexPattern Data Source suggestions', () => { dataType: 'number', isBucketed: false, operationType: 'count', - sourceField: 'Records', + sourceField: '___records___', }, metric3: { label: '', dataType: 'number', isBucketed: false, operationType: 'count', - sourceField: 'Records', + sourceField: '___records___', }, metric4: { label: '', dataType: 'number', isBucketed: false, operationType: 'count', - sourceField: 'Records', + sourceField: '___records___', }, ref2: { label: '', @@ -2842,7 +2842,7 @@ describe('IndexPattern Data Source suggestions', () => { dataType: 'number', isBucketed: false, operationType: 'count', - sourceField: 'Records', + sourceField: '___records___', }, }, }, diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions.test.ts b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions.test.ts index 974e37c2aea8e..1a0da126f28e3 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions.test.ts +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions.test.ts @@ -91,7 +91,7 @@ const baseColumnArgs: { // Private operationType: 'count', - sourceField: 'Records', + sourceField: '___records___', }, indexPattern, layer: { diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/filters/filters.test.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/filters/filters.test.tsx index 8d0a07cffd2e1..5a3700c165d20 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/filters/filters.test.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/filters/filters.test.tsx @@ -79,7 +79,7 @@ describe('filters', () => { label: 'Count', dataType: 'number', isBucketed: false, - sourceField: 'Records', + sourceField: '___records___', operationType: 'count', }, }, diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/formula/editor/math_completion.test.ts b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/formula/editor/math_completion.test.ts index 9b7f34b583631..612ae892146fc 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/formula/editor/math_completion.test.ts +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/formula/editor/math_completion.test.ts @@ -58,7 +58,7 @@ const operationDefinitionMap: Record = { input: 'field', buildColumn: buildGenericColumn('count'), getPossibleOperationForField: (field: IndexPatternField) => - field.name === 'Records' ? numericOperation() : null, + field.name === '___records___' ? numericOperation() : null, } as unknown as GenericOperationDefinition, last_value: { type: 'last_value', diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/formula/formula.test.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/formula/formula.test.tsx index d1561e93aa807..a0e5fca114c37 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/formula/formula.test.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/formula/formula.test.tsx @@ -265,7 +265,7 @@ describe('formula', () => { previousColumn: { ...layer.columns.col1, operationType: 'count', - sourceField: 'Records', + sourceField: '___records___', filter: { language: 'lucene', query: `*`, diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/last_value.test.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/last_value.test.tsx index 26074b47e0f48..652c644d653fb 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/last_value.test.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/last_value.test.tsx @@ -242,7 +242,7 @@ describe('last_value', () => { label: 'Count', dataType: 'number', isBucketed: false, - sourceField: 'Records', + sourceField: '___records___', operationType: 'count', }, }, @@ -296,7 +296,7 @@ describe('last_value', () => { label: 'Count', dataType: 'number', isBucketed: false, - sourceField: 'Records', + sourceField: '___records___', operationType: 'count', }, }, @@ -359,7 +359,7 @@ describe('last_value', () => { label: 'Count', dataType: 'number', isBucketed: false, - sourceField: 'Records', + sourceField: '___records___', operationType: 'count', }, }, @@ -378,7 +378,7 @@ describe('last_value', () => { label: 'Count', dataType: 'number', isBucketed: false, - sourceField: 'Records', + sourceField: '___records___', operationType: 'count', params: { format: { diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/ranges.test.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/ranges.test.tsx index 9b1fde8561363..79103841ef4ba 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/ranges.test.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/ranges.test.tsx @@ -159,7 +159,7 @@ describe('ranges', () => { label: 'Count', dataType: 'number', isBucketed: false, - sourceField: 'Records', + sourceField: '___records___', operationType: 'count', }, }, diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/terms/helpers.test.ts b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/terms/helpers.test.ts index 4468953a26d17..628a5d6a7740a 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/terms/helpers.test.ts +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/terms/helpers.test.ts @@ -86,7 +86,7 @@ function getCountOperationColumn( label: 'Count', dataType: 'number', isBucketed: false, - sourceField: 'Records', + sourceField: '___records___', operationType: 'count', ...params, }; 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 bc1106ad3debf..fb3943289437d 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 @@ -82,7 +82,7 @@ describe('terms', () => { label: 'Count of records', dataType: 'number', isBucketed: false, - sourceField: 'Records', + sourceField: '___records___', operationType: 'count', }, }, @@ -434,7 +434,7 @@ describe('terms', () => { label: 'Count', dataType: 'number', isBucketed: false, - sourceField: 'Records', + sourceField: '___records___', operationType: 'count', }, }, @@ -544,7 +544,7 @@ describe('terms', () => { label: 'Count', dataType: 'number', isBucketed: false, - sourceField: 'Records', + sourceField: '___records___', operationType: 'count', }, }, @@ -630,7 +630,7 @@ describe('terms', () => { dataType: 'number', isBucketed: false, operationType: 'count', - sourceField: 'Records', + sourceField: '___records___', }, }, columnOrder: [], @@ -779,7 +779,7 @@ describe('terms', () => { label: 'Count', dataType: 'number', isBucketed: false, - sourceField: 'Records', + sourceField: '___records___', operationType: 'count', }, }, diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/layer_helpers.test.ts b/x-pack/plugins/lens/public/indexpattern_datasource/operations/layer_helpers.test.ts index 9066641b522d9..dad1250b39e14 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/layer_helpers.test.ts +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/layer_helpers.test.ts @@ -378,7 +378,7 @@ describe('state_helpers', () => { // Private operationType: 'count', - sourceField: 'Records', + sourceField: '___records___', }, }, }; @@ -414,7 +414,7 @@ describe('state_helpers', () => { // Private operationType: 'count', - sourceField: 'Records', + sourceField: '___records___', }, }, }; @@ -575,7 +575,7 @@ describe('state_helpers', () => { // Private operationType: 'count', - sourceField: 'Records', + sourceField: '___records___', }, }, }, @@ -1292,7 +1292,7 @@ describe('state_helpers', () => { label: 'Count', dataType: 'number', isBucketed: false, - sourceField: 'Records', + sourceField: '___records___', operationType: 'count', }, }, @@ -1351,7 +1351,7 @@ describe('state_helpers', () => { label: 'Count of records', dataType: 'number', isBucketed: false, - sourceField: 'Records', + sourceField: '___records___', operationType: 'count', }, }, @@ -1376,7 +1376,7 @@ describe('state_helpers', () => { id1: expect.objectContaining({ dataType: 'number', isBucketed: false, - sourceField: 'Records', + sourceField: '___records___', operationType: 'count', }), willBeReference: expect.objectContaining({ @@ -1435,7 +1435,7 @@ describe('state_helpers', () => { customLabel: true, dataType: 'number' as const, isBucketed: false, - sourceField: 'Records', + sourceField: '___records___', operationType: 'count' as const, }; @@ -1472,7 +1472,7 @@ describe('state_helpers', () => { customLabel: true, dataType: 'number' as const, isBucketed: false, - sourceField: 'Records', + sourceField: '___records___', operationType: 'count' as const, }; @@ -1607,7 +1607,7 @@ describe('state_helpers', () => { label: 'Count', dataType: 'number' as const, isBucketed: false, - sourceField: 'Records', + sourceField: '___records___', operationType: 'count' as const, }, }, @@ -1647,7 +1647,7 @@ describe('state_helpers', () => { label: 'Count', dataType: 'number' as const, isBucketed: false, - sourceField: 'Records', + sourceField: '___records___', operationType: 'count' as const, }, }, @@ -1720,7 +1720,7 @@ describe('state_helpers', () => { isBucketed: false, operationType: 'count' as const, - sourceField: 'Records', + sourceField: '___records___', }, invalid: { label: 'Test reference', @@ -1772,7 +1772,7 @@ describe('state_helpers', () => { isBucketed: false, operationType: 'count' as const, - sourceField: 'Records', + sourceField: '___records___', }, invalid: { label: 'Test reference', @@ -1990,7 +1990,7 @@ describe('state_helpers', () => { isBucketed: false, operationType: 'count' as const, - sourceField: 'Records', + sourceField: '___records___', filter: { language: 'kuery', query: 'bytes > 4000' }, timeShift: '3h', }; @@ -2168,7 +2168,7 @@ describe('state_helpers', () => { columnOrder: ['col1', 'col2'], columns: { col1: expect.objectContaining({ - sourceField: 'Records', + sourceField: '___records___', operationType: 'count', }), col2: expect.objectContaining({ references: ['col1'] }), @@ -2228,7 +2228,7 @@ describe('state_helpers', () => { label: 'Count of records', dataType: 'number', isBucketed: false, - sourceField: 'Records', + sourceField: '___records___', operationType: 'count', }, }, @@ -2282,7 +2282,7 @@ describe('state_helpers', () => { label: 'Count', dataType: 'number', isBucketed: false, - sourceField: 'Records', + sourceField: '___records___', operationType: 'count', }, }, @@ -2309,7 +2309,7 @@ describe('state_helpers', () => { isBucketed: false, operationType: 'count', - sourceField: 'Records', + sourceField: '___records___', }, col2: { label: 'Test reference', @@ -2337,7 +2337,7 @@ describe('state_helpers', () => { isBucketed: false, operationType: 'count', - sourceField: 'Records', + sourceField: '___records___', }, col2: { label: 'Changed label', @@ -2382,7 +2382,7 @@ describe('state_helpers', () => { isBucketed: false, operationType: 'count', - sourceField: 'Records', + sourceField: '___records___', }, col2: { label: 'Test reference', @@ -2566,7 +2566,7 @@ describe('state_helpers', () => { operationType: 'count', isBucketed: false, scale: 'ratio', - sourceField: 'Records', + sourceField: '___records___', customLabel: true, }, date: { @@ -2598,7 +2598,7 @@ describe('state_helpers', () => { operationType: 'count', isBucketed: false, scale: 'ratio', - sourceField: 'Records', + sourceField: '___records___', customLabel: true, }, math: { diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/time_scale_utils.test.ts b/x-pack/plugins/lens/public/indexpattern_datasource/operations/time_scale_utils.test.ts index 30f8c85a81b90..1eb02fa82ceef 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/time_scale_utils.test.ts +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/time_scale_utils.test.ts @@ -99,7 +99,7 @@ describe('time scale utils', () => { describe('adjustTimeScaleOnOtherColumnChange', () => { const baseColumn: GenericIndexPatternColumn = { operationType: 'count', - sourceField: 'Records', + sourceField: '___records___', label: 'Count of records per second', dataType: 'number', isBucketed: false, From e7800a36a363e9d63ed55c31e5d9fd9cc8501c8c Mon Sep 17 00:00:00 2001 From: Joe Reuter Date: Thu, 27 Jan 2022 14:23:54 +0100 Subject: [PATCH 3/3] fix tests --- .../lens/public/indexpattern_datasource/datapanel.test.tsx | 2 +- .../dimension_panel/dimension_panel.test.tsx | 2 +- .../lens/public/indexpattern_datasource/indexpattern.test.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/datapanel.test.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/datapanel.test.tsx index 71cc3a5052080..7fe115847b2b5 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/datapanel.test.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/datapanel.test.tsx @@ -641,7 +641,7 @@ describe('IndexPattern Data Panel', () => { }); it('should list all supported fields in the pattern sorted alphabetically in groups', async () => { const wrapper = mountWithIntl(); - expect(wrapper.find(FieldItem).first().prop('field').name).toEqual('Records'); + expect(wrapper.find(FieldItem).first().prop('field').displayName).toEqual('Records'); expect( wrapper .find('[data-test-subj="lnsIndexPatternAvailableFields"]') diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/dimension_panel.test.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/dimension_panel.test.tsx index fca45488fd2c2..975e08e5ca1a9 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/dimension_panel.test.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/dimension_panel.test.tsx @@ -350,7 +350,7 @@ describe('IndexPatternDimensionEditorPanel', () => { .filter('[data-test-subj="indexPattern-dimension-field"]') .prop('options'); - expect(options![0]['data-test-subj']).toEqual('lns-fieldOptionIncompatible-Records'); + expect(options![0]['data-test-subj']).toEqual('lns-fieldOptionIncompatible-___records___'); expect( options![1].options!.filter(({ label }) => label === 'timestampLabel')[0]['data-test-subj'] diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/indexpattern.test.ts b/x-pack/plugins/lens/public/indexpattern_datasource/indexpattern.test.ts index f906bc6046bc0..404c31010278b 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/indexpattern.test.ts +++ b/x-pack/plugins/lens/public/indexpattern_datasource/indexpattern.test.ts @@ -479,7 +479,7 @@ describe('IndexPattern Data Source', () => { Object { "arguments": Object { "idMap": Array [ - "{\\"col-0-0\\":{\\"label\\":\\"Count of records\\",\\"dataType\\":\\"number\\",\\"isBucketed\\":false,\\"sourceField\\":\\"Records\\",\\"operationType\\":\\"count\\",\\"id\\":\\"col1\\"},\\"col-1-1\\":{\\"label\\":\\"Date\\",\\"dataType\\":\\"date\\",\\"isBucketed\\":true,\\"operationType\\":\\"date_histogram\\",\\"sourceField\\":\\"timestamp\\",\\"params\\":{\\"interval\\":\\"1d\\"},\\"id\\":\\"col2\\"}}", + "{\\"col-0-0\\":{\\"label\\":\\"Count of records\\",\\"dataType\\":\\"number\\",\\"isBucketed\\":false,\\"sourceField\\":\\"___records___\\",\\"operationType\\":\\"count\\",\\"id\\":\\"col1\\"},\\"col-1-1\\":{\\"label\\":\\"Date\\",\\"dataType\\":\\"date\\",\\"isBucketed\\":true,\\"operationType\\":\\"date_histogram\\",\\"sourceField\\":\\"timestamp\\",\\"params\\":{\\"interval\\":\\"1d\\"},\\"id\\":\\"col2\\"}}", ], }, "function": "lens_rename_columns",