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

# Backport

This will backport the following commits from `main` to `8.6`:
- [[Fleet] Fix add fleet server flow from agent policy page
(#149507)](https://github.com/elastic/kibana/pull/149507)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Nicolas
Chaulet","email":"nicolas.chaulet@elastic.co"},"sourceCommit":{"committedDate":"2023-01-26T15:55:36Z","message":"[Fleet]
Fix add fleet server flow from agent policy page
(#149507)","sha":"da83d96ff65a3ad5f56d350576e6c4811e5f26af","branchLabelMapping":{"^v8.7.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:Fleet","v8.7.0","v8.6.1"],"number":149507,"url":"https://github.com/elastic/kibana/pull/149507","mergeCommit":{"message":"[Fleet]
Fix add fleet server flow from agent policy page
(#149507)","sha":"da83d96ff65a3ad5f56d350576e6c4811e5f26af"}},"sourceBranch":"main","suggestedTargetBranches":["8.6"],"targetPullRequestStates":[{"branch":"main","label":"v8.7.0","labelRegex":"^v8.7.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/149507","number":149507,"mergeCommit":{"message":"[Fleet]
Fix add fleet server flow from agent policy page
(#149507)","sha":"da83d96ff65a3ad5f56d350576e6c4811e5f26af"}},{"branch":"8.6","label":"v8.6.1","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Nicolas Chaulet <nicolas.chaulet@elastic.co>
This commit is contained in:
Kibana Machine 2023-01-26 11:59:12 -05:00 committed by GitHub
parent a37bf49288
commit b744988d28
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 &&