Merge branch '14434-display-workflow-name'
[arvados.git] / src / views-components / main-app-bar / account-menu.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import * as React from "react";
6 import { MenuItem } from "@material-ui/core";
7 import { User, getUserFullname } from "~/models/user";
8 import { DropdownMenu } from "~/components/dropdown-menu/dropdown-menu";
9 import { UserPanelIcon } from "~/components/icon/icon";
10 import { DispatchProp, connect } from 'react-redux';
11 import { logout } from '~/store/auth/auth-action';
12 import { RootState } from "~/store/store";
13 import { openCurrentTokenDialog } from '~/store/current-token-dialog/current-token-dialog-actions';
14 import { openRepositoriesPanel } from "~/store/repositories/repositories-actions";
15 import {
16     navigateToSiteManager,
17     navigateToSshKeysUser,
18     navigateToMyAccount
19 } from '~/store/navigation/navigation-action';
20 import { openUserVirtualMachines } from "~/store/virtual-machines/virtual-machines-actions";
21
22 interface AccountMenuProps {
23     user?: User;
24     currentRoute: string;
25 }
26
27 const mapStateToProps = (state: RootState): AccountMenuProps => ({
28     user: state.auth.user,
29     currentRoute: state.router.location ? state.router.location.pathname : ''
30 });
31
32 export const AccountMenu = connect(mapStateToProps)(
33     ({ user, dispatch, currentRoute }: AccountMenuProps & DispatchProp<any>) =>
34         user
35             ? <DropdownMenu
36                 icon={<UserPanelIcon />}
37                 id="account-menu"
38                 title="Account Management"
39                 key={currentRoute}>
40                 <MenuItem>
41                     {getUserFullname(user)}
42                 </MenuItem>
43                 <MenuItem onClick={() => dispatch(openUserVirtualMachines())}>Virtual Machines</MenuItem>
44                 {!user.isAdmin && <MenuItem onClick={() => dispatch(openRepositoriesPanel())}>Repositories</MenuItem>}
45                 <MenuItem onClick={() => dispatch(openCurrentTokenDialog)}>Current token</MenuItem>
46                 <MenuItem onClick={() => dispatch(navigateToSshKeysUser)}>Ssh Keys</MenuItem>
47                 <MenuItem onClick={() => dispatch(navigateToSiteManager)}>Site Manager</MenuItem>
48                 <MenuItem onClick={() => dispatch(navigateToMyAccount)}>My account</MenuItem>
49                 <MenuItem onClick={() => dispatch(logout())}>Logout</MenuItem>
50             </DropdownMenu>
51             : null);