Merge pull request #28918 from fabiojvalente/feature/add-spec-field-to-mygroups-sidebar
fix(MyGroupsSidebarItem): Return spec.profile field on getEntities
This commit is contained in:
@@ -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"
|
||||
@@ -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<string, any> = { 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<string, any>)[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'],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -66,7 +66,7 @@ export const MyGroupsSidebarItem = (props: {
|
||||
...(filter ?? {}),
|
||||
},
|
||||
],
|
||||
fields: ['metadata', 'kind'],
|
||||
fields: ['metadata', 'kind', 'spec.profile'],
|
||||
});
|
||||
return response.items;
|
||||
}, []);
|
||||
|
||||
Reference in New Issue
Block a user