created-admin-menu-and-extracted-virtual-machines-to-separated-components
[arvados-workbench2.git] / src / views-components / main-content-bar / main-content-bar.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 { Toolbar, IconButton, Tooltip, Grid } from "@material-ui/core";
7 import { DetailsIcon } from "~/components/icon/icon";
8 import { Breadcrumbs } from "~/views-components/breadcrumbs/breadcrumbs";
9 import { connect } from 'react-redux';
10 import { RootState } from '~/store/store';
11 import * as Routes from '~/routes/routes';
12 import { toggleDetailsPanel } from '~/store/details-panel/details-panel-action';
13
14 interface MainContentBarProps {
15     onDetailsPanelToggle: () => void;
16     buttonVisible: boolean;
17 }
18
19 const isButtonVisible = ({ router }: RootState) => {
20     const pathname = router.location ? router.location.pathname : '';
21     return !Routes.matchWorkflowRoute(pathname) && !Routes.matchUserVirtualMachineRoute(pathname) &&
22         !Routes.matchAdminVirtualMachineRoute(pathname) && !Routes.matchRepositoriesRoute(pathname) && 
23         !Routes.matchSshKeysRoute(pathname) && !Routes.matchKeepServicesRoute(pathname) && 
24         !Routes.matchComputeNodesRoute(pathname) && !Routes.matchApiClientAuthorizationsRoute(pathname) && 
25         !Routes.matchUsersRoute(pathname) && !Routes.matchMyAccountRoute(pathname);
26 };
27
28 export const MainContentBar = connect((state: RootState) => ({
29     buttonVisible: isButtonVisible(state)
30 }), {
31         onDetailsPanelToggle: toggleDetailsPanel
32     })((props: MainContentBarProps) =>
33         <Toolbar>
34             <Grid container>
35                 <Grid container item xs alignItems="center">
36                     <Breadcrumbs />
37                 </Grid>
38                 <Grid item>
39                     {props.buttonVisible && <Tooltip title="Additional Info">
40                         <IconButton color="inherit" onClick={props.onDetailsPanelToggle}>
41                             <DetailsIcon />
42                         </IconButton>
43                     </Tooltip>}
44                 </Grid>
45             </Grid>
46         </Toolbar>);