Skip to content

Commit

Permalink
[8.x] Add a warning callout when deleting managed assets (#207329) (#…
Browse files Browse the repository at this point in the history
…208491)

# Backport

This will backport the following commits from `main` to `8.x`:
- [Add a warning callout when deleting managed assets
(#207329)](#207329)

<!--- Backport version: 9.6.4 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Ignacio
Rivas","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-01-28T08:46:58Z","message":"Add
a warning callout when deleting managed assets
(#207329)","sha":"c8bd387668ed3e6fe0fd71ec9cfbc5be58bbfc5c","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Index
Management","Team:Kibana
Management","release_note:skip","v9.0.0","Feature:Ingest Node
Pipelines","backport:prev-minor"],"title":"Add a warning callout when
deleting managed
assets","number":207329,"url":"https://github.com/elastic/kibana/pull/207329","mergeCommit":{"message":"Add
a warning callout when deleting managed assets
(#207329)","sha":"c8bd387668ed3e6fe0fd71ec9cfbc5be58bbfc5c"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/207329","number":207329,"mergeCommit":{"message":"Add
a warning callout when deleting managed assets
(#207329)","sha":"c8bd387668ed3e6fe0fd71ec9cfbc5be58bbfc5c"}}]}]
BACKPORT-->

---------

Co-authored-by: kibanamachine <[email protected]>
  • Loading branch information
sabarasaba and kibanamachine authored Jan 30, 2025
1 parent 5cd5f6c commit 1cf806f
Show file tree
Hide file tree
Showing 26 changed files with 284 additions and 26 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ src/platform/packages/private/default-nav/analytics @elastic/kibana-data-discove
src/platform/packages/private/default-nav/devtools @elastic/kibana-management
src/platform/packages/private/default-nav/management @elastic/kibana-management
src/platform/packages/private/default-nav/ml @elastic/ml-ui
src/platform/packages/shared/kbn-management/delete_managed_assets_callout @elastic/kibana-management
packages/kbn-dependency-usage @elastic/kibana-security
packages/kbn-dev-cli-errors @elastic/kibana-operations
packages/kbn-dev-cli-runner @elastic/kibana-operations
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@
"@kbn/default-nav-devtools": "link:src/platform/packages/private/default-nav/devtools",
"@kbn/default-nav-management": "link:src/platform/packages/private/default-nav/management",
"@kbn/default-nav-ml": "link:src/platform/packages/private/default-nav/ml",
"@kbn/delete-managed-asset-callout": "link:src/platform/packages/shared/kbn-management/delete_managed_assets_callout",
"@kbn/dev-tools-plugin": "link:src/platform/plugins/shared/dev_tools",
"@kbn/developer-examples-plugin": "link:examples/developer_examples",
"@kbn/discover-contextual-components": "link:src/platform/packages/shared/kbn-discover-contextual-components",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
id: kbn-management/components/DeleteManagedAssetsCallout
slug: /kbn-management/components/delete_managed_assets_callout
title: Delete Managed Assets Callout
description: A callout component that displays a warning message for when a user is about to delete a managed asset.
tags: ['management', 'component']
date: 2025-01-20
---

This component is used to display a warning callout when a user is about to delete a managed asset.


```typescript
<DeleteManagedAssetsCallout assetName="ingest pipeline" />
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export type { DeleteManagedAssetsCalloutProps } from './src/callout';
export { DeleteManagedAssetsCallout } from './src/callout';
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "shared-common",
"id": "@kbn/delete-managed-asset-callout",
"owner": "@elastic/kibana-management",
"group": "platform",
"visibility": "shared"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "@kbn/delete-managed-asset-callout",
"private": true,
"version": "1.0.0",
"license": "Elastic License 2.0 OR AGPL-3.0-only OR SSPL-1.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import React from 'react';

import { DeleteManagedAssetsCallout as Component } from './callout';

export default {
title: 'Developer/Delete Managed Assets Callout',
description: '',
};

export const DeleteManagedAssetsCallout = () => {
return <Component assetName="ingest pipelines" />;
};

export const ErrorDeleteManagedAssetsCallout = () => {
return <Component assetName="ingest pipelines" color="danger" iconType="trash" />;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import React from 'react';
import { i18n } from '@kbn/i18n';
import type { EuiCallOutProps } from '@elastic/eui';
import { EuiCallOut } from '@elastic/eui';

export interface DeleteManagedAssetsCalloutProps extends EuiCallOutProps {
assetName: string;
overrideBody?: string;
}

export const DeleteManagedAssetsCallout = ({
assetName,
overrideBody,
...overrideCalloutProps
}: DeleteManagedAssetsCalloutProps) => {
return (
<EuiCallOut
color="warning"
iconType="warning"
data-test-subj="deleteManagedAssetsCallout"
{...overrideCalloutProps}
>
<p>
{overrideBody ??
i18n.translate('management.deleteManagedAssetsCallout.body', {
defaultMessage: `Elasticsearch automatically re-creates any missing managed {assetName}. If you delete managed {assetName}, the deletion appears as successful, but the {assetName} are immediately re-created and reappear.`,
values: { assetName },
})}
</p>
</EuiCallOut>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"extends": "../../../../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "target/types",
"types": [
"jest",
"node",
"react"
]
},
"include": [
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"target/**/*"
],
"kbn_references": [
"@kbn/i18n",
]
}
2 changes: 2 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,8 @@
"@kbn/default-nav-management/*": ["src/platform/packages/private/default-nav/management/*"],
"@kbn/default-nav-ml": ["src/platform/packages/private/default-nav/ml"],
"@kbn/default-nav-ml/*": ["src/platform/packages/private/default-nav/ml/*"],
"@kbn/delete-managed-asset-callout": ["src/platform/packages/shared/kbn-management/delete_managed_assets_callout"],
"@kbn/delete-managed-asset-callout/*": ["src/platform/packages/shared/kbn-management/delete_managed_assets_callout/*"],
"@kbn/dependency-usage": ["packages/kbn-dependency-usage"],
"@kbn/dependency-usage/*": ["packages/kbn-dependency-usage/*"],
"@kbn/dev-cli-errors": ["packages/kbn-dev-cli-errors"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ describe('Index Templates tab', () => {
`${API_BASE_PATH}/delete_index_templates`,
expect.objectContaining({
body: JSON.stringify({
templates: [{ name: templates[0].name, isLegacy }],
templates: [{ name: templates[0].name, isLegacy, type: 'default' }],
}),
})
);
Expand Down Expand Up @@ -518,7 +518,7 @@ describe('Index Templates tab', () => {
`${API_BASE_PATH}/delete_index_templates`,
expect.objectContaining({
body: JSON.stringify({
templates: [{ name: templates[0].name, isLegacy: false }],
templates: [{ name: templates[0].name, isLegacy: false, type: 'default' }],
}),
})
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,29 @@
*/

import React, { Fragment, useState } from 'react';
import { EuiConfirmModal, EuiCallOut, EuiCheckbox, EuiBadge } from '@elastic/eui';
import { EuiConfirmModal, EuiCallOut, EuiCheckbox, EuiBadge, EuiSpacer } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';

import { DeleteManagedAssetsCallout } from '@kbn/delete-managed-asset-callout';
import { deleteTemplates } from '../services/api';
import { notificationService } from '../services/notification';

export const TemplateDeleteModal = ({
templatesToDelete,
callback,
}: {
templatesToDelete: Array<{ name: string; isLegacy?: boolean }>;
templatesToDelete: Array<{ name: string; isLegacy?: boolean; type?: string }>;
callback: (data?: { hasDeletedTemplates: boolean }) => void;
}) => {
const [isDeleteConfirmed, setIsDeleteConfirmed] = useState<boolean>(false);

const numTemplatesToDelete = templatesToDelete.length;

const hasSystemTemplate = Boolean(templatesToDelete.find(({ name }) => name.startsWith('.')));
const managedTemplatesToDelete = templatesToDelete.filter(
({ type }) => type === 'managed'
).length;

const handleDeleteTemplates = () => {
deleteTemplates(templatesToDelete).then(({ data: { templatesDeleted, errors }, error }) => {
Expand Down Expand Up @@ -109,6 +113,17 @@ export const TemplateDeleteModal = ({
confirmButtonDisabled={hasSystemTemplate ? !isDeleteConfirmed : false}
>
<Fragment>
{managedTemplatesToDelete > 0 && (
<>
<DeleteManagedAssetsCallout
assetName={i18n.translate('xpack.idxMgmt.deleteTemplatesModal.assetName', {
defaultMessage: 'index templates',
})}
/>

<EuiSpacer size="m" />
</>
)}
<p>
<FormattedMessage
id="xpack.idxMgmt.deleteTemplatesModal.deleteDescription"
Expand All @@ -118,9 +133,20 @@ export const TemplateDeleteModal = ({
</p>

<ul>
{templatesToDelete.map(({ name }) => (
{templatesToDelete.map(({ name, type }) => (
<li key={name}>
{name}
{type === 'managed' && (
<>
{' '}
<EuiBadge color="hollow">
<FormattedMessage
id="xpack.idxMgmt.deleteTemplatesModal.managedTemplateLabel"
defaultMessage="Managed"
/>
</EuiBadge>
</>
)}
{name.startsWith('.') ? (
<Fragment>
{' '}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const tabToUiMetricMap: { [key: string]: string } = {
};

export interface Props {
template: { name: string; isLegacy?: boolean };
template: { name: string; isLegacy?: boolean; type?: string };
onClose: () => void;
editTemplate: (name: string, isLegacy?: boolean) => void;
cloneTemplate: (name: string, isLegacy?: boolean) => void;
Expand All @@ -106,8 +106,9 @@ export const TemplateDetailsContent = ({
const { uiMetricService } = useServices();
const { error, data: templateDetails, isLoading } = useLoadIndexTemplate(templateName, isLegacy);
const isCloudManaged = templateDetails?._kbnMeta.type === 'cloudManaged';
const templateType = templateDetails?._kbnMeta.type;
const [templateToDelete, setTemplateToDelete] = useState<
Array<{ name: string; isLegacy?: boolean }>
Array<{ name: string; isLegacy?: boolean; type?: string }>
>([]);
const [activeTab, setActiveTab] = useState<string>(SUMMARY_TAB_ID);
const [isPopoverOpen, setIsPopOverOpen] = useState<boolean>(false);
Expand Down Expand Up @@ -306,7 +307,11 @@ export const TemplateDetailsContent = ({
defaultMessage: 'Delete',
}),
icon: 'trash',
onClick: () => setTemplateToDelete([{ name: templateName, isLegacy }]),
onClick: () =>
setTemplateToDelete([
{ name: templateName, isLegacy, type: templateType },
]),
'data-test-subj': 'deleteIndexTemplateButton',
disabled: isCloudManaged,
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const TemplateTable: React.FunctionComponent<Props> = ({
const { uiMetricService } = useServices();
const [selection, setSelection] = useState<TemplateListItem[]>([]);
const [templatesToDelete, setTemplatesToDelete] = useState<
Array<{ name: string; isLegacy?: boolean }>
Array<{ name: string; isLegacy?: boolean; type?: string }>
>([]);

const columns: Array<EuiBasicTableColumn<TemplateListItem>> = [
Expand Down Expand Up @@ -182,8 +182,8 @@ export const TemplateTable: React.FunctionComponent<Props> = ({
icon: 'trash',
color: 'danger',
type: 'icon',
onClick: ({ name, _kbnMeta: { isLegacy } }: TemplateListItem) => {
setTemplatesToDelete([{ name, isLegacy }]);
onClick: ({ name, _kbnMeta: { isLegacy, type } }: TemplateListItem) => {
setTemplatesToDelete([{ name, isLegacy, type }]);
},
isPrimary: true,
enabled: ({ _kbnMeta: { type } }: TemplateListItem) => type !== 'cloudManaged',
Expand Down Expand Up @@ -233,9 +233,10 @@ export const TemplateTable: React.FunctionComponent<Props> = ({
data-test-subj="deleteTemplatesButton"
onClick={() =>
setTemplatesToDelete(
selection.map(({ name, _kbnMeta: { isLegacy } }: TemplateListItem) => ({
selection.map(({ name, _kbnMeta: { isLegacy, type } }: TemplateListItem) => ({
name,
isLegacy,
type,
}))
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const bodySchema = schema.object({
schema.object({
name: schema.string(),
isLegacy: schema.maybe(schema.boolean()),
type: schema.maybe(schema.string()),
})
),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"@kbn/unsaved-changes-prompt",
"@kbn/shared-ux-table-persist",
"@kbn/core-application-browser",
"@kbn/delete-managed-asset-callout",
"@kbn/inference-endpoint-ui-common",
],
"exclude": ["target/**/*"]
Expand Down
Loading

0 comments on commit 1cf806f

Please sign in to comment.