Skip to content

Commit

Permalink
[Lens] Fix records field name and migrate (#123894)
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 authored Jan 31, 2022
1 parent 89fc72f commit fabaa88
Show file tree
Hide file tree
Showing 23 changed files with 207 additions and 99 deletions.
3 changes: 3 additions & 0 deletions x-pack/plugins/lens/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 `#/`;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
{
Expand Down Expand Up @@ -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"]')
Expand Down Expand Up @@ -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);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -481,7 +481,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
dataType: 'number',
isBucketed: false,
operationType: 'count',
sourceField: 'Records',
sourceField: '___records___',
},
})}
/>
Expand Down Expand Up @@ -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', () => {
Expand All @@ -1004,7 +1004,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
isBucketed: false,
label: '',
operationType: 'count',
sourceField: 'Records',
sourceField: '___records___',
},
})}
columnId="col2"
Expand Down Expand Up @@ -1090,7 +1090,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
isBucketed: false,
label: 'Count of records',
operationType: 'count',
sourceField: 'Records',
sourceField: '___records___',
...colOverrides,
} as GenericIndexPatternColumn,
}),
Expand Down Expand Up @@ -1320,7 +1320,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
isBucketed: false,
label: 'Count of records',
operationType: 'count',
sourceField: 'Records',
sourceField: '___records___',
...colOverrides,
} as GenericIndexPatternColumn,
}),
Expand All @@ -1337,7 +1337,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
isBucketed: false,
label: 'Count of records',
operationType: 'count',
sourceField: 'Records',
sourceField: '___records___',
} as GenericIndexPatternColumn,
}),
columnId: 'col2',
Expand Down Expand Up @@ -1524,7 +1524,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
isBucketed: false,
label: 'Count of records',
operationType: 'count',
sourceField: 'Records',
sourceField: '___records___',
...colOverrides,
} as GenericIndexPatternColumn,
}),
Expand Down Expand Up @@ -1871,7 +1871,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
isBucketed: false,
label: '',
operationType: 'count',
sourceField: 'Records',
sourceField: '___records___',
},
})}
columnId={'col2'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
label: 'Count of records',
dataType: 'number',
isBucketed: false,
sourceField: 'Records',
sourceField: '___records___',
operationType: 'count',
},
},
Expand Down Expand Up @@ -1186,7 +1186,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
label: 'Count of records',
dataType: 'number',
isBucketed: false,
sourceField: 'Records',
sourceField: '___records___',
operationType: 'count',
},
},
Expand Down Expand Up @@ -1249,7 +1249,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
label: 'Count of records',
dataType: 'number',
isBucketed: false,
sourceField: 'Records',
sourceField: '___records___',
operationType: 'count',
},
ref2: {
Expand Down Expand Up @@ -1329,7 +1329,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
label: 'Count of records',
dataType: 'number',
isBucketed: false,
sourceField: 'Records',
sourceField: '___records___',
operationType: 'count',
},
ref2: {
Expand Down Expand Up @@ -1415,7 +1415,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
label: 'Count of records',
dataType: 'number',
isBucketed: false,
sourceField: 'Records',
sourceField: '___records___',
operationType: 'count',
},
col2: {
Expand Down Expand Up @@ -1605,7 +1605,7 @@ describe('IndexPatternDimensionEditorPanel', () => {

// Private
operationType: 'count',
sourceField: 'Records',
sourceField: '___records___',
customLabel: true,
},
},
Expand Down Expand Up @@ -1822,15 +1822,15 @@ describe('IndexPatternDimensionEditorPanel', () => {
operationType: 'count',
label: '',
isBucketed: false,
sourceField: 'Records',
sourceField: '___records___',
customLabel: true,
},
col6: {
dataType: 'number',
operationType: 'count',
label: '',
isBucketed: false,
sourceField: 'Records',
sourceField: '___records___',
customLabel: true,
},
},
Expand Down Expand Up @@ -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___',
}),
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function getCountOperationColumn(): GenericIndexPatternColumn {
label: 'Count',
dataType: 'number',
isBucketed: false,
sourceField: 'Records',
sourceField: '___records___',
operationType: 'count',
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import { i18n } from '@kbn/i18n';
import { DOCUMENT_FIELD_NAME } from '../../common';
import { IndexPatternField } from './types';

/**
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
Loading

0 comments on commit fabaa88

Please sign in to comment.