]> git.arvados.org - arvados.git/blob - services/workbench2/src/views-components/main-content-bar/main-content-bar.tsx
Merge branch '21720-material-ui-upgrade'
[arvados.git] / services / workbench2 / 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 import { CustomStyleRulesCallback } from 'common/custom-theme';
7 import { Toolbar, Grid } from "@mui/material";
8 import { WithStyles } from '@mui/styles';
9 import withStyles from '@mui/styles/withStyles';
10 import { Breadcrumbs } from "views-components/breadcrumbs/breadcrumbs";
11 import { connect } from 'react-redux';
12 import { RootState } from 'store/store';
13 import * as Routes from 'routes/routes';
14 import RefreshButton from "components/refresh-button/refresh-button";
15 import { loadSidePanelTreeProjects } from "store/side-panel-tree/side-panel-tree-actions";
16 import { Dispatch } from "redux";
17
18 type CssRules = 'mainBar' | 'breadcrumbContainer';
19
20 const styles: CustomStyleRulesCallback<CssRules> = theme => ({
21     mainBar: {
22         flexWrap: 'nowrap',
23     },
24     breadcrumbContainer: {
25         overflow: 'hidden',
26     },
27 });
28
29 interface MainContentBarProps {
30     onRefreshPage: () => void;
31     buttonVisible: boolean;
32     projectUuid: string;
33 }
34
35 const isButtonVisible = ({ router }: RootState) => {
36     const pathname = router.location ? router.location.pathname : '';
37     return Routes.matchCollectionsContentAddressRoute(pathname) ||
38         Routes.matchPublicFavoritesRoute(pathname) ||
39         Routes.matchGroupDetailsRoute(pathname) ||
40         Routes.matchGroupsRoute(pathname) ||
41         Routes.matchUsersRoute(pathname) ||
42         Routes.matchSearchResultsRoute(pathname) ||
43         Routes.matchSharedWithMeRoute(pathname) ||
44         Routes.matchProcessRoute(pathname) ||
45         Routes.matchCollectionRoute(pathname) ||
46         Routes.matchProjectRoute(pathname) ||
47         Routes.matchAllProcessesRoute(pathname) ||
48         Routes.matchTrashRoute(pathname) ||
49         Routes.matchFavoritesRoute(pathname);
50 };
51
52 const mapStateToProps = (state: RootState) => {
53     const currentRoute = state.router.location?.pathname.split('/') || [];
54     const projectUuid = currentRoute[currentRoute.length - 1];
55
56     return {
57         buttonVisible: isButtonVisible(state),
58         projectUuid,
59     }
60 };
61
62 const mapDispatchToProps = () => (dispatch: Dispatch) => ({
63     onRefreshButtonClick: (id) => {
64         dispatch<any>(loadSidePanelTreeProjects(id));
65     }
66 });
67
68 export const MainContentBar = connect(mapStateToProps, mapDispatchToProps)(withStyles(styles)(
69     (props: MainContentBarProps & WithStyles<CssRules> & any) =>
70         <Toolbar><Grid container className={props.classes.mainBar}>
71             <Grid container item xs alignItems="center" className={props.classes.breadcrumbContainer}>
72                 <Breadcrumbs />
73             </Grid>
74             <Grid item>
75                 <RefreshButton onClick={() => {
76                     props.onRefreshButtonClick(props.projectUuid);
77                 }} />
78             </Grid>
79         </Grid></Toolbar>
80 ));