diff --git a/.changeset/shaggy-stingrays-check.md b/.changeset/shaggy-stingrays-check.md new file mode 100644 index 0000000000..74e0013224 --- /dev/null +++ b/.changeset/shaggy-stingrays-check.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-org': patch +--- + +Fixed missing spec.profile field on MyGroupsSidebarItem.tsx so the group spec.profile.displayName is shown on the sidebar" diff --git a/plugins/org/src/components/MyGroupsSidebarItem/MyGroupsSidebarItem.test.tsx b/plugins/org/src/components/MyGroupsSidebarItem/MyGroupsSidebarItem.test.tsx index 88b8d675fa..ae60415b1c 100644 --- a/plugins/org/src/components/MyGroupsSidebarItem/MyGroupsSidebarItem.test.tsx +++ b/plugins/org/src/components/MyGroupsSidebarItem/MyGroupsSidebarItem.test.tsx @@ -32,6 +32,7 @@ import { catalogApiMock } from '@backstage/plugin-catalog-react/testUtils'; import { DefaultEntityPresentationApi } from '@backstage/plugin-catalog'; import userEvent from '@testing-library/user-event'; import { screen } from '@testing-library/react'; +import { GetEntitiesRequest } from '@backstage/catalog-client'; describe('MyGroupsSidebarItem Test', () => { describe('For guests or users with no groups', () => { @@ -130,8 +131,9 @@ describe('MyGroupsSidebarItem Test', () => { ownershipEntityRefs: ['user:default/nigel.manning'], }); const catalogApi = catalogApiMock.mock({ - getEntities: async () => ({ - items: [ + getEntities: async (request: GetEntitiesRequest = {}) => { + const { fields } = request; + const fullItems = [ { apiVersion: 'backstage.io/v1alpha1', kind: 'Group', @@ -172,8 +174,28 @@ describe('MyGroupsSidebarItem Test', () => { }, }, }, - ] as Entity[], - }), + ] as Entity[]; + + // Filter requested fields + const filteredItems = fullItems.map(item => { + const filtered: Record = { apiVersion: item.apiVersion }; + (fields || []).forEach((field: string) => { + if (field.includes('.')) { + // Handle nested fields like 'spec.profile' + const [parent, child] = field.split('.'); + if (!filtered[parent]) filtered[parent] = {}; + filtered[parent][child] = (item as Record)[parent]?.[ + child + ]; + } else { + filtered[field] = item[field as keyof Entity]; + } + }); + return filtered as Entity; + }); + + return { items: filteredItems }; + }, }); await renderInTestApp( @@ -255,7 +277,7 @@ describe('MyGroupsSidebarItem Test', () => { 'relations.hasMember': 'user:default/guest', }, ], - fields: ['metadata', 'kind'], + fields: ['metadata', 'kind', 'spec.profile'], }); }); }); @@ -300,7 +322,7 @@ describe('MyGroupsSidebarItem Test', () => { 'spec.type': 'team', }, ], - fields: ['metadata', 'kind'], + fields: ['metadata', 'kind', 'spec.profile'], }); }); }); diff --git a/plugins/org/src/components/MyGroupsSidebarItem/MyGroupsSidebarItem.tsx b/plugins/org/src/components/MyGroupsSidebarItem/MyGroupsSidebarItem.tsx index 358d46d9a5..b63bf2c5f2 100644 --- a/plugins/org/src/components/MyGroupsSidebarItem/MyGroupsSidebarItem.tsx +++ b/plugins/org/src/components/MyGroupsSidebarItem/MyGroupsSidebarItem.tsx @@ -66,7 +66,7 @@ export const MyGroupsSidebarItem = (props: { ...(filter ?? {}), }, ], - fields: ['metadata', 'kind'], + fields: ['metadata', 'kind', 'spec.profile'], }); return response.items; }, []);