1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from "react";
6 import { MenuItem, Divider } from "@material-ui/core";
7 import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core/styles';
8 import { User, getUserFullname } from "~/models/user";
9 import { DropdownMenu } from "~/components/dropdown-menu/dropdown-menu";
10 import { Link } from "react-router-dom";
11 import { UserPanelIcon } from "~/components/icon/icon";
12 import { DispatchProp, connect } from 'react-redux';
13 import { logout } from '~/store/auth/auth-action';
14 import { RootState } from "~/store/store";
15 import { openCurrentTokenDialog } from '~/store/current-token-dialog/current-token-dialog-actions';
16 import { openRepositoriesPanel } from "~/store/repositories/repositories-actions";
18 navigateToSiteManager,
19 navigateToSshKeysUser,
21 } from '~/store/navigation/navigation-action';
22 import { openUserVirtualMachines } from "~/store/virtual-machines/virtual-machines-actions";
24 interface AccountMenuProps {
32 const mapStateToProps = (state: RootState): AccountMenuProps => ({
33 user: state.auth.user,
34 currentRoute: state.router.location ? state.router.location.pathname : '',
35 workbenchURL: state.config.workbenchUrl,
36 apiToken: state.auth.apiToken,
37 localCluster: state.auth.localCluster
40 const wb1URL = (route: string) => {
41 const r = route.replace(/^\//, "");
42 if (r.match(/^(projects|collections)\//)) {
44 } else if (r.match(/^processes\//)) {
45 return r.replace(/^processes/, "container_requests");
50 type CssRules = 'link';
52 const styles: StyleRulesCallback<CssRules> = () => ({
54 textDecoration: 'none',
59 export const AccountMenu = withStyles(styles)(
60 connect(mapStateToProps)(
61 ({ user, dispatch, currentRoute, workbenchURL, apiToken, localCluster, classes }: AccountMenuProps & DispatchProp<any> & WithStyles<CssRules>) =>
64 icon={<UserPanelIcon />}
66 title="Account Management"
69 {getUserFullname(user)} {user.uuid.substr(0, 5) !== localCluster && `(${user.uuid.substr(0, 5)})`}
71 <MenuItem onClick={() => dispatch(openUserVirtualMachines())}>Virtual Machines</MenuItem>
72 {!user.isAdmin && <MenuItem onClick={() => dispatch(openRepositoriesPanel())}>Repositories</MenuItem>}
73 <MenuItem onClick={() => dispatch(openCurrentTokenDialog)}>Current token</MenuItem>
74 <MenuItem onClick={() => dispatch(navigateToSshKeysUser)}>Ssh Keys</MenuItem>
75 <MenuItem onClick={() => dispatch(navigateToSiteManager)}>Site Manager</MenuItem>
76 <MenuItem onClick={() => dispatch(navigateToMyAccount)}>My account</MenuItem>
78 <a href={`${workbenchURL.replace(/\/$/, "")}/${wb1URL(currentRoute)}?api_token=${apiToken}`}
79 className={classes.link}>
80 Switch to Workbench v1</a></MenuItem>
82 <MenuItem onClick={() => dispatch(logout())}>Logout</MenuItem>