mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[Lens] Fix records field name and migrate (#123894)
This commit is contained in:
parent
89fc72f955
commit
fabaa88791
23 changed files with 207 additions and 99 deletions
|
@ -22,6 +22,9 @@ export const layerTypes: Record<string, LayerType> = {
|
|||
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 `#/`;
|
||||
}
|
||||
|
|
|
@ -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 = [
|
||||
{
|
||||
|
@ -640,7 +641,7 @@ describe('IndexPattern Data Panel', () => {
|
|||
});
|
||||
it('should list all supported fields in the pattern sorted alphabetically in groups', async () => {
|
||||
const wrapper = mountWithIntl(<InnerIndexPatternDataPanel {...props} />);
|
||||
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"]')
|
||||
|
@ -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);
|
||||
});
|
||||
|
|
|
@ -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']
|
||||
|
@ -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'}
|
||||
|
|
|
@ -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___',
|
||||
}),
|
||||
},
|
||||
},
|
||||
|
|
|
@ -98,7 +98,7 @@ function getCountOperationColumn(): GenericIndexPatternColumn {
|
|||
label: 'Count',
|
||||
dataType: 'number',
|
||||
isBucketed: false,
|
||||
sourceField: 'Records',
|
||||
sourceField: '___records___',
|
||||
operationType: 'count',
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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(<InnerFieldItem {...defaultProps} field={documentField} />);
|
||||
|
||||
clickField(wrapper, 'Records');
|
||||
clickField(wrapper, DOCUMENT_FIELD_NAME);
|
||||
|
||||
expect(core.http.post).not.toHaveBeenCalled();
|
||||
expect(wrapper.find(EuiPopover).prop('isOpen')).toEqual(true);
|
||||
|
|
|
@ -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: {
|
||||
|
@ -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",
|
||||
|
@ -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'],
|
||||
|
|
|
@ -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___',
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
@ -91,7 +91,7 @@ const baseColumnArgs: {
|
|||
|
||||
// Private
|
||||
operationType: 'count',
|
||||
sourceField: 'Records',
|
||||
sourceField: '___records___',
|
||||
},
|
||||
indexPattern,
|
||||
layer: {
|
||||
|
|
|
@ -79,7 +79,7 @@ describe('filters', () => {
|
|||
label: 'Count',
|
||||
dataType: 'number',
|
||||
isBucketed: false,
|
||||
sourceField: 'Records',
|
||||
sourceField: '___records___',
|
||||
operationType: 'count',
|
||||
},
|
||||
},
|
||||
|
|
|
@ -58,7 +58,7 @@ const operationDefinitionMap: Record<string, GenericOperationDefinition> = {
|
|||
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',
|
||||
|
|
|
@ -265,7 +265,7 @@ describe('formula', () => {
|
|||
previousColumn: {
|
||||
...layer.columns.col1,
|
||||
operationType: 'count',
|
||||
sourceField: 'Records',
|
||||
sourceField: '___records___',
|
||||
filter: {
|
||||
language: 'lucene',
|
||||
query: `*`,
|
||||
|
|
|
@ -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: {
|
||||
|
|
|
@ -159,7 +159,7 @@ describe('ranges', () => {
|
|||
label: 'Count',
|
||||
dataType: 'number',
|
||||
isBucketed: false,
|
||||
sourceField: 'Records',
|
||||
sourceField: '___records___',
|
||||
operationType: 'count',
|
||||
},
|
||||
},
|
||||
|
|
|
@ -86,7 +86,7 @@ function getCountOperationColumn(
|
|||
label: 'Count',
|
||||
dataType: 'number',
|
||||
isBucketed: false,
|
||||
sourceField: 'Records',
|
||||
sourceField: '___records___',
|
||||
operationType: 'count',
|
||||
...params,
|
||||
};
|
||||
|
|
|
@ -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',
|
||||
},
|
||||
},
|
||||
|
|
|
@ -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: {
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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<VisState716> };
|
||||
const migratedLensState = commonRenameFilterReferences(lensState.attributes);
|
||||
const lensState = state as unknown as { attributes: LensDocShape715 };
|
||||
const migratedLensState = commonRenameRecordsField(
|
||||
commonRenameFilterReferences(lensState.attributes)
|
||||
);
|
||||
return {
|
||||
...lensState,
|
||||
attributes: migratedLensState,
|
||||
|
|
|
@ -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<VisState716>) => {
|
||||
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<Filter[]>) => {
|
||||
|
|
|
@ -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<LensDocShape810>;
|
||||
|
||||
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<LensDocShape, LensDocShape>
|
||||
>;
|
||||
|
||||
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';
|
||||
|
||||
|
|
|
@ -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<VisualizationState = unknown> {
|
||||
|
@ -444,14 +446,16 @@ const moveDefaultReversedPaletteToCustom: SavedObjectMigrationFn<
|
|||
return { ...newDoc, attributes: commonMakeReversePaletteAsCustom(newDoc.attributes) };
|
||||
};
|
||||
|
||||
const renameFilterReferences: SavedObjectMigrationFn<
|
||||
LensDocShape715<VisState716>,
|
||||
LensDocShape715<VisState716>
|
||||
> = (doc) => {
|
||||
const renameFilterReferences: SavedObjectMigrationFn<LensDocShape715, LensDocShape810> = (doc) => {
|
||||
const newDoc = cloneDeep(doc);
|
||||
return { ...newDoc, attributes: commonRenameFilterReferences(newDoc.attributes) };
|
||||
};
|
||||
|
||||
const renameRecordsField: SavedObjectMigrationFn<LensDocShape810, LensDocShape810> = (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 = (
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue