Merge branch '14503_keep_services_panel'
[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 * as React from "react";
6 import { Toolbar, IconButton, Tooltip, Grid } from "@material-ui/core";
7 import { DetailsIcon } from "~/components/icon/icon";
8 import { Breadcrumbs } from "~/views-components/breadcrumbs/breadcrumbs";
9 import { connect } from 'react-redux';
10 import { RootState } from '~/store/store';
11 import { matchWorkflowRoute, matchSshKeysRoute, matchRepositoriesRoute, matchVirtualMachineRoute, matchKeepServicesRoute } from '~/routes/routes';
12 import { toggleDetailsPanel } from '~/store/details-panel/details-panel-action';
13
14 interface MainContentBarProps {
15     onDetailsPanelToggle: () => void;
16     buttonVisible: boolean;
17 }
18
19 const isButtonVisible = ({ router }: RootState) => {
20     const pathname = router.location ? router.location.pathname : '';
21     return !matchWorkflowRoute(pathname) && !matchVirtualMachineRoute(pathname) &&
22         !matchRepositoriesRoute(pathname) && !matchSshKeysRoute(pathname) && !matchKeepServicesRoute(pathname);
23 };
24
25 export const MainContentBar = connect((state: RootState) => ({
26     buttonVisible: isButtonVisible(state)
27 }), {
28         onDetailsPanelToggle: toggleDetailsPanel
29     })((props: MainContentBarProps) =>
30         <Toolbar>
31             <Grid container>
32                 <Grid container item xs alignItems="center">
33                     <Breadcrumbs />
34                 </Grid>
35                 <Grid item>
36                     {props.buttonVisible && <Tooltip title="Additional Info">
37                         <IconButton color="inherit" onClick={props.onDetailsPanelToggle}>
38                             <DetailsIcon />
39                         </IconButton>
40                     </Tooltip>}
41                 </Grid>
42             </Grid>
43         </Toolbar>);