virtual-machines-panel-init
[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 { detailsPanelActions } from "~/store/details-panel/details-panel-action";
10 import { connect } from 'react-redux';
11 import { RootState } from '~/store/store';
12 import { matchWorkflowRoute } from '~/routes/routes';
13 import { matchVirtualMachineRoute } from '~/routes/routes';
14
15 interface MainContentBarProps {
16     onDetailsPanelToggle: () => void;
17     buttonVisible: boolean;
18 }
19
20 const isWorkflowPath = ({ router }: RootState) => {
21     const pathname = router.location ? router.location.pathname : '';
22     const match = matchWorkflowRoute(pathname);
23     return !!match;
24 };
25
26 const isVirtualMachinePath = ({ router }: RootState) => {
27     const pathname = router.location ? router.location.pathname : '';
28     const match = matchVirtualMachineRoute(pathname);
29     return !!match;
30 };
31
32 export const MainContentBar = connect((state: RootState) => ({
33     buttonVisible: !isWorkflowPath(state) && !isVirtualMachinePath(state)
34 }), {
35         onDetailsPanelToggle: detailsPanelActions.TOGGLE_DETAILS_PANEL
36     })((props: MainContentBarProps) =>
37         <Toolbar>
38             <Grid container>
39                 <Grid container item xs alignItems="center">
40                     <Breadcrumbs />
41                 </Grid>
42                 <Grid item>
43                     {props.buttonVisible && <Tooltip title="Additional Info">
44                         <IconButton color="inherit" onClick={props.onDetailsPanelToggle}>
45                             <DetailsIcon />
46                         </IconButton>
47                     </Tooltip>}
48                 </Grid>
49             </Grid>
50         </Toolbar>);