diff --git a/x-pack/plugins/cloud_security_posture/public/components/fleet_extensions/policy_template_form.tsx b/x-pack/plugins/cloud_security_posture/public/components/fleet_extensions/policy_template_form.tsx index c205ef7f825258..ae1a1cb755afc9 100644 --- a/x-pack/plugins/cloud_security_posture/public/components/fleet_extensions/policy_template_form.tsx +++ b/x-pack/plugins/cloud_security_posture/public/components/fleet_extensions/policy_template_form.tsx @@ -549,7 +549,7 @@ export const CspPolicyTemplateForm = memo )} diff --git a/x-pack/plugins/cloud_security_posture/public/components/fleet_extensions/setup_technology_selector/use_setup_technology.ts b/x-pack/plugins/cloud_security_posture/public/components/fleet_extensions/setup_technology_selector/use_setup_technology.ts index 1eb3334d09103f..eb18a90b72936d 100644 --- a/x-pack/plugins/cloud_security_posture/public/components/fleet_extensions/setup_technology_selector/use_setup_technology.ts +++ b/x-pack/plugins/cloud_security_posture/public/components/fleet_extensions/setup_technology_selector/use_setup_technology.ts @@ -38,8 +38,15 @@ export const useSetupTechnology = ({ return SetupTechnology.AGENT_BASED; }); + const [isDirty, setIsDirty] = useState(false); + + const updateSetupTechnology = (value: SetupTechnology) => { + setSetupTechnology(value); + setIsDirty(true); + }; + useEffect(() => { - if (isEditPage) { + if (isEditPage || isDirty) { return; } @@ -58,7 +65,7 @@ export const useSetupTechnology = ({ } else { setSetupTechnology(SetupTechnology.AGENT_BASED); } - }, [agentPolicyId, agentlessPolicyId, isAgentlessAvailable, isEditPage]); + }, [agentPolicyId, agentlessPolicyId, isAgentlessAvailable, isDirty, isEditPage]); useEffect(() => { if (isEditPage) { @@ -74,5 +81,6 @@ export const useSetupTechnology = ({ isAgentlessAvailable, setupTechnology, setSetupTechnology, + updateSetupTechnology, }; }; diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/single_page_layout/hooks/setup_technology.ts b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/single_page_layout/hooks/setup_technology.ts index 7088bdd37f0439..2eab867e2ae121 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/single_page_layout/hooks/setup_technology.ts +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/single_page_layout/hooks/setup_technology.ts @@ -37,7 +37,7 @@ export function useSetupTechnology({ }: { updateNewAgentPolicy: (policy: NewAgentPolicy) => void; newAgentPolicy: NewAgentPolicy; - updateAgentPolicy: (policy: AgentPolicy) => void; + updateAgentPolicy: (policy: AgentPolicy | undefined) => void; setSelectedPolicyTab: (tab: SelectedPolicyTab) => void; }) { const { isAgentlessEnabled } = useAgentlessPolicy(); @@ -75,8 +75,8 @@ export function useSetupTechnology({ } else if (setupTechnology === SetupTechnology.AGENT_BASED) { updateNewAgentPolicy(newAgentPolicy); setSelectedPolicyTab(SelectedPolicyTab.NEW); + updateAgentPolicy(undefined); } - setSelectedSetupTechnology(setupTechnology); }, [ diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/single_page_layout/index.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/single_page_layout/index.tsx index 6093f7b327b17d..572b7a4136ea54 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/single_page_layout/index.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/single_page_layout/index.tsx @@ -226,10 +226,15 @@ export const CreatePackagePolicySinglePage: CreatePackagePolicyParams = ({ } }; + if (selectedPolicyTab === SelectedPolicyTab.NEW) { + setAgentCount(0); + return; + } + if (isFleetEnabled && agentPolicyId) { getAgentCount(); } - }, [agentPolicyId, isFleetEnabled]); + }, [agentPolicyId, selectedPolicyTab, isFleetEnabled]); const handleExtensionViewOnChange = useCallback< PackagePolicyEditExtensionComponentProps['onChange']