diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/edit_package_policy_page/index.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/edit_package_policy_page/index.tsx index 4c7fbaacf02de..acaf623afa330 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/edit_package_policy_page/index.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/edit_package_policy_page/index.tsx @@ -184,24 +184,23 @@ export const EditPackagePolicyForm = memo<{ // if `from === 'edit'` then it links back to Policy Details // if `from === 'package-edit'`, or `upgrade-from-integrations-policy-list` then it links back to the Integration Policy List const cancelUrl = useMemo((): string => { - if (packageInfo && policyId) { - return from === 'package-edit' - ? getHref('integration_details_policies', { - pkgkey: pkgKeyFromPackageInfo(packageInfo!), - }) - : getHref('policy_details', { policyId }); - } - return '/'; + return from === 'package-edit' && packageInfo + ? getHref('integration_details_policies', { + pkgkey: pkgKeyFromPackageInfo(packageInfo!), + }) + : policyId + ? getHref('policy_details', { policyId }) + : '/'; }, [from, getHref, packageInfo, policyId]); const successRedirectPath = useMemo(() => { - if (packageInfo && policyId) { - return from === 'package-edit' || from === 'upgrade-from-integrations-policy-list' - ? getHref('integration_details_policies', { - pkgkey: pkgKeyFromPackageInfo(packageInfo!), - }) - : getHref('policy_details', { policyId }); - } - return '/'; + return (from === 'package-edit' || from === 'upgrade-from-integrations-policy-list') && + packageInfo + ? getHref('integration_details_policies', { + pkgkey: pkgKeyFromPackageInfo(packageInfo!), + }) + : policyId + ? getHref('policy_details', { policyId }) + : '/'; }, [from, getHref, packageInfo, policyId]); useHistoryBlock(isEdited);