Merge branch 'master' into 14566-admin-modal
[arvados-workbench2.git] / src / views-components / main-app-bar / admin-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 } from "~/models/user";
8 import { DropdownMenu } from "~/components/dropdown-menu/dropdown-menu";
9 import { AdminMenuIcon } 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 { openRepositoriesPanel } from "~/store/repositories/repositories-actions";
14 import { 
15     navigateToSshKeysAdmin, navigateToKeepServices, navigateToComputeNodes,
16     navigateToApiClientAuthorizations
17 } from '~/store/navigation/navigation-action';
18 import { openAdminVirtualMachines } from "~/store/virtual-machines/virtual-machines-actions";
19 import { openUserPanel } from "~/store/users/users-actions";
20
21 interface AdminMenuProps {
22     user?: User;
23 }
24
25 const mapStateToProps = (state: RootState): AdminMenuProps => ({
26     user: state.auth.user
27 });
28
29 export const AdminMenu = connect(mapStateToProps)(
30     ({ user, dispatch }: AdminMenuProps & DispatchProp<any>) =>
31         user
32             ? <DropdownMenu
33                 icon={<AdminMenuIcon />}
34                 id="admin-menu"
35                 title="Admin Panel">
36                 <MenuItem onClick={() => dispatch(openRepositoriesPanel())}>Repositories</MenuItem>
37                 <MenuItem onClick={() => dispatch(openAdminVirtualMachines())}>Virtual Machines</MenuItem>
38                 <MenuItem onClick={() => dispatch(navigateToSshKeysAdmin)}>Ssh Keys</MenuItem>
39                 <MenuItem onClick={() => dispatch(navigateToApiClientAuthorizations)}>Api Tokens</MenuItem>
40                 <MenuItem onClick={() => dispatch(openUserPanel())}>Users</MenuItem>
41                 <MenuItem onClick={() => dispatch(navigateToComputeNodes)}>Compute Nodes</MenuItem>
42                 <MenuItem onClick={() => dispatch(navigateToKeepServices)}>Keep Services</MenuItem>
43                 <MenuItem onClick={() => dispatch(logout())}>Logout</MenuItem>
44             </DropdownMenu>
45             : null);