Skip to content

Commit 0c6bec1

Browse files
authored
fix count and custom label on runtime fields (#95019)
1 parent 0a5ca7b commit 0c6bec1

File tree

3 files changed

+64
-19
lines changed

3 files changed

+64
-19
lines changed

src/plugins/data/common/index_patterns/index_patterns/__snapshots__/index_patterns.test.ts.snap

Lines changed: 36 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/plugins/data/common/index_patterns/index_patterns/index_patterns.test.ts

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,25 @@ function setDocsourcePayload(id: string | null, providedPayload: any) {
2626
object = defaults(providedPayload || {}, stubbedSavedObjectIndexPattern(id));
2727
}
2828

29+
const savedObject = {
30+
id: 'id',
31+
version: 'version',
32+
attributes: {
33+
title: 'kibana-*',
34+
timeFieldName: '@timestamp',
35+
fields: '[]',
36+
sourceFilters: '[{"value":"item1"},{"value":"item2"}]',
37+
fieldFormatMap: '{"field":{}}',
38+
typeMeta: '{}',
39+
type: '',
40+
runtimeFieldMap:
41+
'{"aRuntimeField": { "type": "keyword", "script": {"source": "emit(\'hello\')"}}}',
42+
fieldAttrs: '{"aRuntimeField": { "count": 5, "customLabel": "A Runtime Field"}}',
43+
},
44+
type: 'index-pattern',
45+
references: [],
46+
};
47+
2948
describe('IndexPatterns', () => {
3049
let indexPatterns: IndexPatternsService;
3150
let savedObjectsClient: SavedObjectsClientCommon;
@@ -219,23 +238,14 @@ describe('IndexPatterns', () => {
219238
});
220239

221240
test('savedObjectToSpec', () => {
222-
const savedObject = {
223-
id: 'id',
224-
version: 'version',
225-
attributes: {
226-
title: 'kibana-*',
227-
timeFieldName: '@timestamp',
228-
fields: '[]',
229-
sourceFilters: '[{"value":"item1"},{"value":"item2"}]',
230-
fieldFormatMap: '{"field":{}}',
231-
typeMeta: '{}',
232-
type: '',
233-
},
234-
type: 'index-pattern',
235-
references: [],
236-
};
241+
const spec = indexPatterns.savedObjectToSpec(savedObject);
242+
expect(spec).toMatchSnapshot();
243+
});
237244

238-
expect(indexPatterns.savedObjectToSpec(savedObject)).toMatchSnapshot();
245+
test('correctly composes runtime field', async () => {
246+
setDocsourcePayload('id', savedObject);
247+
const indexPattern = await indexPatterns.get('id');
248+
expect(indexPattern.fields).toMatchSnapshot();
239249
});
240250

241251
test('failed requests are not cached', async () => {

src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,9 @@ export class IndexPatternsService {
425425
runtimeField: value,
426426
aggregatable: true,
427427
searchable: true,
428-
count: 0,
429428
readFromDocValues: false,
429+
customLabel: spec.fieldAttrs?.[key]?.customLabel,
430+
count: spec.fieldAttrs?.[key]?.count,
430431
};
431432
}
432433
}

0 commit comments

Comments
 (0)