Skip to content

Commit 56f51b4

Browse files
committed
fix: display role.name coming from the metadata
1 parent b1f3538 commit 56f51b4

2 files changed

Lines changed: 46 additions & 13 deletions

File tree

src/authz-module/libraries-manager/components/TeamTable.test.tsx

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ describe('TeamTable', () => {
2424
const mockTeamMembers = [
2525
{
2626
27-
roles: ['Admin', 'Editor'],
27+
roles: ['admin', 'editor'],
2828
username: 'alice',
2929
},
3030
{
3131
32-
roles: ['Viewer'],
32+
roles: ['viewer'],
3333
username: 'bob',
3434
},
3535
];
@@ -38,6 +38,38 @@ describe('TeamTable', () => {
3838
libraryId: 'lib:123',
3939
canManageTeam: true,
4040
username: 'alice',
41+
roles: [
42+
{
43+
role: 'admin',
44+
permissions: [
45+
'delete_library',
46+
'publish_library',
47+
'manage_library_team',
48+
],
49+
userCount: 3,
50+
name: 'Admin',
51+
description: 'The Admin role',
52+
},
53+
{
54+
role: 'editor',
55+
permissions: [
56+
'edit_library',
57+
'publish_library',
58+
],
59+
userCount: 3,
60+
name: 'Editor',
61+
description: 'The Editor role',
62+
},
63+
{
64+
role: 'viewer',
65+
permissions: [
66+
'view_library',
67+
],
68+
userCount: 3,
69+
name: 'Viewer',
70+
description: 'The Viewer role',
71+
},
72+
],
4173
};
4274

4375
beforeEach(() => {

src/authz-module/libraries-manager/components/TeamTable.tsx

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,12 @@ const NameCell = ({ row }: CellProps) => {
4444
return row.original.username;
4545
};
4646

47-
const RolesCell = ({ row }: CellProps) => (row.original.username === SKELETON_ROWS[0].username ? (
48-
<Skeleton width="80px" />
49-
) : (
50-
row.original.roles.map((role) => (
51-
<Chip key={`${row.original.username}-role-${role}`}>{role}</Chip>
52-
))
53-
));
54-
5547
const TeamTable = () => {
5648
const intl = useIntl();
57-
const { libraryId, canManageTeam, username } = useLibraryAuthZ();
58-
49+
const {
50+
libraryId, canManageTeam, username, roles,
51+
} = useLibraryAuthZ();
52+
const roleLabels = roles.reduce((acc, role) => ({ ...acc, [role.role]: role.name }), {} as Record<string, string>);
5953
// TODO: Display error in the notification system
6054
const {
6155
data: teamMembers, isLoading, isError,
@@ -107,7 +101,14 @@ const TeamTable = () => {
107101
{
108102
Header: intl.formatMessage(messages['library.authz.team.table.roles']),
109103
accessor: 'roles',
110-
Cell: RolesCell,
104+
// eslint-disable-next-line react/no-unstable-nested-components
105+
Cell: ({ row }: CellProps) => (row.original.username === SKELETON_ROWS[0].username ? (
106+
<Skeleton width="80px" />
107+
) : (
108+
row.original.roles.map((role) => (
109+
<Chip key={`${row.original.username}-role-${role}`}>{roleLabels[role]}</Chip>
110+
))
111+
)),
111112
},
112113
]
113114
}

0 commit comments

Comments
 (0)