Refactor to apply global navigation actions
[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 * as React from 'react';
6 import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core/styles';
7 import Drawer from '@material-ui/core/Drawer';
8 import { ArvadosTheme } from '~/common/custom-theme';
9 import { SidePanelTree, SidePanelTreeProps } from '~/views-components/side-panel-tree/side-panel-tree';
10 import { compose, Dispatch } from 'redux';
11 import { connect } from 'react-redux';
12 import { navigateFromSidePanel } from '../../store/side-panel/side-panel-action';
13
14 const DRAWER_WITDH = 240;
15
16 type CssRules = 'drawerPaper' | 'toolbar';
17
18 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
19     drawerPaper: {
20         position: 'relative',
21         width: DRAWER_WITDH,
22         display: 'flex',
23         flexDirection: 'column',
24         paddingTop: 58,
25         overflow: 'auto',
26     },
27     toolbar: theme.mixins.toolbar
28 });
29
30 const mapDispatchToProps = (dispatch: Dispatch): SidePanelTreeProps => ({
31     onItemActivation: id => {
32         dispatch<any>(navigateFromSidePanel(id));
33     }
34 });
35
36 export const SidePanel = compose(
37     withStyles(styles),
38     connect(undefined, mapDispatchToProps)
39 )(({ classes, ...props }: WithStyles<CssRules> & SidePanelTreeProps) =>
40     <Drawer
41         variant="permanent"
42         classes={{ paper: classes.drawerPaper }}>
43         <div className={classes.toolbar} />
44         <SidePanelTree {...props} />
45     </Drawer>);