fix count and custom label on runtime fields (#95019) (#95053)

This commit is contained in:
Matthew Kime 2021-03-22 10:42:38 -05:00 committed by GitHub
parent be92bf37ba
commit 0eaaade078
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 64 additions and 19 deletions

View file

@ -1,16 +1,50 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`IndexPatterns correctly composes runtime field 1`] = `
FldList [
Object {
"aggregatable": true,
"conflictDescriptions": undefined,
"count": 5,
"customLabel": "A Runtime Field",
"esTypes": Array [
"keyword",
],
"lang": undefined,
"name": "aRuntimeField",
"readFromDocValues": false,
"script": undefined,
"scripted": false,
"searchable": true,
"subType": undefined,
"type": "string",
},
]
`;
exports[`IndexPatterns savedObjectToSpec 1`] = `
Object {
"allowNoIndex": undefined,
"fieldAttrs": Object {},
"fieldAttrs": Object {
"aRuntimeField": Object {
"count": 5,
"customLabel": "A Runtime Field",
},
},
"fieldFormats": Object {
"field": Object {},
},
"fields": Object {},
"id": "id",
"intervalName": undefined,
"runtimeFieldMap": Object {},
"runtimeFieldMap": Object {
"aRuntimeField": Object {
"script": Object {
"source": "emit('hello')",
},
"type": "keyword",
},
},
"sourceFilters": Array [
Object {
"value": "item1",

View file

@ -26,6 +26,25 @@ function setDocsourcePayload(id: string | null, providedPayload: any) {
object = defaults(providedPayload || {}, stubbedSavedObjectIndexPattern(id));
}
const savedObject = {
id: 'id',
version: 'version',
attributes: {
title: 'kibana-*',
timeFieldName: '@timestamp',
fields: '[]',
sourceFilters: '[{"value":"item1"},{"value":"item2"}]',
fieldFormatMap: '{"field":{}}',
typeMeta: '{}',
type: '',
runtimeFieldMap:
'{"aRuntimeField": { "type": "keyword", "script": {"source": "emit(\'hello\')"}}}',
fieldAttrs: '{"aRuntimeField": { "count": 5, "customLabel": "A Runtime Field"}}',
},
type: 'index-pattern',
references: [],
};
describe('IndexPatterns', () => {
let indexPatterns: IndexPatternsService;
let savedObjectsClient: SavedObjectsClientCommon;
@ -220,23 +239,14 @@ describe('IndexPatterns', () => {
});
test('savedObjectToSpec', () => {
const savedObject = {
id: 'id',
version: 'version',
attributes: {
title: 'kibana-*',
timeFieldName: '@timestamp',
fields: '[]',
sourceFilters: '[{"value":"item1"},{"value":"item2"}]',
fieldFormatMap: '{"field":{}}',
typeMeta: '{}',
type: '',
},
type: 'index-pattern',
references: [],
};
const spec = indexPatterns.savedObjectToSpec(savedObject);
expect(spec).toMatchSnapshot();
});
expect(indexPatterns.savedObjectToSpec(savedObject)).toMatchSnapshot();
test('correctly composes runtime field', async () => {
setDocsourcePayload('id', savedObject);
const indexPattern = await indexPatterns.get('id');
expect(indexPattern.fields).toMatchSnapshot();
});
test('failed requests are not cached', async () => {

View file

@ -429,8 +429,9 @@ export class IndexPatternsService {
runtimeField: value,
aggregatable: true,
searchable: true,
count: 0,
readFromDocValues: false,
customLabel: spec.fieldAttrs?.[key]?.customLabel,
count: spec.fieldAttrs?.[key]?.count,
};
}
}