Merge branch '18661-refresh-flicker-fix'. Closes #18661
[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 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 import { loadSidePanelTreeProjects } from "store/side-panel-tree/side-panel-tree-actions";
16
17 type CssRules = "infoTooltip";
18
19 const styles: StyleRulesCallback<CssRules> = theme => ({
20     infoTooltip: {
21         marginTop: '-10px',
22         marginLeft: '10px',
23     }
24 });
25
26 interface MainContentBarProps {
27     onRefreshPage: () => void;
28     onDetailsPanelToggle: () => void;
29     buttonVisible: boolean;
30 }
31
32 const isButtonVisible = ({ router }: RootState) => {
33     const pathname = router.location ? router.location.pathname : '';
34     return Routes.matchCollectionsContentAddressRoute(pathname) ||
35         Routes.matchPublicFavoritesRoute(pathname) ||
36         Routes.matchGroupDetailsRoute(pathname) ||
37         Routes.matchGroupsRoute(pathname) ||
38         Routes.matchUsersRoute(pathname) ||
39         Routes.matchSearchResultsRoute(pathname) ||
40         Routes.matchSharedWithMeRoute(pathname) ||
41         Routes.matchProcessRoute(pathname) ||
42         Routes.matchCollectionRoute(pathname) ||
43         Routes.matchProjectRoute(pathname) ||
44         Routes.matchAllProcessesRoute(pathname) ||
45         Routes.matchTrashRoute(pathname) ||
46         Routes.matchFavoritesRoute(pathname);
47
48     /* return !Routes.matchWorkflowRoute(pathname) && !Routes.matchUserVirtualMachineRoute(pathname) &&
49      *     !Routes.matchAdminVirtualMachineRoute(pathname) && !Routes.matchRepositoriesRoute(pathname) &&
50      *     !Routes.matchSshKeysAdminRoute(pathname) && !Routes.matchSshKeysUserRoute(pathname) &&
51      *     !Routes.matchSiteManagerRoute(pathname) &&
52      *     !Routes.matchKeepServicesRoute(pathname) && !Routes.matchComputeNodesRoute(pathname) &&
53      *     !Routes.matchApiClientAuthorizationsRoute(pathname) && !Routes.matchUsersRoute(pathname) &&
54      *     !Routes.matchMyAccountRoute(pathname) && !Routes.matchLinksRoute(pathname); */
55 };
56
57 export const MainContentBar =
58     connect((state: RootState) => ({
59         buttonVisible: isButtonVisible(state),
60         projectUuid: state.detailsPanel.resourceUuid,
61     }), (dispatch) => ({
62             onDetailsPanelToggle: () => dispatch<any>(toggleDetailsPanel()),
63             onRefreshButtonClick: (id) => {
64                 dispatch<any>(loadSidePanelTreeProjects(id));
65             }
66         }))(
67             withStyles(styles)(
68                 (props: MainContentBarProps & WithStyles<CssRules> & any) =>
69                     <Toolbar>
70                         <Grid container>
71                             <Grid container item xs alignItems="center">
72                                 <Breadcrumbs />
73                             </Grid>
74                             <Grid item>
75                                 <RefreshButton onClick={() => {
76                                     props.onRefreshButtonClick(props.projectUuid);
77                                 }} />
78                             </Grid>
79                             <Grid item>
80                                 {props.buttonVisible && <Tooltip title="Additional Info">
81                                     <IconButton data-cy="additional-info-icon" color="inherit" className={props.classes.infoTooltip} onClick={props.onDetailsPanelToggle}>
82                                         <DetailsIcon />
83                                     </IconButton>
84                                 </Tooltip>}
85                             </Grid>
86                         </Grid>
87                     </Toolbar>
88             )
89         );