Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
5b0f272
composite runtime fields in data view layer
mattkime Feb 10, 2022
1b23853
update data view jest test
mattkime Feb 10, 2022
82e46c5
remove unneeded test
mattkime Feb 10, 2022
c111f36
increase limits.yml
mattkime Feb 10, 2022
2ec8449
fix UI bits
mattkime Feb 10, 2022
d8a5560
Merge branch 'main' into composite_runtime_field_data_view
kibanamachine Feb 11, 2022
c42d1bf
remove typecast
mattkime Feb 11, 2022
300f55e
Merge branch 'composite_runtime_field_data_view' of github.com:mattki…
mattkime Feb 11, 2022
d32d62c
Merge branch 'main' into composite_runtime_field_data_view
kibanamachine Feb 11, 2022
0883407
fix security solutions changes
mattkime Feb 11, 2022
1d0afde
Merge branch 'main' into composite_runtime_field_data_view
mattkime Feb 11, 2022
4a9d030
revert security solution changes
mattkime Feb 12, 2022
67f1179
check for collision on composite runtime fields
mattkime Feb 12, 2022
28fe98f
Merge branch 'main' into composite_runtime_field_data_view
kibanamachine Feb 12, 2022
6ee7011
Merge branch 'main' into composite_runtime_field_data_view
mattkime Feb 12, 2022
4817893
merge from master
mattkime Feb 12, 2022
f4e4933
Merge branch 'composite_runtime_field_data_view' of github.com:mattki…
mattkime Feb 12, 2022
ffa078b
fix jest test
mattkime Feb 12, 2022
0bdfdd8
change how field type is set for fieldspec for runtime fields.
mattkime Feb 14, 2022
2c703bf
try removing transform api change
mattkime Feb 14, 2022
4708b03
simplify infra resolveRuntimeMappings
mattkime Feb 14, 2022
0471b0e
lint fix
mattkime Feb 14, 2022
e2e95fc
fix jest test
mattkime Feb 14, 2022
12b5cc2
transform cleanup
mattkime Feb 14, 2022
3413674
fix field attribute handling for runtime fields
mattkime Feb 16, 2022
de567b4
fix field attribute handling for runtime fields
mattkime Feb 16, 2022
6802d71
cleanup
mattkime Feb 16, 2022
e736b2f
Merge branch 'main' into composite_runtime_field_data_view
mattkime Feb 16, 2022
ca6edc2
fix minor code mistakes
mattkime Feb 17, 2022
1180a84
Merge branch 'main' into composite_runtime_field_data_view
mattkime Feb 17, 2022
028b2cd
update test test
mattkime Feb 17, 2022
ef730ca
fix create runtime field jest test
mattkime Feb 17, 2022
1f31d85
Merge branch 'main' into composite_runtime_field_data_view
kibanamachine Feb 21, 2022
a485cd7
Fix unit test expectations
weltenwort Feb 22, 2022
33139c8
Merge branch 'main' into composite_runtime_field_data_view
mattkime Feb 22, 2022
7d07bd5
refactor to simplify getting multiple runtime fields for single runti…
mattkime Feb 23, 2022
edbb83f
fix removal of single runtime field:
mattkime Feb 23, 2022
3b8996b
fix tests
mattkime Feb 23, 2022
2d4b365
schema improvements
mattkime Feb 23, 2022
55fcb12
fix update runtime field, field not found
mattkime Feb 23, 2022
fb8d185
update api integration test
mattkime Feb 23, 2022
8a6a26f
update api integration test
mattkime Feb 23, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/kbn-optimizer/limits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ pageLoadAssetSize:
bfetch: 22837
kibanaUtils: 79713
data: 491273
dataViews: 41532
dataViews: 42532
expressions: 140958
fieldFormats: 65209
kibanaReact: 74422
Expand Down
8 changes: 7 additions & 1 deletion src/plugins/data_view_field_editor/public/open_editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
UsageCollectionStart,
DataViewsPublicPluginStart,
FieldFormatsStart,
RuntimeType,
} from './shared_imports';

import type { PluginStart, InternalFieldType, CloseEditor } from './types';
Expand Down Expand Up @@ -104,7 +105,12 @@ export const getFieldEditorOpener =
}

const isNewRuntimeField = !fieldName;
const isExistingRuntimeField = field && field.runtimeField && !field.isMapped;
const isExistingRuntimeField =
field &&
field.runtimeField &&
!field.isMapped &&
// treat composite field instances as mapped fields for field editing purposes
field.runtimeField.type !== ('composite' as RuntimeType);
const fieldTypeToProcess: InternalFieldType =
isNewRuntimeField || isExistingRuntimeField ? 'runtime' : 'concrete';

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import React from 'react';
import { shallow } from 'enzyme';
import { DataView } from 'src/plugins/data_views/public';
import { IndexedFieldItem } from '../../types';
import { Table, renderFieldName, getConflictModalContent } from './table';
import { Table, renderFieldName, getConflictModalContent, showDelete } from './table';
import { overlayServiceMock, themeServiceMock } from 'src/core/public/mocks';

const theme = themeServiceMock.createStartContract();
Expand Down Expand Up @@ -198,4 +198,42 @@ describe('Table', () => {
})
).toMatchSnapshot();
});

test('showDelete', () => {
const runtimeFields = [
{
name: 'customer',
info: [],
excluded: false,
kbnType: 'string',
type: 'keyword',
isMapped: false,
isUserEditable: true,
hasRuntime: true,
runtimeField: {
type: 'keyword',
},
},
{
name: 'thing',
info: [],
excluded: false,
kbnType: 'string',
type: 'keyword',
isMapped: false,
isUserEditable: true,
hasRuntime: true,
runtimeField: {
type: 'composite',
},
},
] as IndexedFieldItem[];

// indexed field
expect(showDelete(items[0])).toBe(false);
// runtime field - primitive type
expect(showDelete(runtimeFields[0])).toBe(true);
// runtime field - composite type
expect(showDelete(runtimeFields[1])).toBe(false);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ import { toMountPoint } from '../../../../../../../kibana_react/public';
import { DataView } from '../../../../../../../data_views/public';
import { IndexedFieldItem } from '../../types';

export const showDelete = (field: IndexedFieldItem) =>
!field.isMapped && field.isUserEditable && field.runtimeField?.type !== 'composite';

// localized labels
const additionalInfoAriaLabel = i18n.translate(
'indexPatternManagement.editIndexPattern.fields.table.additionalInfoAriaLabel',
Expand Down Expand Up @@ -454,7 +457,7 @@ export class Table extends PureComponent<IndexedFieldProps> {
onClick: (field) => deleteField(field.name),
type: 'icon',
'data-test-subj': 'deleteField',
available: (field) => !field.isMapped && field.isUserEditable,
available: showDelete,
},
],
width: '40px',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ const fields = [
name: 'runtime',
displayName: 'runtime',
runtimeField,
esTypes: ['long'],
type: 'number',
},
].map(mockFieldToIndexPatternField);

Expand Down
1 change: 1 addition & 0 deletions src/plugins/data_views/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const RUNTIME_FIELD_TYPES = [
'ip',
'boolean',
'geo_point',
'composite',
] as const;

/**
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

100 changes: 96 additions & 4 deletions src/plugins/data_views/common/data_views/data_view.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { IndexPatternField } from '../fields';

import { fieldFormatsMock } from '../../../field_formats/common/mocks';
import { FieldFormat } from '../../../field_formats/common';
import { RuntimeField } from '../types';
import { RuntimeField, RuntimeTypeExceptComposite } from '../types';
import { stubLogstashFields } from '../field.stub';
import { stubbedSavedObjectIndexPattern } from '../data_view.stub';

Expand All @@ -37,6 +37,8 @@ const runtimeField = {
name: 'runtime_field',
runtimeField: runtimeFieldScript,
scripted: false,
esTypes: ['keyword'],
type: 'string',
};

fieldFormatsMock.getInstance = jest.fn().mockImplementation(() => new MockFieldFormatter()) as any;
Expand Down Expand Up @@ -223,20 +225,80 @@ describe('IndexPattern', () => {
},
};

const runtimeWithAttrs = {
...runtime,
popularity: 5,
customLabel: 'custom name',
format: {
id: 'bytes',
},
};

const runtimeComposite = {
type: 'composite' as RuntimeField['type'],
script: {
source: "emit('hello world');",
},
fields: {
a: {
type: 'keyword' as RuntimeTypeExceptComposite,
},
b: {
type: 'long' as RuntimeTypeExceptComposite,
},
},
};

const runtimeCompositeWithAttrs = {
type: runtimeComposite.type,
script: runtimeComposite.script,
fields: {
a: {
...runtimeComposite.fields.a,
popularity: 3,
customLabel: 'custom name a',
format: {
id: 'bytes',
},
},
b: {
...runtimeComposite.fields.b,
popularity: 4,
customLabel: 'custom name b',
format: {
id: 'bytes',
},
},
},
};

beforeEach(() => {
const formatter = {
toJSON: () => ({ id: 'bytes' }),
} as FieldFormat;
indexPattern.getFormatterForField = () => formatter;
indexPattern.getFormatterForFieldNoDefault = () => undefined;
});

test('add and remove runtime field to existing field', () => {
indexPattern.addRuntimeField('@tags', runtime);
indexPattern.addRuntimeField('@tags', runtimeWithAttrs);
expect(indexPattern.toSpec().runtimeFieldMap).toEqual({
'@tags': runtime,
runtime_field: runtimeField.runtimeField,
});
expect(indexPattern.toSpec()!.fields!['@tags'].runtimeField).toEqual(runtime);
const field = indexPattern.toSpec()!.fields!['@tags'];
expect(field.runtimeField).toEqual(runtime);
expect(field.count).toEqual(5);
expect(field.format).toEqual({
id: 'bytes',
});
expect(field.customLabel).toEqual('custom name');
expect(indexPattern.toSpec().fieldAttrs).toEqual({
'@tags': {
customLabel: 'custom name',
count: 5,
},
});

indexPattern.removeRuntimeField('@tags');
expect(indexPattern.toSpec().runtimeFieldMap).toEqual({
Expand All @@ -246,11 +308,12 @@ describe('IndexPattern', () => {
});

test('add and remove runtime field as new field', () => {
indexPattern.addRuntimeField('new_field', runtime);
indexPattern.addRuntimeField('new_field', runtimeWithAttrs);
expect(indexPattern.toSpec().runtimeFieldMap).toEqual({
runtime_field: runtimeField.runtimeField,
new_field: runtime,
});
expect(indexPattern.getRuntimeField('new_field')).toMatchSnapshot();
expect(indexPattern.toSpec()!.fields!.new_field.runtimeField).toEqual(runtime);

indexPattern.removeRuntimeField('new_field');
Expand All @@ -260,6 +323,35 @@ describe('IndexPattern', () => {
expect(indexPattern.toSpec()!.fields!.new_field).toBeUndefined();
});

test('add and remove composite runtime field as new fields', () => {
const fieldCount = indexPattern.fields.length;
indexPattern.addRuntimeField('new_field', runtimeCompositeWithAttrs);
expect(indexPattern.toSpec().runtimeFieldMap).toEqual({
runtime_field: runtimeField.runtimeField,
new_field: runtimeComposite,
});
expect(indexPattern.fields.length - fieldCount).toEqual(2);
expect(indexPattern.getRuntimeField('new_field')).toMatchSnapshot();
expect(indexPattern.toSpec()!.fields!['new_field.a']).toBeDefined();
expect(indexPattern.toSpec()!.fields!['new_field.b']).toBeDefined();
expect(indexPattern.toSpec()!.fieldAttrs).toEqual({
'new_field.a': {
count: 3,
customLabel: 'custom name a',
},
'new_field.b': {
count: 4,
customLabel: 'custom name b',
},
});

indexPattern.removeRuntimeField('new_field');
expect(indexPattern.toSpec().runtimeFieldMap).toEqual({
runtime_field: runtimeField.runtimeField,
});
expect(indexPattern.toSpec()!.fields!.new_field).toBeUndefined();
});

test('should not allow runtime field with * in name', async () => {
try {
await indexPattern.addRuntimeField('test*123', runtime);
Expand Down
Loading