Skip to content

refactor: Display member role when user has no role #1965

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 2, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Remove fallback role from the change event
  • Loading branch information
BrunoQuaresma committed Jun 1, 2022
commit fcc7b91a824e905ff48ba309573bfe1a89f3c434
20 changes: 11 additions & 9 deletions site/src/components/UsersTable/UsersTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,12 @@ export const UsersTable: FC<UsersTableProps> = ({
{!isLoading &&
users &&
users.map((user) => {
// When the user has no role, it is because they are a member
const fallbackRoles: TypesGen.Role[] = [
{
name: "member",
display_name: "Member",
},
]
const userRoles = user.roles.length === 0 ? fallbackRoles : user.roles
// When the user has no role we want to show they are a Member
const fallbackRole: TypesGen.Role = {
name: "member",
display_name: "Member",
}
const userRoles = user.roles.length === 0 ? [fallbackRole] : user.roles

return (
<TableRow key={user.id}>
Expand All @@ -93,7 +91,11 @@ export const UsersTable: FC<UsersTableProps> = ({
roles={roles ?? []}
selectedRoles={userRoles}
loading={isUpdatingUserRoles}
onChange={(roles) => onUpdateUserRoles(user, roles)}
onChange={(roles) => {
// Remove the fallback role because it is only for the UI
roles = roles.filter((role) => role !== fallbackRole.name)
onUpdateUserRoles(user, roles)
}}
/>
) : (
<>{userRoles.map((role) => role.display_name).join(", ")}</>
Expand Down