diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/single_page_layout/hooks/setup_technology.test.ts b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/single_page_layout/hooks/setup_technology.test.ts index be7884aad753d..550a288dad371 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/single_page_layout/hooks/setup_technology.test.ts +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/single_page_layout/hooks/setup_technology.test.ts @@ -143,6 +143,7 @@ describe('useSetupTechnology', () => { namespace: 'default', is_managed: false, supports_agentless: false, + inactivity_timeout: 3600, }; const packagePolicyMock = createPackagePolicyMock(); @@ -169,6 +170,7 @@ describe('useSetupTechnology', () => { (generateNewAgentPolicyWithDefaults as MockFn).mockReturnValue({ name: 'Agentless policy for endpoint-1', supports_agentless: true, + inactivity_timeout: 3600, }); jest.clearAllMocks(); }); @@ -266,12 +268,14 @@ describe('useSetupTechnology', () => { act(() => { result.current.handleSetupTechnologyChange(SetupTechnology.AGENTLESS); }); + waitForNextUpdate(); expect(result.current.selectedSetupTechnology).toBe(SetupTechnology.AGENTLESS); expect(setNewAgentPolicy).toHaveBeenCalledWith({ name: 'Agentless policy for endpoint-1', supports_agentless: true, + inactivity_timeout: 3600, }); }); @@ -307,6 +311,7 @@ describe('useSetupTechnology', () => { expect(result.current.selectedSetupTechnology).toBe(SetupTechnology.AGENTLESS); expect(setNewAgentPolicy).toHaveBeenCalledWith({ + inactivity_timeout: 3600, name: 'Agentless policy for endpoint-1', supports_agentless: true, }); @@ -325,6 +330,7 @@ describe('useSetupTechnology', () => { waitFor(() => { expect(setNewAgentPolicy).toHaveBeenCalledWith({ name: 'Agentless policy for endpoint-2', + inactivity_timeout: 3600, supports_agentless: true, }); }); @@ -505,6 +511,7 @@ describe('useSetupTechnology', () => { expect(setNewAgentPolicy).toHaveBeenCalledWith({ name: 'Agentless policy for endpoint-1', supports_agentless: true, + inactivity_timeout: 3600, }); }); diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/single_page_layout/hooks/setup_technology.ts b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/single_page_layout/hooks/setup_technology.ts index fb6aefcf7583e..95b4aa80a02bb 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/single_page_layout/hooks/setup_technology.ts +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/single_page_layout/hooks/setup_technology.ts @@ -99,12 +99,14 @@ export function useSetupTechnology({ const [selectedSetupTechnology, setSelectedSetupTechnology] = useState( SetupTechnology.AGENT_BASED ); - const [newAgentlessPolicy, setNewAgentlessPolicy] = useState( - generateNewAgentPolicyWithDefaults({ + const [newAgentlessPolicy, setNewAgentlessPolicy] = useState(() => { + const agentless = generateNewAgentPolicyWithDefaults({ + inactivity_timeout: 3600, supports_agentless: true, monitoring_enabled: ['logs', 'metrics'], - }) - ); + }); + return agentless; + }); useEffect(() => { if (isEditPage && agentPolicies && agentPolicies.some((policy) => policy.supports_agentless)) { @@ -116,7 +118,7 @@ export function useSetupTechnology({ ...newAgentlessPolicy, name: getAgentlessAgentPolicyNameFromPackagePolicyName(packagePolicy.name), }; - if (nextNewAgentlessPolicy.name !== newAgentlessPolicy.name) { + if (!newAgentlessPolicy.name || nextNewAgentlessPolicy.name !== newAgentlessPolicy.name) { setNewAgentlessPolicy(nextNewAgentlessPolicy); setNewAgentPolicy(nextNewAgentlessPolicy as NewAgentPolicy); updateAgentPolicies([nextNewAgentlessPolicy] as AgentPolicy[]);