1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from "react";
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 import { Dispatch } from "redux";
18 type CssRules = 'mainBar' | 'breadcrumbContainer' | 'infoTooltip';
20 const styles: StyleRulesCallback<CssRules> = theme => ({
24 breadcrumbContainer: {
33 interface MainContentBarProps {
34 onRefreshPage: () => void;
35 onDetailsPanelToggle: () => void;
36 buttonVisible: boolean;
40 const isButtonVisible = ({ router }: RootState) => {
41 const pathname = router.location ? router.location.pathname : '';
42 return Routes.matchCollectionsContentAddressRoute(pathname) ||
43 Routes.matchPublicFavoritesRoute(pathname) ||
44 Routes.matchGroupDetailsRoute(pathname) ||
45 Routes.matchGroupsRoute(pathname) ||
46 Routes.matchUsersRoute(pathname) ||
47 Routes.matchSearchResultsRoute(pathname) ||
48 Routes.matchSharedWithMeRoute(pathname) ||
49 Routes.matchProcessRoute(pathname) ||
50 Routes.matchCollectionRoute(pathname) ||
51 Routes.matchProjectRoute(pathname) ||
52 Routes.matchAllProcessesRoute(pathname) ||
53 Routes.matchTrashRoute(pathname) ||
54 Routes.matchFavoritesRoute(pathname);
57 const mapStateToProps = (state: RootState) => {
58 const currentRoute = state.router.location?.pathname.split('/') || [];
59 const projectUuid = currentRoute[currentRoute.length - 1];
62 buttonVisible: isButtonVisible(state),
67 const mapDispatchToProps = () => (dispatch: Dispatch) => ({
68 onDetailsPanelToggle: (uuid: string) => dispatch<any>(toggleDetailsPanel(uuid)),
69 onRefreshButtonClick: (id) => {
70 dispatch<any>(loadSidePanelTreeProjects(id));
74 export const MainContentBar = connect(mapStateToProps, mapDispatchToProps)(withStyles(styles)(
75 (props: MainContentBarProps & WithStyles<CssRules> & any) =>
76 <Toolbar><Grid container className={props.classes.mainBar}>
77 <Grid container item xs alignItems="center" className={props.classes.breadcrumbContainer}>
81 <RefreshButton onClick={() => {
82 props.onRefreshButtonClick(props.projectUuid);
86 {props.buttonVisible && <Tooltip title="Additional Info" disableFocusListener>
87 <IconButton data-cy="additional-info-icon"
89 className={props.classes.infoTooltip}
90 onClick={()=>props.onDetailsPanelToggle(props.projectUuid)}>