17426: Add plugin ability to override app bar.
[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.matchCollectionsContentAddressRoute(pathname) ||
34         Routes.matchPublicFavoritesRoute(pathname) ||
35         Routes.matchGroupDetailsRoute(pathname) ||
36         Routes.matchGroupsRoute(pathname) ||
37         Routes.matchUsersRoute(pathname) ||
38         Routes.matchSearchResultsRoute(pathname) ||
39         Routes.matchSharedWithMeRoute(pathname) ||
40         Routes.matchProcessRoute(pathname) ||
41         Routes.matchCollectionRoute(pathname) ||
42         Routes.matchProjectRoute(pathname) ||
43         Routes.matchAllProcessesRoute(pathname) ||
44         Routes.matchTrashRoute(pathname) ||
45         Routes.matchFavoritesRoute(pathname);
46
47     /* return !Routes.matchWorkflowRoute(pathname) && !Routes.matchUserVirtualMachineRoute(pathname) &&
48      *     !Routes.matchAdminVirtualMachineRoute(pathname) && !Routes.matchRepositoriesRoute(pathname) &&
49      *     !Routes.matchSshKeysAdminRoute(pathname) && !Routes.matchSshKeysUserRoute(pathname) &&
50      *     !Routes.matchSiteManagerRoute(pathname) &&
51      *     !Routes.matchKeepServicesRoute(pathname) && !Routes.matchComputeNodesRoute(pathname) &&
52      *     !Routes.matchApiClientAuthorizationsRoute(pathname) && !Routes.matchUsersRoute(pathname) &&
53      *     !Routes.matchMyAccountRoute(pathname) && !Routes.matchLinksRoute(pathname); */
54 };
55
56 export const MainContentBar =
57     connect((state: RootState) => ({
58         buttonVisible: isButtonVisible(state)
59     }), {
60             onDetailsPanelToggle: toggleDetailsPanel,
61         })(
62             withStyles(styles)(
63                 (props: MainContentBarProps & WithStyles<CssRules> & any) =>
64                     <Toolbar>
65                         <Grid container>
66                             <Grid container item xs alignItems="center">
67                                 <Breadcrumbs />
68                             </Grid>
69                             <Grid item>
70                                 <RefreshButton />
71                             </Grid>
72                             <Grid item>
73                                 {props.buttonVisible && <Tooltip title="Additional Info">
74                                     <IconButton color="inherit" className={props.classes.infoTooltip} onClick={props.onDetailsPanelToggle}>
75                                         <DetailsIcon />
76                                     </IconButton>
77                                 </Tooltip>}
78                             </Grid>
79                         </Grid>
80                     </Toolbar>
81             )
82         );