From 7dceebfad9a8aaed474bf2d5f3ea1339eb292041 Mon Sep 17 00:00:00 2001
From: Julia Bardi <90178898+juliaElastic@users.noreply.github.com>
Date: Thu, 13 Mar 2025 18:01:08 +0100
Subject: [PATCH] [Fleet] fix UI bug displaying default agent binary source
(#214360)
## Summary
Fix UI bug when an agent policy uses the default download source
explicitly. The Agent binary download UI select was empty.
To verify:
- create a new agent binary download source
- create an agent policy with using the default download source
- check on Agent policy details UI that the Agent binary download UI
select is populated correctly
```
POST kbn:/api/fleet/agent_policies
{
"name": "demo-policy-5",
"description": "",
"namespace": "default",
"monitoring_enabled": [
"logs",
"metrics",
"traces"
],
"inactivity_timeout": 1209600,
"is_protected": false,
"download_source_id": "fleet-default-download-source"
}
```
Before:

After:
(cherry picked from commit eb62a047bd06ebb70c6119bf3c19145df901fdda)
---
.../hooks.test.tsx | 5 +++
.../agent_policy_advanced_fields/hooks.tsx | 34 ++++++++-----------
.../agent_policy_advanced_fields/index.tsx | 2 +-
3 files changed, 21 insertions(+), 20 deletions(-)
diff --git a/x-pack/platform/plugins/shared/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_advanced_fields/hooks.test.tsx b/x-pack/platform/plugins/shared/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_advanced_fields/hooks.test.tsx
index 0f3f7356733dd..34ad71f2036d5 100644
--- a/x-pack/platform/plugins/shared/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_advanced_fields/hooks.test.tsx
+++ b/x-pack/platform/plugins/shared/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_advanced_fields/hooks.test.tsx
@@ -681,6 +681,11 @@ describe('useFleetServerHostsOptions', () => {
"inputDisplay": "Default (currently Default)",
"value": "@@##DEFAULT_SELECT##@@",
},
+ Object {
+ "disabled": false,
+ "inputDisplay": "Default",
+ "value": "default-host",
+ },
Object {
"disabled": true,
"inputDisplay": "Internal",
diff --git a/x-pack/platform/plugins/shared/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_advanced_fields/hooks.tsx b/x-pack/platform/plugins/shared/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_advanced_fields/hooks.tsx
index 68204e8c1ac60..5e851be571565 100644
--- a/x-pack/platform/plugins/shared/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_advanced_fields/hooks.tsx
+++ b/x-pack/platform/plugins/shared/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_advanced_fields/hooks.tsx
@@ -156,7 +156,7 @@ export function useOutputOptions(agentPolicy: Partial) {
+export function useDownloadSourcesOptions() {
const downloadSourcesRequest = useGetDownloadSources();
const dataDownloadSourceOptions = useMemo(() => {
@@ -169,14 +169,12 @@ export function useDownloadSourcesOptions(agentPolicy: Partial !item.is_default)
- .map((item) => {
- return {
- value: item.id,
- inputDisplay: item.name,
- };
- }),
+ ...downloadSourcesRequest.data.items.map((item) => {
+ return {
+ value: item.id,
+ inputDisplay: item.name,
+ };
+ }),
];
}, [downloadSourcesRequest]);
@@ -222,17 +220,15 @@ export function useFleetServerHostsOptions(agentPolicy: Partial !item.is_default)
- .map((item) => {
- const isInternalFleetServerHost = !!item.is_internal;
+ ...fleetServerHostsRequest.data.items.map((item) => {
+ const isInternalFleetServerHost = !!item.is_internal;
- return {
- value: item.id,
- inputDisplay: item.name,
- disabled: isInternalFleetServerHost,
- };
- }),
+ return {
+ value: item.id,
+ inputDisplay: item.name,
+ disabled: isInternalFleetServerHost,
+ };
+ }),
];
}, [fleetServerHostsRequest]);
diff --git a/x-pack/platform/plugins/shared/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_advanced_fields/index.tsx b/x-pack/platform/plugins/shared/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_advanced_fields/index.tsx
index 442cc453a2642..644394956dc3c 100644
--- a/x-pack/platform/plugins/shared/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_advanced_fields/index.tsx
+++ b/x-pack/platform/plugins/shared/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_advanced_fields/index.tsx
@@ -113,7 +113,7 @@ export const AgentPolicyAdvancedOptionsContent: React.FunctionComponent =
maxAgentPoliciesWithInactivityTimeout !== undefined &&
totalAgentPoliciesWithInactivityTimeout > (maxAgentPoliciesWithInactivityTimeout ?? 0);
const { dataDownloadSourceOptions, isLoading: isLoadingDownloadSources } =
- useDownloadSourcesOptions(agentPolicy);
+ useDownloadSourcesOptions();
const { fleetServerHostsOptions, isLoading: isLoadingFleetServerHostsOption } =
useFleetServerHostsOptions(agentPolicy);