Skip to content

Commit 315e5c6

Browse files
authored
fix: display role.name coming from the metadata (#10)
1 parent 2259a45 commit 315e5c6

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
@@ -23,12 +23,12 @@ describe('TeamTable', () => {
2323
const mockTeamMembers = [
2424
{
2525
26-
roles: ['Admin', 'Editor'],
26+
roles: ['admin', 'editor'],
2727
username: 'alice',
2828
},
2929
{
3030
31-
roles: ['Viewer'],
31+
roles: ['viewer'],
3232
username: 'bob',
3333
},
3434
];
@@ -37,6 +37,38 @@ describe('TeamTable', () => {
3737
libraryId: 'lib:123',
3838
canManageTeam: true,
3939
username: 'alice',
40+
roles: [
41+
{
42+
role: 'admin',
43+
permissions: [
44+
'delete_library',
45+
'publish_library',
46+
'manage_library_team',
47+
],
48+
userCount: 3,
49+
name: 'Admin',
50+
description: 'The Admin role',
51+
},
52+
{
53+
role: 'editor',
54+
permissions: [
55+
'edit_library',
56+
'publish_library',
57+
],
58+
userCount: 3,
59+
name: 'Editor',
60+
description: 'The Editor role',
61+
},
62+
{
63+
role: 'viewer',
64+
permissions: [
65+
'view_library',
66+
],
67+
userCount: 3,
68+
name: 'Viewer',
69+
description: 'The Viewer role',
70+
},
71+
],
4072
};
4173

4274
beforeEach(() => {

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

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

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

0 commit comments

Comments
 (0)