[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:
parent
9bee677f68
commit
72cb883d80
|
@ -5,7 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { GraphWorkspaceSavedObject, IndexPatternSavedObject, Workspace } from '../../types';
|
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 { createWorkspace } from '../../angular/graph_client_workspace';
|
||||||
import { outlinkEncoders } from '../../helpers/outlink_encoders';
|
import { outlinkEncoders } from '../../helpers/outlink_encoders';
|
||||||
import { IndexPattern } from '../../../../../../src/plugins/data/public';
|
import { IndexPattern } from '../../../../../../src/plugins/data/public';
|
||||||
|
@ -119,9 +119,9 @@ describe('deserialize', () => {
|
||||||
savedWorkspace,
|
savedWorkspace,
|
||||||
{
|
{
|
||||||
getNonScriptedFields: () => [
|
getNonScriptedFields: () => [
|
||||||
{ name: 'field1', type: 'string', aggregatable: true },
|
{ name: 'field1', type: 'string', aggregatable: true, isMapped: true },
|
||||||
{ name: 'field2', type: 'string', aggregatable: true },
|
{ name: 'field2', type: 'string', aggregatable: true, isMapped: true },
|
||||||
{ name: 'field3', type: 'string', aggregatable: true },
|
{ name: 'field3', type: 'string', aggregatable: true, isMapped: true },
|
||||||
],
|
],
|
||||||
} as IndexPattern,
|
} as IndexPattern,
|
||||||
workspace
|
workspace
|
||||||
|
@ -236,4 +236,22 @@ describe('deserialize', () => {
|
||||||
expect(workspacePayload).toEqual(savedWorkspace);
|
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',
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -104,7 +104,11 @@ export function mapFields(indexPattern: IndexPattern): WorkspaceField[] {
|
||||||
return indexPattern
|
return indexPattern
|
||||||
.getNonScriptedFields()
|
.getNonScriptedFields()
|
||||||
.filter(
|
.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) => ({
|
.map((field, index) => ({
|
||||||
name: field.name,
|
name: field.name,
|
||||||
|
|
|
@ -25,7 +25,7 @@ describe('datasource saga', () => {
|
||||||
get: jest.fn(() =>
|
get: jest.fn(() =>
|
||||||
Promise.resolve({
|
Promise.resolve({
|
||||||
title: 'test-pattern',
|
title: 'test-pattern',
|
||||||
getNonScriptedFields: () => [{ name: 'field1', type: 'string' }],
|
getNonScriptedFields: () => [{ name: 'field1', type: 'string', isMapped: true }],
|
||||||
} as IndexPattern)
|
} as IndexPattern)
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue