-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fleet] Move delete policy action from settings -> menus (#165921)
## Summary Closes #165888 Move "delete policy" action from a button on the policy settings screen to an action button on the agent policy list and in the "Actions" menu on the policy details page. This aligns the delete action with other Elastic/Kibana products, and with how we treat deletion for other resource types. <img width="592" alt="image" src="https://github.com/elastic/kibana/assets/6766512/0e893d34-fb80-4b40-933f-5c1145ab92e1"> <img width="665" alt="image" src="https://github.com/elastic/kibana/assets/6766512/fdcf76c3-2e29-4912-99de-3738c2cbbddb"> If an agent policy contains a managed package policy, the delete option will be disabled with a tooltip, e.g: <img width="514" alt="image" src="https://github.com/elastic/kibana/assets/6766512/d59226ab-a603-4a7f-80fd-9004382361f0"> I'd like to see if I can write a basic test case for the disabled logic at least before this PR lands. ### Checklist Delete any items that are not applicable to this PR. - [x] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [x] Any UI touched in this PR is usable by keyboard only (learn more about [keyboard accessibility](https://webaim.org/techniques/keyboard/))
- Loading branch information
Showing
10 changed files
with
133 additions
and
80 deletions.
There are no files selected for viewing
96 changes: 96 additions & 0 deletions
96
...ns/fleet/public/applications/fleet/sections/agent_policy/components/actions_menu.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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( | ||
<AgentPolicyActionMenu agentPolicy={agentPolicyWithStandardPackagePolicy} /> | ||
); | ||
|
||
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( | ||
<AgentPolicyActionMenu agentPolicy={agentPolicyWithManagedPackagePolicy} /> | ||
); | ||
|
||
const agentActionsButton = result.getByTestId('agentActionsBtn'); | ||
agentActionsButton.click(); | ||
|
||
const deleteButton = result.getByTestId('agentPolicyActionMenuDeleteButton'); | ||
expect(deleteButton).toHaveAttribute('disabled'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters