diff --git a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/agent_policy_select_create.tsx b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/agent_policy_select_create.tsx index 304239ac77dad7..4dab3b054bc8dd 100644 --- a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/agent_policy_select_create.tsx +++ b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/agent_policy_select_create.tsx @@ -14,7 +14,7 @@ import { } from '../../applications/fleet/sections/agents/components'; import { AgentPolicyCreateInlineForm } from '../../applications/fleet/sections/agent_policy/components'; import type { AgentPolicy } from '../../types'; -import { incrementPolicyName } from '../../services'; +import { incrementPolicyName, policyHasFleetServer } from '../../services'; import { AgentPolicySelection } from '.'; @@ -48,6 +48,18 @@ export const SelectCreateAgentPolicy: React.FC = ({ ); }, [agentPolicies, excludeFleetServer]); + useEffect(() => { + // Select default value if policy has no fleet server + if ( + regularAgentPolicies.length === 1 && + !selectedPolicyId && + excludeFleetServer !== false && + !policyHasFleetServer(regularAgentPolicies[0]) + ) { + setSelectedPolicyId(regularAgentPolicies[0].id); + } + }, [regularAgentPolicies, selectedPolicyId, setSelectedPolicyId, excludeFleetServer]); + const onAgentPolicyChange = useCallback( async (key?: string, policy?: AgentPolicy) => { if (policy) {