Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions src/authz-module/libraries-manager/components/TeamTable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
];
Expand All @@ -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(() => {
Expand Down
23 changes: 12 additions & 11 deletions src/authz-module/libraries-manager/components/TeamTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,12 @@ const NameCell = ({ row }: CellProps) => {
return row.original.username;
};

const RolesCell = ({ row }: CellProps) => (row.original.username === SKELETON_ROWS[0].username ? (
<Skeleton width="80px" />
) : (
row.original.roles.map((role) => (
<Chip key={`${row.original.username}-role-${role}`}>{role}</Chip>
))
));

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<string, string>);
// TODO: Display error in the notification system
const {
data: teamMembers, isLoading, isError,
Expand Down Expand Up @@ -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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a huge fan of ignoring eslint rules, but I see this is already being done earlier in this file

// eslint-disable-next-line react/no-unstable-nested-components

I created an issue to track this

Cell: ({ row }: CellProps) => (row.original.username === SKELETON_ROWS[0].username ? (
<Skeleton width="80px" />
) : (
row.original.roles.map((role) => (
<Chip key={`${row.original.username}-role-${role}`}>{roleLabels[role]}</Chip>
))
)),
},
]
}
Expand Down