don't include group fields with no child fields in index pattern (#69457)

This commit is contained in:
Sandra Gonzales 2020-06-18 13:49:03 -04:00 committed by GitHub
parent 2436e2c9a6
commit f4b0d5cbbc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 4 deletions

View file

@ -611,7 +611,7 @@ exports[`creating index patterns from yaml fields createIndexPatternFields funct
}
`;
exports[`creating index patterns from yaml fields flattenFields function flattens recursively and handles copying alias fields: flattenFields 1`] = `
exports[`creating index patterns from yaml fields flattenFields function flattens recursively and handles copying alias fields flattenFields matches snapshot: flattenFields 1`] = `
[
{
"name": "coredns.id",

View file

@ -56,9 +56,15 @@ describe('creating index patterns from yaml fields', () => {
expect(indexPattern).toMatchSnapshot('createIndexPattern');
});
test('flattenFields function flattens recursively and handles copying alias fields', () => {
const flattened = flattenFields(fields);
expect(flattened).toMatchSnapshot('flattenFields');
describe('flattenFields function flattens recursively and handles copying alias fields', () => {
test('a field of type group with no nested fields is skipped', () => {
const flattened = flattenFields([{ name: 'nginx', type: 'group' }]);
expect(flattened.length).toBe(0);
});
test('flattenFields matches snapshot', () => {
const flattened = flattenFields(fields);
expect(flattened).toMatchSnapshot('flattenFields');
});
});
describe('dedupFields', () => {

View file

@ -307,6 +307,10 @@ export const transformField = (field: Field, i: number, fields: Fields): IndexPa
export const flattenFields = (allFields: Fields): Fields => {
const flatten = (fields: Fields): Fields =>
fields.reduce<Field[]>((acc, field) => {
// if this is a group fields with no fields, skip the field
if (field.type === 'group' && !field.fields?.length) {
return acc;
}
// recurse through nested fields
if (field.type === 'group' && field.fields?.length) {
// skip if field.enabled is not explicitly set to false

View file

@ -116,3 +116,5 @@
type: keyword
- name: text
type: text
- name: nginx
type: group