Skip to content

Commit

Permalink
fix policy preselect (#133711)
Browse files Browse the repository at this point in the history
(cherry picked from commit 6014b1e)
  • Loading branch information
juliaElastic committed Jun 7, 2022
1 parent 70ed6c7 commit b465c26
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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 '.';

Expand Down Expand Up @@ -48,6 +48,18 @@ export const SelectCreateAgentPolicy: React.FC<Props> = ({
);
}, [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) {
Expand Down

0 comments on commit b465c26

Please sign in to comment.