Add ability to specify a different relationship name for MembersListCard
The default relationship remains `memberOf` but could be overridden to specify (for instance) `leaderOf` if you wanted to have multiple MembersListCard components on a `Group` page (one for "Members" and another for "Leaders") Signed-off-by: Brian Phillips <28457+brianphillips@users.noreply.github.com>
This commit is contained in:
@@ -99,6 +99,7 @@ describe('MemberTab Test', () => {
|
||||
] as Entity[],
|
||||
}),
|
||||
};
|
||||
const getEntitiesSpy = jest.spyOn(catalogApi, 'getEntities');
|
||||
|
||||
it('Display Profile Card', async () => {
|
||||
await renderInTestApp(
|
||||
@@ -115,6 +116,12 @@ describe('MemberTab Test', () => {
|
||||
},
|
||||
},
|
||||
);
|
||||
expect(getEntitiesSpy).toHaveBeenCalledWith({
|
||||
filter: {
|
||||
kind: 'User',
|
||||
'relations.memberOf': ['group:default/team-d'],
|
||||
},
|
||||
});
|
||||
|
||||
expect(screen.getByAltText('Tara MacGovern')).toHaveAttribute(
|
||||
'src',
|
||||
@@ -149,6 +156,29 @@ describe('MemberTab Test', () => {
|
||||
expect(screen.getByText('Testers (1)')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('Can query a different relationship', async () => {
|
||||
await renderInTestApp(
|
||||
<TestApiProvider apis={[[catalogApiRef, catalogApi]]}>
|
||||
<EntityProvider entity={groupEntity}>
|
||||
<MembersListCard relationship="leaderOf" />
|
||||
</EntityProvider>
|
||||
</TestApiProvider>,
|
||||
{
|
||||
mountedRoutes: {
|
||||
'/catalog/:namespace/:kind/:name': entityRouteRef,
|
||||
'/catalog': rootRouteRef,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
expect(getEntitiesSpy).toHaveBeenCalledWith({
|
||||
filter: {
|
||||
kind: 'User',
|
||||
'relations.leaderOf': ['group:default/team-d'],
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
describe('Aggregate members toggle', () => {
|
||||
it('Does not show the aggregate members toggle if the showAggregateMembersToggle prop is undefined', async () => {
|
||||
await renderInTestApp(
|
||||
|
||||
@@ -138,12 +138,14 @@ export const MembersListCard = (props: {
|
||||
memberDisplayTitle?: string;
|
||||
pageSize?: number;
|
||||
showAggregateMembersToggle?: boolean;
|
||||
relationship?: string;
|
||||
relationsType?: EntityRelationAggregation;
|
||||
}) => {
|
||||
const {
|
||||
memberDisplayTitle = 'Members',
|
||||
pageSize = 50,
|
||||
showAggregateMembersToggle,
|
||||
relationship = 'memberOf',
|
||||
relationsType = 'direct',
|
||||
} = props;
|
||||
const classes = useListStyles();
|
||||
@@ -187,7 +189,7 @@ export const MembersListCard = (props: {
|
||||
const membersList = await catalogApi.getEntities({
|
||||
filter: {
|
||||
kind: 'User',
|
||||
'relations.memberof': [
|
||||
[`relations.${relationship}`]: [
|
||||
stringifyEntityRef({
|
||||
kind: 'group',
|
||||
namespace: groupNamespace.toLocaleLowerCase('en-US'),
|
||||
|
||||
Reference in New Issue
Block a user