Merge branch '17337-files-not-visible-in-arvados'
[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
7 import { Toolbar, StyleRulesCallback, IconButton, Tooltip, Grid, WithStyles, withStyles } from "@material-ui/core";
8 import { DetailsIcon } from "~/components/icon/icon";
9 import { Breadcrumbs } from "~/views-components/breadcrumbs/breadcrumbs";
10 import { connect } from 'react-redux';
11 import { RootState } from '~/store/store';
12 import * as Routes from '~/routes/routes';
13 import { toggleDetailsPanel } from '~/store/details-panel/details-panel-action';
14 import RefreshButton from "~/components/refresh-button/refresh-button";
15
16 type CssRules = "infoTooltip";
17
18 const styles: StyleRulesCallback<CssRules> = theme => ({
19     infoTooltip: {
20         marginTop: '-10px',
21         marginLeft: '10px',
22     }
23 });
24
25 interface MainContentBarProps {
26     onRefreshPage: () => void;
27     onDetailsPanelToggle: () => void;
28     buttonVisible: boolean;
29 }
30
31 const isButtonVisible = ({ router }: RootState) => {
32     const pathname = router.location ? router.location.pathname : '';
33     return !Routes.matchWorkflowRoute(pathname) && !Routes.matchUserVirtualMachineRoute(pathname) &&
34         !Routes.matchAdminVirtualMachineRoute(pathname) && !Routes.matchRepositoriesRoute(pathname) &&
35         !Routes.matchSshKeysAdminRoute(pathname) && !Routes.matchSshKeysUserRoute(pathname) &&
36         !Routes.matchSiteManagerRoute(pathname) &&
37         !Routes.matchKeepServicesRoute(pathname) && !Routes.matchComputeNodesRoute(pathname) &&
38         !Routes.matchApiClientAuthorizationsRoute(pathname) && !Routes.matchUsersRoute(pathname) &&
39         !Routes.matchMyAccountRoute(pathname) && !Routes.matchLinksRoute(pathname);
40 };
41
42 export const MainContentBar =
43     connect((state: RootState) => ({
44         buttonVisible: isButtonVisible(state)
45     }), {
46             onDetailsPanelToggle: toggleDetailsPanel,
47         })(
48             withStyles(styles)(
49                 (props: MainContentBarProps & WithStyles<CssRules> & any) =>
50                     <Toolbar>
51                         <Grid container>
52                             <Grid container item xs alignItems="center">
53                                 <Breadcrumbs />
54                             </Grid>
55                             <Grid item>
56                                 <RefreshButton />
57                             </Grid>
58                             <Grid item>
59                                 {props.buttonVisible && <Tooltip title="Additional Info">
60                                     <IconButton color="inherit" className={props.classes.infoTooltip} onClick={props.onDetailsPanelToggle}>
61                                         <DetailsIcon />
62                                     </IconButton>
63                                 </Tooltip>}
64                             </Grid>
65                         </Grid>
66                     </Toolbar>
67             )
68         );