[Graph] Disable runtime fields showing up in Graph (#90010)

* [Graph] Disable runtime fields

* Fix jest test

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Tim Roes 2021-02-03 16:02:36 +01:00 committed by GitHub
parent 9bee677f68
commit 72cb883d80
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 6 deletions

View file

@ -5,7 +5,7 @@
*/
import { GraphWorkspaceSavedObject, IndexPatternSavedObject, Workspace } from '../../types';
import { migrateLegacyIndexPatternRef, savedWorkspaceToAppState } from './deserialize';
import { migrateLegacyIndexPatternRef, savedWorkspaceToAppState, mapFields } from './deserialize';
import { createWorkspace } from '../../angular/graph_client_workspace';
import { outlinkEncoders } from '../../helpers/outlink_encoders';
import { IndexPattern } from '../../../../../../src/plugins/data/public';
@ -119,9 +119,9 @@ describe('deserialize', () => {
savedWorkspace,
{
getNonScriptedFields: () => [
{ name: 'field1', type: 'string', aggregatable: true },
{ name: 'field2', type: 'string', aggregatable: true },
{ name: 'field3', type: 'string', aggregatable: true },
{ name: 'field1', type: 'string', aggregatable: true, isMapped: true },
{ name: 'field2', type: 'string', aggregatable: true, isMapped: true },
{ name: 'field3', type: 'string', aggregatable: true, isMapped: true },
],
} as IndexPattern,
workspace
@ -236,4 +236,22 @@ describe('deserialize', () => {
expect(workspacePayload).toEqual(savedWorkspace);
});
});
describe('mapFields', () => {
it('should not include unmapped fields', () => {
const indexPattern = {
getNonScriptedFields: () => [
{ name: 'field1', type: 'string', aggregatable: true, isMapped: true },
{ name: 'field2', type: 'string', aggregatable: true, isMapped: true },
{ name: 'runtimeField', type: 'string', aggregatable: true, isMapped: false },
{ name: 'field3', type: 'string', aggregatable: true, isMapped: true },
],
} as IndexPattern;
expect(mapFields(indexPattern).map(({ name }) => name)).toEqual([
'field1',
'field2',
'field3',
]);
});
});
});

View file

@ -104,7 +104,11 @@ export function mapFields(indexPattern: IndexPattern): WorkspaceField[] {
return indexPattern
.getNonScriptedFields()
.filter(
(field) => !blockedFieldNames.includes(field.name) && !indexPatternsUtils.isNestedField(field)
(field) =>
// Make sure to only include mapped fields, e.g. no index pattern runtime fields
field.isMapped &&
!blockedFieldNames.includes(field.name) &&
!indexPatternsUtils.isNestedField(field)
)
.map((field, index) => ({
name: field.name,

View file

@ -25,7 +25,7 @@ describe('datasource saga', () => {
get: jest.fn(() =>
Promise.resolve({
title: 'test-pattern',
getNonScriptedFields: () => [{ name: 'field1', type: 'string' }],
getNonScriptedFields: () => [{ name: 'field1', type: 'string', isMapped: true }],
} as IndexPattern)
),
},