Skip to content

Commit

Permalink
applied PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
hotzenklotz committed Mar 14, 2023
1 parent 7b91d56 commit c0546d3
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 41 deletions.
60 changes: 42 additions & 18 deletions frontend/javascripts/admin/team/team_list_view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,47 @@ type State = {
isTeamCreationModalVisible: boolean;
};

export function renderTeamRolesAndPermissionsForUser(user: APIUser) {
//used by user list page
const tags = [
...(user.isOrganizationOwner ? [["Organization Owner", "cyan"]] : []),
...(user.isAdmin
? [["Admin - Access to all Teams", "red"]]
: [
...(user.isDatasetManager ? [["Dataset Manager - Edit all Datasets", "geekblue"]] : []),
...user.teams.map((team) => {
const roleName = team.isTeamManager ? "Team Manager" : "Member";
return [`${team.name}: ${roleName}`, stringToColor(roleName)];
}),
]),
];

return tags.map(([text, color]) => (
<Tag key={`${text}_${user.id}`} color={color} style={{ marginBottom: 4 }}>
{text}
</Tag>
));
}

function renderTeamRolesForUser(user: APIUser, highlightedTeam: APITeam) {
// used by teams list page
// does not include dataset managers and team names
const tags = user.isAdmin
? [["Admin - Access to all Teams", "red"]]
: user.teams
.filter((team) => team.id === highlightedTeam.id)
.map((team) => {
const roleName = team.isTeamManager ? "Team Manager" : "Member";
return [`${roleName}`, stringToColor(roleName)];
});

return tags.map(([text, color]) => (
<Tag key={`${text}_${user.id}`} color={color} style={{ marginBottom: 4 }}>
{text}
</Tag>
));
}

const persistence = new Persistence<Pick<State, "searchQuery">>(
{
searchQuery: PropTypes.string,
Expand Down Expand Up @@ -118,23 +159,6 @@ class TeamListView extends React.PureComponent<Props, State> {
);
}

renderTeamRolesForUser(user: APIUser, highlightedTeam: APITeam) {
const tags = user.isAdmin
? [["Admin - Access to all Teams", "red"]]
: user.teams
.filter((team) => team.id === highlightedTeam.id)
.map((team) => {
const roleName = team.isTeamManager ? "Team Manager" : "Member";
return [`${roleName}`, stringToColor(roleName)];
});

return tags.map(([text, color]) => (
<Tag key={`${text}_${user.id}`} color={color} style={{ marginBottom: 4 }}>
{text}
</Tag>
));
}

renderUsersForTeam(team: APITeam) {
const teamMembers = this.state.users.filter(
(user) =>
Expand All @@ -148,7 +172,7 @@ class TeamListView extends React.PureComponent<Props, State> {
{teamMembers.map((teamMember) => (
<li>
{teamMember.firstName} {teamMember.lastName} ({teamMember.email}){" "}
{this.renderTeamRolesForUser(teamMember, team)}
{renderTeamRolesForUser(teamMember, team)}
</li>
))}
</ul>
Expand Down
27 changes: 4 additions & 23 deletions frontend/javascripts/admin/user/user_list_view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import type { OxalisState } from "oxalis/store";
import { enforceActiveUser } from "oxalis/model/accessors/user_accessor";
import LinkButton from "components/link_button";
import { getEditableUsers, updateUser } from "admin/admin_rest_api";
import { stringToColor } from "libs/format_utils";
import EditableTextLabel from "oxalis/view/components/editable_text_label";
import ExperienceModalView from "admin/user/experience_modal_view";
import Persistence from "libs/persistence";
Expand All @@ -43,6 +42,7 @@ import messages from "messages";
import { logoutUserAction } from "../../oxalis/model/actions/user_actions";
import Store from "../../oxalis/store";
import { enforceActiveOrganization } from "oxalis/model/accessors/organization_accessors";
import { renderTeamRolesAndPermissionsForUser } from "admin/team/team_list_view";

const { Column } = Table;
const { Search } = Input;
Expand Down Expand Up @@ -543,28 +543,9 @@ class UserListView extends React.PureComponent<Props, State> {
dataIndex="teams"
key="teams_"
width={250}
render={(_teams: APITeamMembership[], user: APIUser) => {
const tags = [
...(user.isOrganizationOwner ? [["Organization Owner", "cyan"]] : []),
...(user.isAdmin
? [["Admin - Access to all Teams", "red"]]
: [
...(user.isDatasetManager
? [["Dataset Manager - Edit all Datasets", "geekblue"]]
: []),
...user.teams.map((team) => {
const roleName = team.isTeamManager ? "Team Manager" : "Member";
return [`${team.name}: ${roleName}`, stringToColor(roleName)];
}),
]),
];

return tags.map(([text, color]) => (
<Tag key={`${text}_${user.id}`} color={color} style={{ marginBottom: 4 }}>
{text}
</Tag>
));
}}
render={(_teams: APITeamMembership[], user: APIUser) =>
renderTeamRolesAndPermissionsForUser(user)
}
/>
<Column
title="Status"
Expand Down

0 comments on commit c0546d3

Please sign in to comment.