collapse toggle button in main app bar, redux store set up to handle state change...
[arvados-workbench2.git] / src / views-components / side-panel / side-panel.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import React from 'react';
6 import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core/styles';
7 import { ArvadosTheme } from 'common/custom-theme';
8 import { SidePanelTree, SidePanelTreeProps } from 'views-components/side-panel-tree/side-panel-tree';
9 import { Dispatch } from 'redux';
10 import { connect } from 'react-redux';
11 import { navigateFromSidePanel } from 'store/side-panel/side-panel-action';
12 import { Grid, Tooltip, IconButton  } from '@material-ui/core';
13 import { SidePanelButton } from 'views-components/side-panel-button/side-panel-button';
14 import { RootState } from 'store/store';
15 import MenuIcon from "@material-ui/icons/Menu";
16 // import { IconButtonProps } from '@material-ui/core/IconButton';
17 // import { toggleSidePanel } from 'store/store';
18
19 const DRAWER_WIDTH = 240;
20
21 type CssRules = 'root';
22
23 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
24     root: {
25         background: theme.palette.background.paper,
26         borderRight: `1px solid ${theme.palette.divider}`,
27         height: '100%',
28         overflowX: 'auto',
29         width: DRAWER_WIDTH,
30     }
31 });
32
33 const mapDispatchToProps = (dispatch: Dispatch): SidePanelTreeProps => ({
34     onItemActivation: id => {
35         dispatch<any>(navigateFromSidePanel(id));
36     }
37 });
38
39 const mapStateToProps = ({ router }: RootState) => ({
40     currentRoute: router.location ? router.location.pathname : '',
41 });
42
43 export const SidePanel = withStyles(styles)(
44     connect(mapStateToProps, mapDispatchToProps)(
45         ({ classes, ...props }: WithStyles<CssRules> & SidePanelTreeProps & { currentRoute: string }) =>
46             <Grid item xs>
47                 <SidePanelButton key={props.currentRoute} />
48                 <SidePanelTree {...props} />
49             </Grid>
50     ));
51
52 export const CollapseLeftPanelTrigger = (props) =>{ 
53     console.log(props)
54     return <Tooltip disableFocusListener title="Toggle Side Panel">
55                 <IconButton onClick={()=>{props.toggleSidePanel(props.sidepanelcollapsed)}}>
56                     <MenuIcon aria-label="Toggle Side Panel" />
57                 </IconButton>
58             </Tooltip>
59     };