diff --git a/.changeset/cold-bees-jam.md b/.changeset/cold-bees-jam.md new file mode 100644 index 0000000000..3c6e652d2b --- /dev/null +++ b/.changeset/cold-bees-jam.md @@ -0,0 +1,6 @@ +--- +'@backstage/plugin-org': patch +--- + +Fixed the display of OwnershipCard with aggregated relations by loading relations when getting children of entity. +This allows the already existing recursive method to work properly when children of entity have children themselves. diff --git a/plugins/org/src/components/Cards/OwnershipCard/useGetEntities.test.ts b/plugins/org/src/components/Cards/OwnershipCard/useGetEntities.test.ts index 191bd10284..4b9389a7d4 100644 --- a/plugins/org/src/components/Cards/OwnershipCard/useGetEntities.test.ts +++ b/plugins/org/src/components/Cards/OwnershipCard/useGetEntities.test.ts @@ -110,6 +110,14 @@ describe('useGetEntities', () => { ); }); + it('given group entity should retrieve child with their relations', async () => { + await whenHookIsCalledWith(givenParentGroupEntity); + expect(catalogApiMock.getEntitiesByRefs).toHaveBeenCalledWith({ + entityRefs: [`group:default/${givenLeafGroup}`], + fields: ['kind', 'metadata.namespace', 'metadata.name', 'relations'], + }); + }); + it('given user entity should aggregate parent ownership and direct', async () => { await whenHookIsCalledWith(givenUserEntity); expect(catalogApiMock.getEntities).toHaveBeenCalledWith( diff --git a/plugins/org/src/components/Cards/OwnershipCard/useGetEntities.ts b/plugins/org/src/components/Cards/OwnershipCard/useGetEntities.ts index 1ff01cd8e1..337e926971 100644 --- a/plugins/org/src/components/Cards/OwnershipCard/useGetEntities.ts +++ b/plugins/org/src/components/Cards/OwnershipCard/useGetEntities.ts @@ -90,7 +90,7 @@ const getChildOwnershipEntityRefs = async ( if (hasChildGroups) { const entityRefs = childGroups.map(r => stringifyEntityRef(r)); const childGroupResponse = await catalogApi.getEntitiesByRefs({ - fields: ['kind', 'metadata.namespace', 'metadata.name'], + fields: ['kind', 'metadata.namespace', 'metadata.name', 'relations'], entityRefs, }); const childGroupEntities = childGroupResponse.items.filter(isEntity);