Skip to content

Commit 78f939b

Browse files
disable delete for active templates
1 parent 808435a commit 78f939b

File tree

3 files changed

+54
-5
lines changed
  • x-pack/plugins/index_management

3 files changed

+54
-5
lines changed

x-pack/plugins/index_management/public/application/sections/home/component_template_list/table.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
EuiButton,
1313
EuiInMemoryTableProps,
1414
EuiTableFieldDataColumnType,
15+
EuiIcon,
1516
} from '@elastic/eui';
1617

1718
interface ComponentTemplate {
@@ -38,6 +39,13 @@ export const ComponentTable: FunctionComponent<Props> = ({
3839
sorting: { sort: { field: 'name', direction: 'asc' } },
3940
selection: {
4041
onSelectionChange: setSelection,
42+
selectable: ({ isActive }) => !isActive,
43+
selectableMessage: (selectable) =>
44+
!selectable
45+
? i18n.translate('xpack.idxMgmt.componentTemplatesList.table.disabledSelectionLabel', {
46+
defaultMessage: 'Component template is in use',
47+
})
48+
: undefined,
4149
},
4250
rowProps: () => ({
4351
'data-test-subj': 'componentTemplateTableRow',
@@ -63,9 +71,7 @@ export const ComponentTable: FunctionComponent<Props> = ({
6371
values={{ count: selection.length }}
6472
/>
6573
</EuiButton>
66-
) : (
67-
undefined
68-
),
74+
) : undefined,
6975
toolsRight: [
7076
<EuiButton
7177
key="reloadButton"
@@ -115,6 +121,14 @@ export const ComponentTable: FunctionComponent<Props> = ({
115121
</EuiLink>
116122
),
117123
},
124+
{
125+
field: 'isActive',
126+
name: i18n.translate('xpack.idxMgmt.componentTemplatesList.table.isActiveColumnTitle', {
127+
defaultMessage: 'Active',
128+
}),
129+
sortable: true,
130+
render: (isActive: boolean) => (isActive ? <EuiIcon type="check" /> : null),
131+
},
118132
{
119133
name: (
120134
<FormattedMessage
@@ -167,6 +181,7 @@ export const ComponentTable: FunctionComponent<Props> = ({
167181
icon: 'trash',
168182
color: 'danger',
169183
onClick: ({ name }) => onDeleteClick([name]),
184+
enabled: ({ isActive }) => !isActive,
170185
},
171186
],
172187
},

x-pack/plugins/index_management/server/client/elasticsearch.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export const elasticsearchJsPlugin = (Client: any, config: any, components: any)
1010
Client.prototype.dataManagement = components.clientAction.namespaceFactory();
1111
const dataManagement = Client.prototype.dataManagement.prototype;
1212

13+
// Component template routes
1314
dataManagement.getComponentTemplates = ca({
1415
urls: [
1516
{
@@ -60,4 +61,14 @@ export const elasticsearchJsPlugin = (Client: any, config: any, components: any)
6061
],
6162
method: 'DELETE',
6263
});
64+
65+
// Index templates v2
66+
dataManagement.getComposableIndexTemplates = ca({
67+
urls: [
68+
{
69+
fmt: '/_index_template',
70+
},
71+
],
72+
method: 'GET',
73+
});
6374
};

x-pack/plugins/index_management/server/routes/api/component_templates/get.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ const paramsSchema = schema.object({
1212
name: schema.string(),
1313
});
1414

15+
const getComponentTemplatesInUse = (indexTemplates) => {
16+
const componentTemplates = indexTemplates.map(({ index_template: indexTemplate }) => {
17+
return indexTemplate.composed_of;
18+
});
19+
return [].concat.apply([], componentTemplates); // return flattened array
20+
};
21+
1522
export function registerGetAllRoute({ router, license, lib: { isEsError } }: RouteDependencies) {
1623
// Get all component templates
1724
router.get(
@@ -20,9 +27,25 @@ export function registerGetAllRoute({ router, license, lib: { isEsError } }: Rou
2027
const { callAsCurrentUser } = ctx.dataManagement!.client;
2128

2229
try {
23-
const response = await callAsCurrentUser('dataManagement.getComponentTemplates');
30+
const { component_templates: componentTemplates } = await callAsCurrentUser(
31+
'dataManagement.getComponentTemplates'
32+
);
33+
34+
const { index_templates: indexTemplates } = await callAsCurrentUser(
35+
'dataManagement.getComposableIndexTemplates'
36+
);
37+
38+
const activeComponentTemplates = getComponentTemplatesInUse(indexTemplates);
39+
40+
const body = componentTemplates.map((component) => {
41+
const isActive = activeComponentTemplates.includes(component.name);
42+
return {
43+
...component,
44+
isActive,
45+
};
46+
});
2447

25-
return res.ok({ body: response.component_templates });
48+
return res.ok({ body });
2649
} catch (error) {
2750
if (isEsError(error)) {
2851
return res.customError({

0 commit comments

Comments
 (0)