1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
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";
18 type CssRules = 'mainBar' | 'breadcrumbContainer';
20 const styles: CustomStyleRulesCallback<CssRules> = theme => ({
24 breadcrumbContainer: {
29 interface MainContentBarProps {
30 onRefreshPage: () => void;
31 buttonVisible: boolean;
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);
52 const mapStateToProps = (state: RootState) => {
53 const currentRoute = state.router.location?.pathname.split('/') || [];
54 const projectUuid = currentRoute[currentRoute.length - 1];
57 buttonVisible: isButtonVisible(state),
62 const mapDispatchToProps = () => (dispatch: Dispatch) => ({
63 onRefreshButtonClick: (id) => {
64 dispatch<any>(loadSidePanelTreeProjects(id));
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}>
75 <RefreshButton onClick={() => {
76 props.onRefreshButtonClick(props.projectUuid);