From d9bf8a556844789270a098c67c46765fe43933d4 Mon Sep 17 00:00:00 2001 From: Julia Bardi Date: Thu, 13 Mar 2025 13:26:13 +0100 Subject: [PATCH 1/3] fix UI bug displaying default agent binary source --- .../components/agent_policy_advanced_fields/hooks.tsx | 9 ++++++--- .../components/agent_policy_advanced_fields/index.tsx | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) 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..92da72442a5c5 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 @@ -16,7 +16,10 @@ import { useGetDownloadSources, useGetFleetServerHosts, } from '../../../../hooks'; -import { LICENCE_FOR_PER_POLICY_OUTPUT } from '../../../../../../../common/constants'; +import { + DEFAULT_DOWNLOAD_SOURCE_ID, + LICENCE_FOR_PER_POLICY_OUTPUT, +} from '../../../../../../../common/constants'; import { getAllowedOutputTypesForAgentPolicy, policyHasFleetServer, @@ -156,7 +159,7 @@ export function useOutputOptions(agentPolicy: Partial) { +export function useDownloadSourcesOptions() { const downloadSourcesRequest = useGetDownloadSources(); const dataDownloadSourceOptions = useMemo(() => { @@ -202,7 +205,7 @@ function getDefaultDownloadSource( }), defaultDownloadSourceDisabledMessage ), - value: DEFAULT_SELECT_VALUE, + value: DEFAULT_DOWNLOAD_SOURCE_ID, disabled: defaultDownloadSourceDisabled, }; } 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 8d0278e277069..d586c93e40a47 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 @@ -112,7 +112,7 @@ export const AgentPolicyAdvancedOptionsContent: React.FunctionComponent = maxAgentPoliciesWithInactivityTimeout !== undefined && totalAgentPoliciesWithInactivityTimeout > (maxAgentPoliciesWithInactivityTimeout ?? 0); const { dataDownloadSourceOptions, isLoading: isLoadingDownloadSources } = - useDownloadSourcesOptions(agentPolicy); + useDownloadSourcesOptions(); const { fleetServerHostsOptions, isLoading: isLoadingFleetServerHostsOption } = useFleetServerHostsOptions(agentPolicy); From 5bc7f4028e676d7dc46d3c50d23a6ead1f42bdef Mon Sep 17 00:00:00 2001 From: Julia Bardi Date: Thu, 13 Mar 2025 14:44:38 +0100 Subject: [PATCH 2/3] address review comments --- .../agent_policy_advanced_fields/hooks.tsx | 39 ++++++++----------- 1 file changed, 16 insertions(+), 23 deletions(-) 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 92da72442a5c5..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 @@ -16,10 +16,7 @@ import { useGetDownloadSources, useGetFleetServerHosts, } from '../../../../hooks'; -import { - DEFAULT_DOWNLOAD_SOURCE_ID, - LICENCE_FOR_PER_POLICY_OUTPUT, -} from '../../../../../../../common/constants'; +import { LICENCE_FOR_PER_POLICY_OUTPUT } from '../../../../../../../common/constants'; import { getAllowedOutputTypesForAgentPolicy, policyHasFleetServer, @@ -172,14 +169,12 @@ export function useDownloadSourcesOptions() { return [ getDefaultDownloadSource(defaultDownloadSourceName), - ...downloadSourcesRequest.data.items - .filter((item) => !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]); @@ -205,7 +200,7 @@ function getDefaultDownloadSource( }), defaultDownloadSourceDisabledMessage ), - value: DEFAULT_DOWNLOAD_SOURCE_ID, + value: DEFAULT_SELECT_VALUE, disabled: defaultDownloadSourceDisabled, }; } @@ -225,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]); From 3011c04e6f5c27cb405a8c1514aa73a0bfc85eec Mon Sep 17 00:00:00 2001 From: Julia Bardi Date: Thu, 13 Mar 2025 16:20:33 +0100 Subject: [PATCH 3/3] fix test --- .../components/agent_policy_advanced_fields/hooks.test.tsx | 5 +++++ 1 file changed, 5 insertions(+) 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",