Skip to content

Commit

Permalink
Collapse roles in user table
Browse files Browse the repository at this point in the history
The roles column in the user table can get extremely long in a
production system. This patch collapses UI, API and capture agent roles.

This fixes #351
  • Loading branch information
lkiesow committed Jun 5, 2024
1 parent 0feca7b commit 82a6f3d
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions src/components/users/partials/UsersRolesCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,36 @@ const UsersRolesCell = ({
row
}: any) => {
const getRoleString = () => {
let roleString = "";
let displayRoles = [];
let roleCountUI = 0;
let roleCountAPI = 0;
let roleCountCaptureAgent = 0;

// @ts-expect-error TS(7006): Parameter 'role' implicitly has an 'any' type.

Check failure on line 15 in src/components/users/partials/UsersRolesCell.tsx

View workflow job for this annotation

GitHub Actions / build

Unused '@ts-expect-error' directive.
row.roles.forEach((role) => {
roleString = roleString.concat(role.name + ", ");
});
for (const role of row.roles) {
// @ts-expect-error TS(7006): Parameter 'role' implicitly has an 'any' type.

Check failure on line 17 in src/components/users/partials/UsersRolesCell.tsx

View workflow job for this annotation

GitHub Actions / build

Unused '@ts-expect-error' directive.
if (role.name.startsWith('ROLE_UI')) {
roleCountUI++;
} else if (role.name.startsWith('ROLE_API')) {
roleCountAPI++;
} else if (role.name.startsWith('ROLE_CAPTURE_AGENT_')) {
roleCountCaptureAgent++;
} else {
displayRoles.push(role.name);
}
}

if (roleCountUI > 0) {
displayRoles.push(`${roleCountUI} UI roles`);
}
if (roleCountAPI > 0) {
displayRoles.push(`${roleCountAPI} API roles`);
}
if (roleCountCaptureAgent > 0) {
displayRoles.push(`${roleCountUI} capture agent roles`);
}

return roleString;
return displayRoles.join(', ');
};

return <span>{getRoleString()}</span>;
Expand Down

0 comments on commit 82a6f3d

Please sign in to comment.