Skip to content

Commit d58f52d

Browse files
authored
[Composable template] Demo and PR review fixes (#71065)
1 parent 9bfdb1c commit d58f52d

File tree

38 files changed

+756
-500
lines changed

38 files changed

+756
-500
lines changed

src/plugins/es_ui_shared/static/forms/components/form_row.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,9 @@ export const FormRow = ({
5757
titleWrapped = title;
5858
}
5959

60-
if (!children && !field) {
61-
throw new Error('You need to provide either children or a field to the FormRow');
62-
}
63-
6460
return (
6561
<EuiDescribedFormGroup title={titleWrapped} description={description} fullWidth>
66-
{children ? children : <Field field={field!} {...rest} />}
62+
{children ? children : field ? <Field field={field!} {...rest} /> : null}
6763
</EuiDescribedFormGroup>
6864
);
6965
};

x-pack/plugins/index_management/__jest__/client_integration/home/index_templates_tab.helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ const createActions = (testBed: TestBed<TestSubjects>) => {
9595
find('closeDetailsButton').simulate('click');
9696
};
9797

98-
const toggleViewItem = (view: 'composable' | 'system') => {
98+
const toggleViewItem = (view: 'managed' | 'cloudManaged' | 'system') => {
9999
const { find, component } = testBed;
100-
const views = ['composable', 'system'];
100+
const views = ['managed', 'cloudManaged', 'system'];
101101

102102
// First open the pop over
103103
act(() => {

x-pack/plugins/index_management/__jest__/client_integration/home/index_templates_tab.test.ts

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ describe('Index Templates tab', () => {
6363
},
6464
},
6565
});
66-
(template1 as any).hasSettings = true;
6766

6867
const template2 = fixtures.getTemplate({
6968
name: `b${getRandomString()}`,
@@ -73,6 +72,7 @@ describe('Index Templates tab', () => {
7372
const template3 = fixtures.getTemplate({
7473
name: `.c${getRandomString()}`, // mock system template
7574
indexPatterns: ['template3Pattern1*', 'template3Pattern2', 'template3Pattern3'],
75+
type: 'system',
7676
});
7777

7878
const template4 = fixtures.getTemplate({
@@ -101,6 +101,7 @@ describe('Index Templates tab', () => {
101101
name: `.c${getRandomString()}`, // mock system template
102102
indexPatterns: ['template6Pattern1*', 'template6Pattern2', 'template6Pattern3'],
103103
isLegacy: true,
104+
type: 'system',
104105
});
105106

106107
const templates = [template1, template2, template3];
@@ -124,44 +125,49 @@ describe('Index Templates tab', () => {
124125
// Test composable table content
125126
tableCellsValues.forEach((row, i) => {
126127
const indexTemplate = templates[i];
127-
const { name, indexPatterns, priority, ilmPolicy, composedOf, template } = indexTemplate;
128+
const { name, indexPatterns, ilmPolicy, composedOf, template } = indexTemplate;
128129

129130
const hasContent = !!template.settings || !!template.mappings || !!template.aliases;
130131
const ilmPolicyName = ilmPolicy && ilmPolicy.name ? ilmPolicy.name : '';
131132
const composedOfString = composedOf ? composedOf.join(',') : '';
132-
const priorityFormatted = priority ? priority.toString() : '';
133-
134-
expect(removeWhiteSpaceOnArrayValues(row)).toEqual([
135-
'', // Checkbox to select row
136-
name,
137-
indexPatterns.join(', '),
138-
ilmPolicyName,
139-
composedOfString,
140-
priorityFormatted,
141-
hasContent ? 'M S A' : 'None', // M S A -> Mappings Settings Aliases badges
142-
'', // Column of actions
143-
]);
133+
134+
try {
135+
expect(removeWhiteSpaceOnArrayValues(row)).toEqual([
136+
'', // Checkbox to select row
137+
name,
138+
indexPatterns.join(', '),
139+
ilmPolicyName,
140+
composedOfString,
141+
hasContent ? 'M S A' : 'None', // M S A -> Mappings Settings Aliases badges
142+
'', // Column of actions
143+
]);
144+
} catch (e) {
145+
console.error(`Error in index template at row ${i}`); // eslint-disable-line no-console
146+
throw e;
147+
}
144148
});
145149

146150
// Test legacy table content
147151
legacyTableCellsValues.forEach((row, i) => {
148-
const template = legacyTemplates[i];
149-
const { name, indexPatterns, order, ilmPolicy } = template;
152+
const legacyIndexTemplate = legacyTemplates[i];
153+
const { name, indexPatterns, ilmPolicy, template } = legacyIndexTemplate;
150154

155+
const hasContent = !!template.settings || !!template.mappings || !!template.aliases;
151156
const ilmPolicyName = ilmPolicy && ilmPolicy.name ? ilmPolicy.name : '';
152-
const orderFormatted = order ? order.toString() : order;
153-
154-
expect(removeWhiteSpaceOnArrayValues(row)).toEqual([
155-
'',
156-
name,
157-
indexPatterns.join(', '),
158-
ilmPolicyName,
159-
orderFormatted,
160-
'',
161-
'',
162-
'',
163-
'',
164-
]);
157+
158+
try {
159+
expect(removeWhiteSpaceOnArrayValues(row)).toEqual([
160+
'',
161+
name,
162+
indexPatterns.join(', '),
163+
ilmPolicyName,
164+
hasContent ? 'M S A' : 'None', // M S A -> Mappings Settings Aliases badges
165+
'', // Column of actions
166+
]);
167+
} catch (e) {
168+
console.error(`Error in legacy template at row ${i}`); // eslint-disable-line no-console
169+
throw e;
170+
}
165171
});
166172
});
167173

@@ -211,7 +217,7 @@ describe('Index Templates tab', () => {
211217
await actions.clickTemplateAt(0);
212218
expect(exists('templateList')).toBe(true);
213219
expect(exists('templateDetails')).toBe(true);
214-
expect(find('templateDetails.title').text()).toBe(templates[0].name);
220+
expect(find('templateDetails.title').text().trim()).toBe(templates[0].name);
215221

216222
// Close flyout
217223
await act(async () => {
@@ -223,7 +229,7 @@ describe('Index Templates tab', () => {
223229

224230
expect(exists('templateList')).toBe(true);
225231
expect(exists('templateDetails')).toBe(true);
226-
expect(find('templateDetails.title').text()).toBe(legacyTemplates[0].name);
232+
expect(find('templateDetails.title').text().trim()).toBe(legacyTemplates[0].name);
227233
});
228234

229235
describe('table row actions', () => {
@@ -460,7 +466,7 @@ describe('Index Templates tab', () => {
460466
const { find } = testBed;
461467
const [{ name }] = templates;
462468

463-
expect(find('templateDetails.title').text()).toEqual(name);
469+
expect(find('templateDetails.title').text().trim()).toEqual(name);
464470
});
465471

466472
it('should have a close button and be able to close flyout', async () => {

x-pack/plugins/index_management/__jest__/client_integration/index_template_wizard/template_create.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,8 @@ describe.skip('<TemplateCreate />', () => {
368368
aliases: ALIASES,
369369
},
370370
_kbnMeta: {
371+
type: 'default',
371372
isLegacy: false,
372-
isManaged: false,
373373
},
374374
};
375375

x-pack/plugins/index_management/__jest__/client_integration/index_template_wizard/template_edit.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ describe.skip('<TemplateEdit />', () => {
213213
aliases: ALIASES,
214214
},
215215
_kbnMeta: {
216-
isManaged: false,
216+
type: 'default',
217217
isLegacy: templateToEdit._kbnMeta.isLegacy,
218218
},
219219
};

x-pack/plugins/index_management/common/lib/template_serialization.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,28 @@ import {
88
LegacyTemplateSerialized,
99
TemplateSerialized,
1010
TemplateListItem,
11+
TemplateType,
1112
} from '../types';
1213

1314
const hasEntries = (data: object = {}) => Object.entries(data).length > 0;
1415

1516
export function serializeTemplate(templateDeserialized: TemplateDeserialized): TemplateSerialized {
16-
const { version, priority, indexPatterns, template, composedOf, _meta } = templateDeserialized;
17+
const {
18+
version,
19+
priority,
20+
indexPatterns,
21+
template,
22+
composedOf,
23+
dataStream,
24+
_meta,
25+
} = templateDeserialized;
1726

1827
return {
1928
version,
2029
priority,
2130
template,
2231
index_patterns: indexPatterns,
32+
data_stream: dataStream,
2333
composed_of: composedOf,
2434
_meta,
2535
};
@@ -41,6 +51,15 @@ export function deserializeTemplate(
4151
} = templateEs;
4252
const { settings } = template;
4353

54+
let type: TemplateType = 'default';
55+
if (Boolean(cloudManagedTemplatePrefix && name.startsWith(cloudManagedTemplatePrefix))) {
56+
type = 'cloudManaged';
57+
} else if (name.startsWith('.')) {
58+
type = 'system';
59+
} else if (Boolean(_meta?.managed === true)) {
60+
type = 'managed';
61+
}
62+
4463
const deserializedTemplate: TemplateDeserialized = {
4564
name,
4665
version,
@@ -52,10 +71,7 @@ export function deserializeTemplate(
5271
dataStream,
5372
_meta,
5473
_kbnMeta: {
55-
isManaged: Boolean(_meta?.managed === true),
56-
isCloudManaged: Boolean(
57-
cloudManagedTemplatePrefix && name.startsWith(cloudManagedTemplatePrefix)
58-
),
74+
type,
5975
hasDatastream: Boolean(dataStream),
6076
},
6177
};

x-pack/plugins/index_management/common/lib/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ export const getTemplateParameter = (
2323
) => {
2424
return isLegacyTemplate(template)
2525
? (template as LegacyTemplateSerialized)[setting]
26-
: (template as TemplateSerialized).template[setting];
26+
: (template as TemplateSerialized).template?.[setting];
2727
};

x-pack/plugins/index_management/common/types/templates.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,24 @@ export interface TemplateDeserialized {
3838
aliases?: Aliases;
3939
mappings?: Mappings;
4040
};
41-
composedOf?: string[]; // Used on composable index template
41+
composedOf?: string[]; // Composable template only
4242
version?: number;
43-
priority?: number;
44-
order?: number; // Used on legacy index template
43+
priority?: number; // Composable template only
44+
order?: number; // Legacy template only
4545
ilmPolicy?: {
4646
name: string;
4747
};
48-
_meta?: { [key: string]: any };
49-
dataStream?: { timestamp_field: string };
48+
_meta?: { [key: string]: any }; // Composable template only
49+
dataStream?: { timestamp_field: string }; // Composable template only
5050
_kbnMeta: {
51-
isManaged: boolean;
52-
isCloudManaged: boolean;
51+
type: TemplateType;
5352
hasDatastream: boolean;
5453
isLegacy?: boolean;
5554
};
5655
}
5756

57+
export type TemplateType = 'default' | 'managed' | 'cloudManaged' | 'system';
58+
5859
export interface TemplateFromEs {
5960
name: string;
6061
index_template: TemplateSerialized;
@@ -78,8 +79,7 @@ export interface TemplateListItem {
7879
name: string;
7980
};
8081
_kbnMeta: {
81-
isManaged: boolean;
82-
isCloudManaged: boolean;
82+
type: TemplateType;
8383
hasDatastream: boolean;
8484
isLegacy?: boolean;
8585
};

x-pack/plugins/index_management/public/application/components/component_templates/__jest__/client_integration/component_template_create.test.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,6 @@ describe('<ComponentTemplateCreate />', () => {
177177
template: {
178178
settings: SETTINGS,
179179
mappings: {
180-
_source: {},
181-
_meta: {},
182180
properties: {
183181
[BOOLEAN_MAPPING_FIELD.name]: {
184182
type: BOOLEAN_MAPPING_FIELD.type,

x-pack/plugins/index_management/public/application/components/component_templates/__jest__/client_integration/component_template_edit.test.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,6 @@ describe('<ComponentTemplateEdit />', () => {
109109
...COMPONENT_TEMPLATE_TO_EDIT,
110110
template: {
111111
...COMPONENT_TEMPLATE_TO_EDIT.template,
112-
mappings: {
113-
_meta: {},
114-
_source: {},
115-
properties: {},
116-
},
117112
},
118113
};
119114

0 commit comments

Comments
 (0)