[Fleet] Fix UI error when agent goes to orphaned state (#207746)

## Summary

Closes https://github.com/elastic/kibana/issues/207017

It seems that when the orphaned agent service is restarted, it briefly
has a component state string, instead of array, that's why the error.
The fix checks that the components is an array before calling map.

To verify:
1. Enroll an agent to an agent policy with endpoint integration.
2. Stop agent service so that agent gets into orphaned state.
3. Now restart the service and observe that the error
`_hit$_source4.components.map is not a function` no longer appears.

<img width="1531" alt="image"
src="https://github.com/user-attachments/assets/c9a957d7-a0d3-4831-90f9-a57479193ee0"
/>
<img width="1530" alt="image"
src="https://github.com/user-attachments/assets/c0aa62f0-708b-463e-9184-01d8641c8f21"
/>
This commit is contained in:
Julia Bardi 2025-01-22 15:20:03 +01:00 committed by GitHub
parent 24bab86aef
commit 9800147681
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -41,7 +41,7 @@ export function searchHitToAgent(
return acc;
}, {} as OutputMap)
: undefined;
const components: FleetServerAgentComponent[] | undefined = hit._source?.components
const components: FleetServerAgentComponent[] | undefined = Array.isArray(hit._source?.components)
? hit._source?.components.map((component) => ({
id: component.id,
type: component.type,