diff --git a/plugins/catalog-react/src/components/EntityRefLink/FetchedEntityRefLinks.test.tsx b/plugins/catalog-react/src/components/EntityRefLink/FetchedEntityRefLinks.test.tsx index c416adcfbd..36e2c0450d 100644 --- a/plugins/catalog-react/src/components/EntityRefLink/FetchedEntityRefLinks.test.tsx +++ b/plugins/catalog-react/src/components/EntityRefLink/FetchedEntityRefLinks.test.tsx @@ -132,4 +132,87 @@ describe('', () => { '/catalog/default/api/implementation', ); }); + + it('should handle heterogeneous array of values to render the custom display text', async () => { + const entityRefs = [ + ...[ + { + kind: 'Component', + namespace: 'default', + name: 'tool', + }, + { + kind: 'API', + namespace: 'default', + name: 'implementation', + }, + ].map(ref => ({ + apiVersion: 'backstage.io/v1alpha1', + kind: ref.kind, + metadata: { + name: ref.name, + namespace: ref.namespace, + }, + spec: { + profile: { + displayName: ref.name.toLocaleUpperCase('en-US'), + }, + type: 'organization', + }, + })), + { + kind: 'Component', + namespace: 'default', + name: 'interface', + }, + ]; + + const catalogApi: Partial = { + getEntities: () => + Promise.resolve({ + items: [ + { + apiVersion: 'backstage.io/v1alpha1', + kind: 'Component', + metadata: { + name: 'interface', + namespace: 'default', + }, + spec: { + profile: { + displayName: 'INTERFACE', + }, + type: 'organization', + }, + }, + ], + }), + }; + + const rendered = await renderInTestApp( + + + , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name/*': entityRouteRef, + }, + }, + ); + + expect(rendered.getByText('TOOL')).toHaveAttribute( + 'href', + '/catalog/default/component/tool', + ); + + expect(rendered.getByText('IMPLEMENTATION')).toHaveAttribute( + 'href', + '/catalog/default/api/implementation', + ); + + expect(rendered.getByText('INTERFACE')).toHaveAttribute( + 'href', + '/catalog/default/component/interface', + ); + }); }); diff --git a/plugins/catalog-react/src/components/EntityRefLink/FetchedEntityRefLinks.tsx b/plugins/catalog-react/src/components/EntityRefLink/FetchedEntityRefLinks.tsx index 88b92b4689..ea4a32b511 100644 --- a/plugins/catalog-react/src/components/EntityRefLink/FetchedEntityRefLinks.tsx +++ b/plugins/catalog-react/src/components/EntityRefLink/FetchedEntityRefLinks.tsx @@ -60,17 +60,24 @@ export function FetchedEntityRefLinks< return 'metadata' in current ? acc : [...acc, parseEntityRef(current)]; }, new Array()); + const pureEntities = entityRefs.filter( + ref => 'metadata' in ref, + ) as Array; + return refs.length > 0 - ? ( - await catalogApi.getEntities({ - filter: refs.map(ref => ({ - kind: ref.kind, - 'metadata.namespace': ref.namespace, - 'metadata.name': ref.name, - })), - }) - ).items - : (entityRefs as Array); + ? [ + ...( + await catalogApi.getEntities({ + filter: refs.map(ref => ({ + kind: ref.kind, + 'metadata.namespace': ref.namespace, + 'metadata.name': ref.name, + })), + }) + ).items, + ...pureEntities, + ] + : pureEntities; }, [entityRefs]); if (loading) {