From 16515dffc85c79891df39162ed5b20fc506d12ad Mon Sep 17 00:00:00 2001 From: Diana Olarte Date: Mon, 13 Oct 2025 13:43:23 +1100 Subject: [PATCH] fix: display role.name coming from the metadata --- .../components/TeamTable.test.tsx | 36 +++++++++++++++++-- .../components/TeamTable.tsx | 23 ++++++------ 2 files changed, 46 insertions(+), 13 deletions(-) diff --git a/src/authz-module/libraries-manager/components/TeamTable.test.tsx b/src/authz-module/libraries-manager/components/TeamTable.test.tsx index a802e22..2e68b0f 100644 --- a/src/authz-module/libraries-manager/components/TeamTable.test.tsx +++ b/src/authz-module/libraries-manager/components/TeamTable.test.tsx @@ -24,12 +24,12 @@ describe('TeamTable', () => { const mockTeamMembers = [ { email: 'alice@example.com', - roles: ['Admin', 'Editor'], + roles: ['admin', 'editor'], username: 'alice', }, { email: 'bob@example.com', - roles: ['Viewer'], + roles: ['viewer'], username: 'bob', }, ]; @@ -38,6 +38,38 @@ describe('TeamTable', () => { libraryId: 'lib:123', canManageTeam: true, username: 'alice', + roles: [ + { + role: 'admin', + permissions: [ + 'delete_library', + 'publish_library', + 'manage_library_team', + ], + userCount: 3, + name: 'Admin', + description: 'The Admin role', + }, + { + role: 'editor', + permissions: [ + 'edit_library', + 'publish_library', + ], + userCount: 3, + name: 'Editor', + description: 'The Editor role', + }, + { + role: 'viewer', + permissions: [ + 'view_library', + ], + userCount: 3, + name: 'Viewer', + description: 'The Viewer role', + }, + ], }; beforeEach(() => { diff --git a/src/authz-module/libraries-manager/components/TeamTable.tsx b/src/authz-module/libraries-manager/components/TeamTable.tsx index cca1d3c..5cb144c 100644 --- a/src/authz-module/libraries-manager/components/TeamTable.tsx +++ b/src/authz-module/libraries-manager/components/TeamTable.tsx @@ -44,18 +44,12 @@ const NameCell = ({ row }: CellProps) => { return row.original.username; }; -const RolesCell = ({ row }: CellProps) => (row.original.username === SKELETON_ROWS[0].username ? ( - -) : ( - row.original.roles.map((role) => ( - {role} - )) -)); - const TeamTable = () => { const intl = useIntl(); - const { libraryId, canManageTeam, username } = useLibraryAuthZ(); - + const { + libraryId, canManageTeam, username, roles, + } = useLibraryAuthZ(); + const roleLabels = roles.reduce((acc, role) => ({ ...acc, [role.role]: role.name }), {} as Record); // TODO: Display error in the notification system const { data: teamMembers, isLoading, isError, @@ -107,7 +101,14 @@ const TeamTable = () => { { Header: intl.formatMessage(messages['library.authz.team.table.roles']), accessor: 'roles', - Cell: RolesCell, + // eslint-disable-next-line react/no-unstable-nested-components + Cell: ({ row }: CellProps) => (row.original.username === SKELETON_ROWS[0].username ? ( + + ) : ( + row.original.roles.map((role) => ( + {roleLabels[role]} + )) + )), }, ] }