X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/2b3f667039ba2e7efe0852d58ae2c62899b773f0..45ee419ff7952fc722a139666c327a321a92cc81:/src/views-components/main-app-bar/account-menu.tsx

diff --git a/src/views-components/main-app-bar/account-menu.tsx b/src/views-components/main-app-bar/account-menu.tsx
index ca88021c..72218053 100644
--- a/src/views-components/main-app-bar/account-menu.tsx
+++ b/src/views-components/main-app-bar/account-menu.tsx
@@ -3,7 +3,8 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import * as React from "react";
-import { MenuItem } from "@material-ui/core";
+import { MenuItem, Divider } from "@material-ui/core";
+import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core/styles';
 import { User, getUserFullname } from "~/models/user";
 import { DropdownMenu } from "~/components/dropdown-menu/dropdown-menu";
 import { UserPanelIcon } from "~/components/icon/icon";
@@ -12,32 +13,75 @@ import { logout } from '~/store/auth/auth-action';
 import { RootState } from "~/store/store";
 import { openCurrentTokenDialog } from '~/store/current-token-dialog/current-token-dialog-actions';
 import { openRepositoriesPanel } from "~/store/repositories/repositories-actions";
-import { navigateToSshKeys } from '~/store/navigation/navigation-action';
-import { openVirtualMachines } from "~/store/virtual-machines/virtual-machines-actions";
+import {
+    navigateToSiteManager,
+    navigateToSshKeysUser,
+    navigateToMyAccount,
+    navigateToLinkAccount
+} from '~/store/navigation/navigation-action';
+import { openUserVirtualMachines } from "~/store/virtual-machines/virtual-machines-actions";
 
 interface AccountMenuProps {
     user?: User;
+    currentRoute: string;
+    workbenchURL: string;
+    apiToken?: string;
+    localCluster: string;
 }
 
 const mapStateToProps = (state: RootState): AccountMenuProps => ({
-    user: state.auth.user
+    user: state.auth.user,
+    currentRoute: state.router.location ? state.router.location.pathname : '',
+    workbenchURL: state.config.workbenchUrl,
+    apiToken: state.auth.apiToken,
+    localCluster: state.auth.localCluster
 });
 
-export const AccountMenu = connect(mapStateToProps)(
-    ({ user, dispatch }: AccountMenuProps & DispatchProp<any>) =>
-        user
-            ? <DropdownMenu
-                icon={<UserPanelIcon />}
-                id="account-menu"
-                title="Account Management">
-                <MenuItem>
-                    {getUserFullname(user)}
-                </MenuItem>
-                <MenuItem onClick={() => dispatch(openVirtualMachines())}>Virtual Machines</MenuItem>
-                <MenuItem onClick={() => dispatch(openRepositoriesPanel())}>Repositories</MenuItem>
-                <MenuItem onClick={() => dispatch(openCurrentTokenDialog)}>Current token</MenuItem>
-                <MenuItem onClick={() => dispatch(navigateToSshKeys)}>Ssh Keys</MenuItem>
-                <MenuItem>My account</MenuItem>
-                <MenuItem onClick={() => dispatch(logout())}>Logout</MenuItem>
-            </DropdownMenu>
-            : null);
+const wb1URL = (route: string) => {
+    const r = route.replace(/^\//, "");
+    if (r.match(/^(projects|collections)\//)) {
+        return r;
+    } else if (r.match(/^processes\//)) {
+        return r.replace(/^processes/, "container_requests");
+    }
+    return "";
+};
+
+type CssRules = 'link';
+
+const styles: StyleRulesCallback<CssRules> = () => ({
+    link: {
+        textDecoration: 'none',
+        color: 'inherit'
+    }
+});
+
+export const AccountMenu = withStyles(styles)(
+    connect(mapStateToProps)(
+        ({ user, dispatch, currentRoute, workbenchURL, apiToken, localCluster, classes }: AccountMenuProps & DispatchProp<any> & WithStyles<CssRules>) =>
+            user
+                ? <DropdownMenu
+                    icon={<UserPanelIcon />}
+                    id="account-menu"
+                    title="Account Management"
+                    key={currentRoute}>
+                    <MenuItem disabled>
+                        {getUserFullname(user)} {user.uuid.substr(0, 5) !== localCluster && `(${user.uuid.substr(0, 5)})`}
+                    </MenuItem>
+                    {user.isActive ? <>
+                        <MenuItem onClick={() => dispatch(openUserVirtualMachines())}>Virtual Machines</MenuItem>
+                        {!user.isAdmin && <MenuItem onClick={() => dispatch(openRepositoriesPanel())}>Repositories</MenuItem>}
+                        <MenuItem onClick={() => dispatch(openCurrentTokenDialog)}>Current token</MenuItem>
+                        <MenuItem onClick={() => dispatch(navigateToSshKeysUser)}>Ssh Keys</MenuItem>
+                        <MenuItem onClick={() => dispatch(navigateToSiteManager)}>Site Manager</MenuItem>
+                        <MenuItem onClick={() => dispatch(navigateToMyAccount)}>My account</MenuItem>
+                        <MenuItem onClick={() => dispatch(navigateToLinkAccount)}>Link account</MenuItem>
+                    </> : null}
+                    <MenuItem>
+                        <a href={`${workbenchURL.replace(/\/$/, "")}/${wb1URL(currentRoute)}?api_token=${apiToken}`}
+                            className={classes.link}>
+                            Switch to Workbench v1</a></MenuItem>
+                    <Divider />
+                    <MenuItem onClick={() => dispatch(logout(true))}>Logout</MenuItem>
+                </DropdownMenu>
+                : null));
