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