[Fleet] Fix add fleet server flow from agent policy page (#149507)

This commit is contained in:
Nicolas Chaulet 2023-01-26 11:55:36 -04:00 committed by GitHub
parent 1d5e25ae27
commit da83d96ff6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -42,7 +42,8 @@ export const Instructions = (props: InstructionProps) => {
refreshAgentPolicies,
} = props;
const fleetStatus = useFleetStatus();
const { isUnhealthy: isFleetServerUnhealthy } = useFleetServerUnhealthy();
const { isUnhealthy: isFleetServerUnhealthy, isLoading: isLoadingFleetServerHealth } =
useFleetServerUnhealthy();
useEffect(() => {
refreshAgentPolicies();
@ -66,14 +67,17 @@ export const Instructions = (props: InstructionProps) => {
const fleetServers = agents?.items || [];
if (isLoadingAgents || isLoadingAgentPolicies) return <Loading size="l" />;
if (isLoadingAgents || isLoadingAgentPolicies || isLoadingFleetServerHealth)
return <Loading size="l" />;
const hasNoFleetServerHost = fleetStatus.isReady && (fleetServerHosts?.length ?? 0) === 0;
const showAgentEnrollment =
fleetStatus.isReady &&
(isFleetServerPolicySelected ||
(!isFleetServerUnhealthy && fleetServers.length > 0 && (fleetServerHosts?.length ?? 0) > 0));
isFleetServerPolicySelected ||
(fleetStatus.isReady &&
!isFleetServerUnhealthy &&
fleetServers.length > 0 &&
(fleetServerHosts?.length ?? 0) > 0);
const showFleetServerEnrollment =
!isFleetServerPolicySelected &&