diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/actions_menu.test.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/actions_menu.test.tsx
new file mode 100644
index 0000000000000..215860c9d475f
--- /dev/null
+++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/actions_menu.test.tsx
@@ -0,0 +1,96 @@
+/*
+ * 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; you may not use this file except in compliance with the Elastic License
+ * 2.0.
+ */
+import React from 'react';
+
+import type { AgentPolicy, PackagePolicy } from '../../../../../../common/types';
+
+import { createFleetTestRendererMock } from '../../../../../mock';
+
+import { AgentPolicyActionMenu } from './actions_menu';
+
+describe('AgentPolicyActionMenu', () => {
+ const baseAgentPolicy: AgentPolicy = {
+ id: 'test',
+ is_managed: false,
+ is_protected: false,
+ name: 'test-agent-policy',
+ namespace: 'default',
+ package_policies: [] as PackagePolicy[],
+ revision: 1,
+ status: 'active',
+ updated_at: new Date().toISOString(),
+ updated_by: 'test',
+ };
+
+ describe('delete action', () => {
+ it('is enabled when a managed package policy is not present', () => {
+ const testRenderer = createFleetTestRendererMock();
+ const agentPolicyWithStandardPackagePolicy: AgentPolicy = {
+ ...baseAgentPolicy,
+ package_policies: [
+ {
+ id: 'test-package-policy',
+ is_managed: false,
+ created_at: new Date().toISOString(),
+ created_by: 'test',
+ enabled: true,
+ inputs: [],
+ name: 'test-package-policy',
+ namespace: 'default',
+ policy_id: 'test',
+ revision: 1,
+ updated_at: new Date().toISOString(),
+ updated_by: 'test',
+ },
+ ],
+ };
+
+ const result = testRenderer.render(
+
+ );
+
+ const agentActionsButton = result.getByTestId('agentActionsBtn');
+ agentActionsButton.click();
+
+ const deleteButton = result.getByTestId('agentPolicyActionMenuDeleteButton');
+ expect(deleteButton).not.toHaveAttribute('disabled');
+ });
+
+ it('is disabled when a managed package policy is present', () => {
+ const testRenderer = createFleetTestRendererMock();
+ const agentPolicyWithManagedPackagePolicy: AgentPolicy = {
+ ...baseAgentPolicy,
+ package_policies: [
+ {
+ id: 'test-package-policy',
+ is_managed: true,
+ created_at: new Date().toISOString(),
+ created_by: 'test',
+ enabled: true,
+ inputs: [],
+ name: 'test-package-policy',
+ namespace: 'default',
+ policy_id: 'test',
+ revision: 1,
+ updated_at: new Date().toISOString(),
+ updated_by: 'test',
+ },
+ ],
+ };
+
+ const result = testRenderer.render(
+
+ );
+
+ const agentActionsButton = result.getByTestId('agentActionsBtn');
+ agentActionsButton.click();
+
+ const deleteButton = result.getByTestId('agentPolicyActionMenuDeleteButton');
+ expect(deleteButton).toHaveAttribute('disabled');
+ });
+ });
+});
diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/actions_menu.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/actions_menu.tsx
index 16efc77f25fe1..fa97cf08f6d91 100644
--- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/actions_menu.tsx
+++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/actions_menu.tsx
@@ -18,10 +18,11 @@ import {
} from '../../../components';
import { FLEET_SERVER_PACKAGE } from '../../../constants';
-import { ExperimentalFeaturesService } from '../../../../../services/experimental_features';
+import { policyHasFleetServer, ExperimentalFeaturesService } from '../../../services';
import { AgentPolicyYamlFlyout } from './agent_policy_yaml_flyout';
import { AgentPolicyCopyProvider } from './agent_policy_copy_provider';
+import { AgentPolicyDeleteProvider } from './agent_policy_delete_provider';
export const AgentPolicyActionMenu = memo<{
agentPolicy: AgentPolicy;
@@ -55,6 +56,10 @@ export const AgentPolicyActionMenu = memo<{
[agentPolicy]
);
+ const hasManagedPackagePolicy =
+ 'package_policies' in agentPolicy &&
+ agentPolicy?.package_policies?.some((packagePolicy) => packagePolicy.is_managed);
+
const [isContextMenuOpen, setIsContextMenuOpen] = useState(false);
const onContextMenuChange = useCallback(
@@ -129,6 +134,35 @@ export const AgentPolicyActionMenu = memo<{
defaultMessage="Duplicate policy"
/>
,
+
+ {(deleteAgentPolicyPrompt) => (
+
+ ) : undefined
+ }
+ icon="trash"
+ onClick={() => {
+ deleteAgentPolicyPrompt(agentPolicy.id);
+ }}
+ >
+
+
+ )}
+ ,
];
if (agentTamperProtectionEnabled && !agentPolicy?.is_managed) {
diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_advanced_fields/index.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_advanced_fields/index.tsx
index 49288da22c935..686934377fdf3 100644
--- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_advanced_fields/index.tsx
+++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_advanced_fields/index.tsx
@@ -13,7 +13,6 @@ import {
EuiComboBox,
EuiIconTip,
EuiCheckboxGroup,
- EuiButton,
EuiLink,
EuiFieldNumber,
EuiFieldText,
@@ -41,10 +40,9 @@ import { useStartServices, useConfig, useGetAgentPolicies, useLicense } from '..
import { AgentPolicyPackageBadge } from '../../../../components';
import { UninstallCommandFlyout } from '../../../../../../components';
-import { AgentPolicyDeleteProvider } from '../agent_policy_delete_provider';
import type { ValidationResults } from '../agent_policy_validation';
-import { ExperimentalFeaturesService, policyHasFleetServer } from '../../../../services';
+import { ExperimentalFeaturesService } from '../../../../services';
import { policyHasEndpointSecurity as hasElasticDefend } from '../../../../../../../common/services';
@@ -60,7 +58,6 @@ interface Props {
updateAgentPolicy: (u: Partial) => void;
validation: ValidationResults;
isEditing?: boolean;
- onDelete?: () => void;
}
export const AgentPolicyAdvancedOptionsContent: React.FunctionComponent = ({
@@ -68,7 +65,6 @@ export const AgentPolicyAdvancedOptionsContent: React.FunctionComponent =
updateAgentPolicy,
validation,
isEditing = false,
- onDelete = () => {},
}) => {
const { docLinks } = useStartServices();
const config = useConfig();
@@ -101,10 +97,6 @@ export const AgentPolicyAdvancedOptionsContent: React.FunctionComponent =
// agent monitoring checkbox group can appear multiple times in the DOM, ids have to be unique to work correctly
const monitoringCheckboxIdSuffix = Date.now();
- const hasManagedPackagePolicy =
- 'package_policies' in agentPolicy &&
- agentPolicy?.package_policies?.some((packagePolicy) => packagePolicy.is_managed);
-
const { agentTamperProtectionEnabled } = ExperimentalFeaturesService.get();
const licenseService = useLicense();
const [isUninstallCommandFlyoutOpen, setIsUninstallCommandFlyoutOpen] = useState(false);
@@ -725,57 +717,7 @@ export const AgentPolicyAdvancedOptionsContent: React.FunctionComponent =
/>
- {isEditing && 'id' in agentPolicy && !agentPolicy.is_managed ? (
-
-
-
- }
- description={
- <>
-
-
-
- {(deleteAgentPolicyPrompt) => {
- return (
-
- ) : undefined
- }
- >
- deleteAgentPolicyPrompt(agentPolicy.id!, onDelete)}
- isDisabled={hasManagedPackagePolicy}
- >
-
-
-
- );
- }}
-
- >
- }
- />
- ) : null}
+
>
);
};
diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_create_inline.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_create_inline.tsx
index 7abeb00dfb65d..b3f06abf72e12 100644
--- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_create_inline.tsx
+++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_create_inline.tsx
@@ -189,7 +189,6 @@ export const AgentPolicyCreateInlineForm: React.FunctionComponent = ({
updateAgentPolicy={updateNewAgentPolicy}
validation={validation}
isEditing={false}
- onDelete={() => {}}
/>
>
diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_form.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_form.tsx
index e4720bad5a091..e3bf5fb72dfe3 100644
--- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_form.tsx
+++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_form.tsx
@@ -36,7 +36,6 @@ interface Props {
updateSysMonitoring: (newValue: boolean) => void;
validation: ValidationResults;
isEditing?: boolean;
- onDelete?: () => void;
}
export const AgentPolicyForm: React.FunctionComponent = ({
@@ -46,7 +45,6 @@ export const AgentPolicyForm: React.FunctionComponent = ({
updateSysMonitoring,
validation,
isEditing = false,
- onDelete = () => {},
}) => {
const generalSettingsWrapper = (children: JSX.Element[]) => (
= ({
updateAgentPolicy={updateAgentPolicy}
validation={validation}
isEditing={isEditing}
- onDelete={onDelete}
/>
>
@@ -122,7 +119,6 @@ export const AgentPolicyForm: React.FunctionComponent = ({
updateAgentPolicy={updateAgentPolicy}
validation={validation}
isEditing={isEditing}
- onDelete={onDelete}
/>
)}
diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_integration.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_integration.tsx
index da7ca2f3e18ec..759c85b54a181 100644
--- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_integration.tsx
+++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_integration.tsx
@@ -102,7 +102,6 @@ export const AgentPolicyIntegrationForm: React.FunctionComponent = ({
updateAgentPolicy={updateAgentPolicy}
validation={validation}
isEditing={isEditing}
- onDelete={onDelete}
/>
>
diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/details_page/components/settings/index.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/details_page/components/settings/index.tsx
index 0728a3d369d87..eb77e63fd2c82 100644
--- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/details_page/components/settings/index.tsx
+++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/details_page/components/settings/index.tsx
@@ -6,7 +6,6 @@
*/
import React, { memo, useMemo, useState } from 'react';
-import { useHistory } from 'react-router-dom';
import styled from 'styled-components';
import { pick } from 'lodash';
import {
@@ -22,7 +21,6 @@ import { FormattedMessage } from '@kbn/i18n-react';
import type { AgentPolicy } from '../../../../../types';
import {
- useLink,
useStartServices,
useAuthz,
sendUpdateAgentPolicy,
@@ -69,8 +67,6 @@ export const SettingsView = memo<{ agentPolicy: AgentPolicy }>(
const {
agents: { enabled: isFleetEnabled },
} = useConfig();
- const history = useHistory();
- const { getPath } = useLink();
const hasFleetAllPrivileges = useAuthz().fleet.all;
const refreshAgentPolicy = useAgentPolicyRefresh();
const [agentPolicy, setAgentPolicy] = useState({
@@ -173,9 +169,6 @@ export const SettingsView = memo<{ agentPolicy: AgentPolicy }>(
updateSysMonitoring={(newValue) => setWithSysMonitoring(newValue)}
validation={validation}
isEditing={true}
- onDelete={() => {
- history.push(getPath('policies_list'));
- }}
/>
{hasChanges ? (
diff --git a/x-pack/plugins/translations/translations/fr-FR.json b/x-pack/plugins/translations/translations/fr-FR.json
index 29fd5965bf442..13b1bb541f32e 100644
--- a/x-pack/plugins/translations/translations/fr-FR.json
+++ b/x-pack/plugins/translations/translations/fr-FR.json
@@ -16564,8 +16564,6 @@
"xpack.fleet.policyDetailsPackagePolicies.createFirstTitle": "Ajouter votre première intégration",
"xpack.fleet.policyForm.deletePolicyActionText": "Supprimer la stratégie",
"xpack.fleet.policyForm.deletePolicyActionText.disabled": "La politique d'agent avec les politiques de package géré ne peut pas être supprimée.",
- "xpack.fleet.policyForm.deletePolicyGroupDescription": "Les données existantes ne sont pas supprimées.",
- "xpack.fleet.policyForm.deletePolicyGroupTitle": "Supprimer la stratégie",
"xpack.fleet.policyForm.generalSettingsGroupDescription": "Attribuez un nom et ajoutez une description à votre stratégie d'agent.",
"xpack.fleet.policyForm.generalSettingsGroupTitle": "Paramètres généraux",
"xpack.fleet.renameAgentTags.errorNotificationTitle": "La balise n’a pas pu être renommée",
diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json
index 7c8ed5b0a5813..92622d22912c6 100644
--- a/x-pack/plugins/translations/translations/ja-JP.json
+++ b/x-pack/plugins/translations/translations/ja-JP.json
@@ -16578,8 +16578,6 @@
"xpack.fleet.policyDetailsPackagePolicies.createFirstTitle": "最初の統合を追加",
"xpack.fleet.policyForm.deletePolicyActionText": "ポリシーを削除",
"xpack.fleet.policyForm.deletePolicyActionText.disabled": "管理されたパッケージポリシーのエージェントポリシーは削除できません。",
- "xpack.fleet.policyForm.deletePolicyGroupDescription": "既存のデータは削除されません。",
- "xpack.fleet.policyForm.deletePolicyGroupTitle": "ポリシーを削除",
"xpack.fleet.policyForm.generalSettingsGroupDescription": "エージェントポリシーの名前と説明を選択してください。",
"xpack.fleet.policyForm.generalSettingsGroupTitle": "一般設定",
"xpack.fleet.renameAgentTags.errorNotificationTitle": "タグ名の変更が失敗しました",
diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json
index b4899f5bd0b4c..802100e31b448 100644
--- a/x-pack/plugins/translations/translations/zh-CN.json
+++ b/x-pack/plugins/translations/translations/zh-CN.json
@@ -16578,8 +16578,6 @@
"xpack.fleet.policyDetailsPackagePolicies.createFirstTitle": "添加您的首个集成",
"xpack.fleet.policyForm.deletePolicyActionText": "删除策略",
"xpack.fleet.policyForm.deletePolicyActionText.disabled": "无法删除包含托管软件包策略的代理策略。",
- "xpack.fleet.policyForm.deletePolicyGroupDescription": "现有数据将不会删除。",
- "xpack.fleet.policyForm.deletePolicyGroupTitle": "删除策略",
"xpack.fleet.policyForm.generalSettingsGroupDescription": "为您的代理策略选择名称和描述。",
"xpack.fleet.policyForm.generalSettingsGroupTitle": "常规设置",
"xpack.fleet.renameAgentTags.errorNotificationTitle": "标签重命名失败",