[8.11] [Fleet] Bugfix - Navigate to policies list on agent policy deletion (#169930) (#169948)

# Backport

This will backport the following commits from `main` to `8.11`:
- [[Fleet] Bugfix - Navigate to policies list on agent policy deletion
(#169930)](https://github.com/elastic/kibana/pull/169930)

<!--- Backport version: 8.9.7 -->

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

<!--BACKPORT [{"author":{"name":"Cristina
Amico","email":"criamico@users.noreply.github.com"},"sourceCommit":{"committedDate":"2023-10-26T14:31:07Z","message":"[Fleet]
Bugfix - Navigate to policies list on agent policy deletion
(#169930)\n\nFixes
https://github.com/elastic/kibana/issues/169227\r\n\r\n##
Summary\r\nFixed a small bug happening on agent policy deletion: instead
of going\r\nto `app/fleet/policies`, the user remained on the deleted
policy page.\r\nThis PR reintroduces some code that got lost in
[this\r\nPR](https://github.com/elastic/kibana/pull/165921/files#diff-59d06cb588d2a5c7214e509a999de43610cf83fc30f8851884cce151b206803dL176-L178).","sha":"32a027e2cd6986e9d84875f222ed242539619491","branchLabelMapping":{"^v8.12.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:Fleet","backport:prev-minor","v8.12.0"],"number":169930,"url":"https://github.com/elastic/kibana/pull/169930","mergeCommit":{"message":"[Fleet]
Bugfix - Navigate to policies list on agent policy deletion
(#169930)\n\nFixes
https://github.com/elastic/kibana/issues/169227\r\n\r\n##
Summary\r\nFixed a small bug happening on agent policy deletion: instead
of going\r\nto `app/fleet/policies`, the user remained on the deleted
policy page.\r\nThis PR reintroduces some code that got lost in
[this\r\nPR](https://github.com/elastic/kibana/pull/165921/files#diff-59d06cb588d2a5c7214e509a999de43610cf83fc30f8851884cce151b206803dL176-L178).","sha":"32a027e2cd6986e9d84875f222ed242539619491"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.12.0","labelRegex":"^v8.12.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/169930","number":169930,"mergeCommit":{"message":"[Fleet]
Bugfix - Navigate to policies list on agent policy deletion
(#169930)\n\nFixes
https://github.com/elastic/kibana/issues/169227\r\n\r\n##
Summary\r\nFixed a small bug happening on agent policy deletion: instead
of going\r\nto `app/fleet/policies`, the user remained on the deleted
policy page.\r\nThis PR reintroduces some code that got lost in
[this\r\nPR](https://github.com/elastic/kibana/pull/165921/files#diff-59d06cb588d2a5c7214e509a999de43610cf83fc30f8851884cce151b206803dL176-L178).","sha":"32a027e2cd6986e9d84875f222ed242539619491"}}]}]
BACKPORT-->

Co-authored-by: Cristina Amico <criamico@users.noreply.github.com>
This commit is contained in:
Kibana Machine 2023-10-26 12:12:27 -04:00 committed by GitHub
parent 1638e2bd95
commit dba57f5116
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -10,8 +10,16 @@ import { EuiConfirmModal, EuiCallOut } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import { useHistory } from 'react-router-dom';
import { AGENTS_PREFIX } from '../../../constants';
import { sendDeleteAgentPolicy, useStartServices, useConfig, sendRequest } from '../../../hooks';
import {
sendDeleteAgentPolicy,
useStartServices,
useConfig,
sendRequest,
useLink,
} from '../../../hooks';
import { API_VERSIONS } from '../../../../../../common/constants';
interface Props {
@ -37,6 +45,8 @@ export const AgentPolicyDeleteProvider: React.FunctionComponent<Props> = ({
const [agentsCount, setAgentsCount] = useState<number>(0);
const [isLoading, setIsLoading] = useState<boolean>(false);
const onSuccessCallback = useRef<OnSuccessCallback | null>(null);
const { getPath } = useLink();
const history = useHistory();
const deleteAgentPolicyPrompt: DeleteAgentPolicy = (
agentPolicyToDelete,
@ -92,6 +102,7 @@ export const AgentPolicyDeleteProvider: React.FunctionComponent<Props> = ({
);
}
closeModal();
history.push(getPath('policies_list'));
};
const fetchAgentsCount = async (agentPolicyToCheck: string) => {