From 18e84c98224f46668ca3e082e39d06bc0dcd4ce5 Mon Sep 17 00:00:00 2001 From: Fabio Valente <8777512+fabiojvalente@users.noreply.github.com> Date: Wed, 19 Feb 2025 15:18:45 +0000 Subject: [PATCH 1/2] fix(MyGroupsSidebarItem): Return spec.profile field on getEntities Signed-off-by: Fabio Valente <8777512+fabiojvalente@users.noreply.github.com> --- .changeset/shaggy-stingrays-check.md | 5 +++++ .../MyGroupsSidebarItem/MyGroupsSidebarItem.test.tsx | 4 ++-- .../components/MyGroupsSidebarItem/MyGroupsSidebarItem.tsx | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 .changeset/shaggy-stingrays-check.md 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 c870d58cc1..33a436b65c 100644 --- a/plugins/org/src/components/MyGroupsSidebarItem/MyGroupsSidebarItem.test.tsx +++ b/plugins/org/src/components/MyGroupsSidebarItem/MyGroupsSidebarItem.test.tsx @@ -256,7 +256,7 @@ describe('MyGroupsSidebarItem Test', () => { 'relations.hasMember': 'user:default/guest', }, ], - fields: ['metadata', 'kind'], + fields: ['metadata', 'kind', 'spec.profile'], }); }); }); @@ -301,7 +301,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 8292455115..21d3608f93 100644 --- a/plugins/org/src/components/MyGroupsSidebarItem/MyGroupsSidebarItem.tsx +++ b/plugins/org/src/components/MyGroupsSidebarItem/MyGroupsSidebarItem.tsx @@ -69,7 +69,7 @@ export const MyGroupsSidebarItem = (props: { ...(filter ?? {}), }, ], - fields: ['metadata', 'kind'], + fields: ['metadata', 'kind', 'spec.profile'], }); return response.items; }, []); From 14916902b991c206815c23d79fb148ebc07ea78f Mon Sep 17 00:00:00 2001 From: Fabio Valente <8777512+fabiojvalente@users.noreply.github.com> Date: Fri, 21 Feb 2025 14:06:51 +0000 Subject: [PATCH 2/2] fix(MyGroupsSidebarItem): Filter fields on test to mock api behaviour Signed-off-by: Fabio Valente <8777512+fabiojvalente@users.noreply.github.com> --- .../MyGroupsSidebarItem.test.tsx | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/plugins/org/src/components/MyGroupsSidebarItem/MyGroupsSidebarItem.test.tsx b/plugins/org/src/components/MyGroupsSidebarItem/MyGroupsSidebarItem.test.tsx index 33a436b65c..a1e4d71911 100644 --- a/plugins/org/src/components/MyGroupsSidebarItem/MyGroupsSidebarItem.test.tsx +++ b/plugins/org/src/components/MyGroupsSidebarItem/MyGroupsSidebarItem.test.tsx @@ -33,6 +33,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', () => { @@ -131,8 +132,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', @@ -173,8 +175,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(