From e6b552f8b1c4fec7700cf73b01c3de54c8a614a8 Mon Sep 17 00:00:00 2001
From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Date: Wed, 3 Jan 2024 08:01:43 -0500
Subject: [PATCH] [8.12] [Fleet] fix unhandled error in agent details when
components are missing (#174152) (#174156)
# Backport
This will backport the following commits from `main` to `8.12`:
- [[Fleet] fix unhandled error in agent details when components are
missing (#174152)](https://github.com/elastic/kibana/pull/174152)
### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)
Co-authored-by: Julia Bardi <90178898+juliaElastic@users.noreply.github.com>
---
.../agent_details_integration_inputs.test.tsx | 9 +++++++
.../agent_details_integration_inputs.tsx | 27 ++++++++++---------
2 files changed, 24 insertions(+), 12 deletions(-)
diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_details_page/components/agent_details/agent_details_integration_inputs.test.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_details_page/components/agent_details/agent_details_integration_inputs.test.tsx
index 59139a09a792f..22d571932c459 100644
--- a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_details_page/components/agent_details/agent_details_integration_inputs.test.tsx
+++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_details_page/components/agent_details/agent_details_integration_inputs.test.tsx
@@ -123,4 +123,13 @@ describe('AgentDetailsIntegrationInputs', () => {
component.queryByTestId('agentDetailsIntegrationsInputStatusHealthSuccess')
).not.toBeInTheDocument();
});
+
+ it('should not throw error when there is no components', () => {
+ agent.components = undefined;
+
+ const component = renderComponent();
+ userEvent.click(component.container.querySelector('#agentIntegrationsInputs')!);
+ userEvent.click(component.container.querySelector('#endpoint')!);
+ expect(component.getByText('Endpoint')).toBeInTheDocument();
+ });
});
diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_details_page/components/agent_details/agent_details_integration_inputs.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_details_page/components/agent_details/agent_details_integration_inputs.tsx
index bb3b6ee5ef701..71b1a1ad6fe3e 100644
--- a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_details_page/components/agent_details/agent_details_integration_inputs.tsx
+++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_details_page/components/agent_details/agent_details_integration_inputs.tsx
@@ -128,6 +128,7 @@ export const AgentDetailsIntegrationInputs: React.FunctionComponent<{
current
) => {
if (current.enabled) {
+ const inputStatusFormatter = inputStatusMap.get(current.type);
return [
...acc,
{
@@ -156,18 +157,20 @@ export const AgentDetailsIntegrationInputs: React.FunctionComponent<{
),
id: current.type,
icon: getInputStatusIcon(current.type),
- children: [
- {
- label: (
-
- ),
- id: `input-status-${current.type}`,
- isExpanded: true,
- className: 'input-action-item-expanded',
- },
- ],
+ children: !!inputStatusFormatter
+ ? [
+ {
+ label: (
+
+ ),
+ id: `input-status-${current.type}`,
+ isExpanded: true,
+ className: 'input-action-item-expanded',
+ },
+ ]
+ : [],
},
];
}