Skip to content
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

Added members to admin team page #6915

Merged
merged 6 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released

### Added
- Added support for remote Zarr datasets with a `datasource-properties.json` as created by the WEBKNOSSOS Python library. [#6879](https://github.com/scalableminds/webknossos/pull/6879)
- Added list of all respective team members to the administration page for teams. [#6915](https://github.com/scalableminds/webknossos/pull/6915)

### Changed
- Upgraded antd UI library to v4.24.8 [#6865](https://github.com/scalableminds/webknossos/pull/6865)
Expand Down
57 changes: 52 additions & 5 deletions frontend/javascripts/admin/team/team_list_view.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
// @ts-expect-error ts-migrate(7016) FIXME: Could not find a declaration file for module '@sca... Remove this comment to see the full error message
import { PropTypes } from "@scalableminds/prop-types";
import { Table, Spin, Button, Input, Modal, Alert } from "antd";
import { Table, Spin, Button, Input, Modal, Alert, Tag } from "antd";
import { DeleteOutlined, PlusOutlined } from "@ant-design/icons";
import * as React from "react";
import _ from "lodash";
import type { APITeam } from "types/api_flow_types";
import { getEditableTeams, deleteTeam } from "admin/admin_rest_api";
import type { APITeam, APITeamMembership, APIUser } from "types/api_flow_types";
import { getEditableTeams, deleteTeam, getEditableUsers } from "admin/admin_rest_api";
import { handleGenericError } from "libs/error_handling";
import LinkButton from "components/link_button";
import CreateTeamModal from "admin/team/create_team_modal_view";
import Persistence from "libs/persistence";
import * as Utils from "libs/utils";
import messages from "messages";
import { stringToColor } from "libs/format_utils";
const { Column } = Table;
const { Search } = Input;
const typeHint: APITeam[] = [];

type Props = {};
type State = {
isLoading: boolean;
teams: Array<APITeam>;
teams: APITeam[];
users: APIUser[];
searchQuery: string;
isTeamCreationModalVisible: boolean;
};

const persistence = new Persistence<Pick<State, "searchQuery">>(
{
searchQuery: PropTypes.string,
Expand All @@ -33,6 +37,7 @@ class TeamListView extends React.PureComponent<Props, State> {
state: State = {
isLoading: true,
teams: [],
users: [],
searchQuery: "",
isTeamCreationModalVisible: false,
};
Expand All @@ -48,10 +53,11 @@ class TeamListView extends React.PureComponent<Props, State> {
}

async fetchData(): Promise<void> {
const teams = await getEditableTeams();
const [teams, users] = await Promise.all([getEditableTeams(), getEditableUsers()]);
this.setState({
isLoading: false,
teams,
users,
});
}

Expand Down Expand Up @@ -112,6 +118,43 @@ 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>
));
Copy link
Member

Choose a reason for hiding this comment

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

could you DRY this with the corresponding code in the user_list_view?

Copy link
Member Author

@hotzenklotz hotzenklotz Mar 14, 2023

Choose a reason for hiding this comment

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

That was my first thought too. But there are slight differences. On this page, the Dataset Manager role is ignored/not display as it has no meaning for Teams. Also the the team name is also no part of the Tag, e.g. Member vs Default - Member

Copy link
Member

Choose a reason for hiding this comment

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

I see. How about moving the similar functions into the same module (could be either the team list view or user list view) so that they are next to each other? I think, it's better to keep them together, so that the chance of divergence is reduced.

Copy link
Member Author

Choose a reason for hiding this comment

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

I move both render methods into one file. Please see commit c0546d3

Copy link
Member

Choose a reason for hiding this comment

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

great 👍 feel free to merge.

}

renderUsersForTeam(team: APITeam) {
const teamMembers = this.state.users.filter(
(user) =>
user.teams.some((userTeam: APITeamMembership) => userTeam.id === team.id) || user.isAdmin,
);

if (teamMembers.length === 0) return messages["team.no_members"];

return (
<ul>
{teamMembers.map((teamMember) => (
<li>
{teamMember.firstName} {teamMember.lastName} ({teamMember.email}){" "}
{this.renderTeamRolesForUser(teamMember, team)}
</li>
))}
</ul>
);
}

render() {
const marginRight = {
marginRight: 20,
Expand Down Expand Up @@ -165,6 +208,10 @@ class TeamListView extends React.PureComponent<Props, State> {
pagination={{
defaultPageSize: 50,
}}
expandable={{
expandedRowRender: (team) => this.renderUsersForTeam(team),
rowExpandable: (_team) => true,
}}
style={{
marginTop: 30,
marginBottom: 30,
Expand Down
1 change: 1 addition & 0 deletions frontend/javascripts/messages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ instead. Only enable this option if you understand its effect. All layers will n
"This download does only include the volume data annotated in the tasks of this project. The fallback volume data is excluded.",
"script.delete": "Do you really want to delete this script?",
"team.delete": "Do you really want to delete this team?",
"team.no_members": "This team has no members assigned yet.",
"taskType.delete": "Do you really want to delete this task type and all its associated tasks?",
"auth.registration_email_input": "Please input your E-mail!",
"auth.registration_email_invalid": "The input is not valid E-mail!",
Expand Down