1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from "react";
6 import { MenuItem, Divider } from "@material-ui/core";
7 import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core/styles';
8 import { User, getUserDisplayName } from "models/user";
9 import { DropdownMenu } from "components/dropdown-menu/dropdown-menu";
10 import { UserPanelIcon } from "components/icon/icon";
11 import { DispatchProp, connect } from 'react-redux';
12 import { authActions, getNewExtraToken } from 'store/auth/auth-action';
13 import { RootState } from "store/store";
14 import { openTokenDialog } from 'store/token-dialog/token-dialog-actions';
15 import { openRepositoriesPanel } from "store/repositories/repositories-actions";
17 navigateToSiteManager,
18 navigateToSshKeysUser,
20 navigateToLinkAccount,
21 } from 'store/navigation/navigation-action';
22 import { openUserVirtualMachines } from "store/virtual-machines/virtual-machines-actions";
23 import { pluginConfig } from 'plugins';
24 import { ElementListReducer } from 'common/plugintypes';
26 interface AccountMenuProps {
34 const mapStateToProps = (state: RootState): AccountMenuProps => ({
35 user: state.auth.user,
36 currentRoute: state.router.location ? state.router.location.pathname : '',
37 workbenchURL: state.auth.config.workbenchUrl,
38 apiToken: state.auth.apiToken,
39 localCluster: state.auth.localCluster
42 type CssRules = 'link';
44 const styles: StyleRulesCallback<CssRules> = () => ({
46 textDecoration: 'none',
51 export const AccountMenuComponent =
52 ({ user, dispatch, currentRoute, workbenchURL, apiToken, localCluster, classes }: AccountMenuProps & DispatchProp<any> & WithStyles<CssRules>) => {
53 let accountMenuItems = <>
54 <MenuItem onClick={() => dispatch(openUserVirtualMachines())}>Shell Access</MenuItem>
55 <MenuItem onClick={() => dispatch(openRepositoriesPanel())}>Repositories</MenuItem>
56 <MenuItem onClick={() => {
57 dispatch<any>(getNewExtraToken(true));
58 dispatch(openTokenDialog);
59 }}>Get API token</MenuItem>
60 <MenuItem onClick={() => dispatch(navigateToSshKeysUser)}>Ssh Keys</MenuItem>
61 <MenuItem onClick={() => dispatch(navigateToSiteManager)}>Site Manager</MenuItem>
62 <MenuItem onClick={() => dispatch(navigateToMyAccount)}>My account</MenuItem>
63 <MenuItem onClick={() => dispatch(navigateToLinkAccount)}>Link account</MenuItem>
66 const reduceItemsFn: (a: React.ReactElement[],
67 b: ElementListReducer) => React.ReactElement[] = (a, b) => b(a);
69 accountMenuItems = React.createElement(React.Fragment, null,
70 pluginConfig.accountMenuList.reduce(reduceItemsFn, React.Children.toArray(accountMenuItems.props.children)));
74 icon={<UserPanelIcon />}
76 title="Account Management"
79 {getUserDisplayName(user)} {user.uuid.substring(0, 5) !== localCluster && `(${user.uuid.substring(0, 5)})`}
81 {user.isActive && accountMenuItems}
83 <MenuItem data-cy="logout-menuitem"
84 onClick={() => dispatch(authActions.LOGOUT({ deleteLinkData: true, preservePath: false }))}>
91 export const AccountMenu = withStyles(styles)(connect(mapStateToProps)(AccountMenuComponent));