fix policy preselect (#133711)

This commit is contained in:
Julia Bardi 2022-06-07 12:00:50 +02:00 committed by GitHub
parent 747b898efb
commit 6014b1ef74
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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<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) {