Send new user data to server
[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 } 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 isWorkflowPath = ({ router }: RootState) => {
20     const pathname = router.location ? router.location.pathname : '';
21     const match = matchWorkflowRoute(pathname);
22     return !!match;
23 };
24
25 const isVirtualMachinePath = ({ router }: RootState) => {
26     const pathname = router.location ? router.location.pathname : '';
27     const match = matchVirtualMachineRoute(pathname);
28     return !!match;
29 };
30
31 const isRepositoriesPath = ({ router }: RootState) => {
32     const pathname = router.location ? router.location.pathname : '';
33     const match = matchRepositoriesRoute(pathname);
34     return !!match;
35 };
36
37 const isSshKeysPath = ({ router }: RootState) => {
38     const pathname = router.location ? router.location.pathname : '';
39     const match = matchSshKeysRoute(pathname);
40     return !!match;
41 };
42
43 export const MainContentBar = connect((state: RootState) => ({
44     buttonVisible: !isWorkflowPath(state) && !isSshKeysPath(state) && !isRepositoriesPath(state) && !isVirtualMachinePath(state)
45 }), {
46         onDetailsPanelToggle: toggleDetailsPanel
47     })((props: MainContentBarProps) =>
48         <Toolbar>
49             <Grid container>
50                 <Grid container item xs alignItems="center">
51                     <Breadcrumbs />
52                 </Grid>
53                 <Grid item>
54                     {props.buttonVisible && <Tooltip title="Additional Info">
55                         <IconButton color="inherit" onClick={props.onDetailsPanelToggle}>
56                             <DetailsIcon />
57                         </IconButton>
58                     </Tooltip>}
59                 </Grid>
60             </Grid>
61         </Toolbar>);