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;
39 const isButtonVisible = ({ router }: RootState) => {
40 const pathname = router.location ? router.location.pathname : '';
41 return Routes.matchCollectionsContentAddressRoute(pathname) ||
42 Routes.matchPublicFavoritesRoute(pathname) ||
43 Routes.matchGroupDetailsRoute(pathname) ||
44 Routes.matchGroupsRoute(pathname) ||
45 Routes.matchUsersRoute(pathname) ||
46 Routes.matchSearchResultsRoute(pathname) ||
47 Routes.matchSharedWithMeRoute(pathname) ||
48 Routes.matchProcessRoute(pathname) ||
49 Routes.matchCollectionRoute(pathname) ||
50 Routes.matchProjectRoute(pathname) ||
51 Routes.matchAllProcessesRoute(pathname) ||
52 Routes.matchTrashRoute(pathname) ||
53 Routes.matchFavoritesRoute(pathname);
56 const mapStateToProps = (state: RootState) => ({
57 buttonVisible: isButtonVisible(state),
58 projectUuid: state.detailsPanel.resourceUuid,
61 const mapDispatchToProps = () => (dispatch: Dispatch) => ({
62 onDetailsPanelToggle: () => dispatch<any>(toggleDetailsPanel()),
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);
80 {props.buttonVisible && <Tooltip title="Additional Info">
81 <IconButton data-cy="additional-info-icon"
83 className={props.classes.infoTooltip}
84 onClick={props.onDetailsPanelToggle}>