Skip to content

Commit

Permalink
[Fleet] Bugfix - Navigate to policies list on agent policy deletion (e…
Browse files Browse the repository at this point in the history
…lastic#169930)

Fixes elastic#169227

## Summary
Fixed a small bug happening on agent policy deletion: instead of going
to `app/fleet/policies`, the user remained on the deleted policy page.
This PR reintroduces some code that got lost in [this
PR](https://github.com/elastic/kibana/pull/165921/files#diff-59d06cb588d2a5c7214e509a999de43610cf83fc30f8851884cce151b206803dL176-L178).
  • Loading branch information
criamico authored Oct 26, 2023
1 parent 7be59c3 commit 32a027e
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down Expand Up @@ -92,6 +102,7 @@ export const AgentPolicyDeleteProvider: React.FunctionComponent<Props> = ({
);
}
closeModal();
history.push(getPath('policies_list'));
};

const fetchAgentsCount = async (agentPolicyToCheck: string) => {
Expand Down

0 comments on commit 32a027e

Please sign in to comment.