Skip to content

Commit e35a42a

Browse files
[Component templates] Form wizard (#69732)
1 parent 2eb0896 commit e35a42a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2195
-103
lines changed

x-pack/plugins/index_management/common/lib/component_template_serialization.test.ts

Lines changed: 138 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -4,91 +4,164 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import { deserializeComponentTemplate } from './component_template_serialization';
7+
import {
8+
deserializeComponentTemplate,
9+
serializeComponentTemplate,
10+
} from './component_template_serialization';
811

9-
describe('deserializeComponentTemplate', () => {
10-
test('deserializes a component template', () => {
11-
expect(
12-
deserializeComponentTemplate(
13-
{
14-
name: 'my_component_template',
15-
component_template: {
16-
version: 1,
17-
_meta: {
18-
serialization: {
19-
id: 10,
20-
class: 'MyComponentTemplate',
21-
},
22-
description: 'set number of shards to one',
23-
},
24-
template: {
25-
settings: {
26-
number_of_shards: 1,
12+
describe('Component template serialization', () => {
13+
describe('deserializeComponentTemplate()', () => {
14+
test('deserializes a component template', () => {
15+
expect(
16+
deserializeComponentTemplate(
17+
{
18+
name: 'my_component_template',
19+
component_template: {
20+
version: 1,
21+
_meta: {
22+
serialization: {
23+
id: 10,
24+
class: 'MyComponentTemplate',
25+
},
26+
description: 'set number of shards to one',
2727
},
28-
mappings: {
29-
_source: {
30-
enabled: false,
28+
template: {
29+
settings: {
30+
number_of_shards: 1,
3131
},
32-
properties: {
33-
host_name: {
34-
type: 'keyword',
32+
mappings: {
33+
_source: {
34+
enabled: false,
3535
},
36-
created_at: {
37-
type: 'date',
38-
format: 'EEE MMM dd HH:mm:ss Z yyyy',
36+
properties: {
37+
host_name: {
38+
type: 'keyword',
39+
},
40+
created_at: {
41+
type: 'date',
42+
format: 'EEE MMM dd HH:mm:ss Z yyyy',
43+
},
3944
},
4045
},
4146
},
4247
},
4348
},
44-
},
45-
[
46-
{
47-
name: 'my_index_template',
48-
index_template: {
49-
index_patterns: ['foo'],
50-
template: {
51-
settings: {
52-
number_of_replicas: 2,
49+
[
50+
{
51+
name: 'my_index_template',
52+
index_template: {
53+
index_patterns: ['foo'],
54+
template: {
55+
settings: {
56+
number_of_replicas: 2,
57+
},
5358
},
59+
composed_of: ['my_component_template'],
60+
},
61+
},
62+
]
63+
)
64+
).toEqual({
65+
name: 'my_component_template',
66+
version: 1,
67+
_meta: {
68+
serialization: {
69+
id: 10,
70+
class: 'MyComponentTemplate',
71+
},
72+
description: 'set number of shards to one',
73+
},
74+
template: {
75+
settings: {
76+
number_of_shards: 1,
77+
},
78+
mappings: {
79+
_source: {
80+
enabled: false,
81+
},
82+
properties: {
83+
host_name: {
84+
type: 'keyword',
85+
},
86+
created_at: {
87+
type: 'date',
88+
format: 'EEE MMM dd HH:mm:ss Z yyyy',
5489
},
55-
composed_of: ['my_component_template'],
5690
},
5791
},
58-
]
59-
)
60-
).toEqual({
61-
name: 'my_component_template',
62-
version: 1,
63-
_meta: {
64-
serialization: {
65-
id: 10,
66-
class: 'MyComponentTemplate',
6792
},
68-
description: 'set number of shards to one',
69-
},
70-
template: {
71-
settings: {
72-
number_of_shards: 1,
93+
_kbnMeta: {
94+
usedBy: ['my_index_template'],
7395
},
74-
mappings: {
75-
_source: {
76-
enabled: false,
96+
});
97+
});
98+
});
99+
100+
describe('serializeComponentTemplate()', () => {
101+
test('serialize a component template', () => {
102+
expect(
103+
serializeComponentTemplate({
104+
name: 'my_component_template',
105+
version: 1,
106+
_kbnMeta: {
107+
usedBy: [],
108+
},
109+
_meta: {
110+
serialization: {
111+
id: 10,
112+
class: 'MyComponentTemplate',
113+
},
114+
description: 'set number of shards to one',
115+
},
116+
template: {
117+
settings: {
118+
number_of_shards: 1,
119+
},
120+
mappings: {
121+
_source: {
122+
enabled: false,
123+
},
124+
properties: {
125+
host_name: {
126+
type: 'keyword',
127+
},
128+
created_at: {
129+
type: 'date',
130+
format: 'EEE MMM dd HH:mm:ss Z yyyy',
131+
},
132+
},
133+
},
134+
},
135+
})
136+
).toEqual({
137+
version: 1,
138+
_meta: {
139+
serialization: {
140+
id: 10,
141+
class: 'MyComponentTemplate',
77142
},
78-
properties: {
79-
host_name: {
80-
type: 'keyword',
143+
description: 'set number of shards to one',
144+
},
145+
template: {
146+
settings: {
147+
number_of_shards: 1,
148+
},
149+
mappings: {
150+
_source: {
151+
enabled: false,
81152
},
82-
created_at: {
83-
type: 'date',
84-
format: 'EEE MMM dd HH:mm:ss Z yyyy',
153+
properties: {
154+
host_name: {
155+
type: 'keyword',
156+
},
157+
created_at: {
158+
type: 'date',
159+
format: 'EEE MMM dd HH:mm:ss Z yyyy',
160+
},
85161
},
86162
},
87163
},
88-
},
89-
_kbnMeta: {
90-
usedBy: ['my_index_template'],
91-
},
164+
});
92165
});
93166
});
94167
});

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
ComponentTemplateFromEs,
99
ComponentTemplateDeserialized,
1010
ComponentTemplateListItem,
11+
ComponentTemplateSerialized,
1112
} from '../types';
1213

1314
const hasEntries = (data: object = {}) => Object.entries(data).length > 0;
@@ -84,3 +85,15 @@ export function deserializeComponenTemplateList(
8485

8586
return componentTemplateListItem;
8687
}
88+
89+
export function serializeComponentTemplate(
90+
componentTemplateDeserialized: ComponentTemplateDeserialized
91+
): ComponentTemplateSerialized {
92+
const { version, template, _meta } = componentTemplateDeserialized;
93+
94+
return {
95+
version,
96+
template,
97+
_meta,
98+
};
99+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ export { getTemplateParameter } from './utils';
2020
export {
2121
deserializeComponentTemplate,
2222
deserializeComponenTemplateList,
23+
serializeComponentTemplate,
2324
} from './component_template_serialization';

x-pack/plugins/index_management/public/application/app.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ import { TemplateClone } from './sections/template_clone';
1616
import { TemplateEdit } from './sections/template_edit';
1717

1818
import { useServices } from './app_context';
19+
import {
20+
ComponentTemplateCreate,
21+
ComponentTemplateEdit,
22+
ComponentTemplateClone,
23+
} from './components';
1924

2025
export const App = ({ history }: { history: ScopedHistory }) => {
2126
const { uiMetricService } = useServices();
@@ -34,6 +39,13 @@ export const AppWithoutRouter = () => (
3439
<Route exact path="/create_template" component={TemplateCreate} />
3540
<Route exact path="/clone_template/:name*" component={TemplateClone} />
3641
<Route exact path="/edit_template/:name*" component={TemplateEdit} />
42+
<Route exact path="/create_component_template" component={ComponentTemplateCreate} />
43+
<Route
44+
exact
45+
path="/create_component_template/:sourceComponentTemplateName"
46+
component={ComponentTemplateClone}
47+
/>
48+
<Route exact path="/edit_component_template/:name*" component={ComponentTemplateEdit} />
3749
<Route path={`/:section(${homeSections.join('|')})`} component={IndexManagementHome} />
3850
<Redirect from={`/`} to={`/indices`} />
3951
</Switch>

x-pack/plugins/index_management/public/application/app_context.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66

77
import React, { createContext, useContext } from 'react';
88
import { ScopedHistory } from 'kibana/public';
9+
import { ManagementAppMountParams } from 'src/plugins/management/public';
910
import { UsageCollectionSetup } from 'src/plugins/usage_collection/public';
10-
1111
import { CoreStart } from '../../../../../src/core/public';
12+
1213
import { IngestManagerSetup } from '../../../ingest_manager/public';
1314
import { IndexMgmtMetricsType } from '../types';
1415
import { UiMetricService, NotificationService, HttpService } from './services';
@@ -32,6 +33,7 @@ export interface AppDependencies {
3233
notificationService: NotificationService;
3334
};
3435
history: ScopedHistory;
36+
setBreadcrumbs: ManagementAppMountParams['setBreadcrumbs'];
3537
}
3638

3739
export const AppContextProvider = ({

0 commit comments

Comments
 (0)