70bc92b7162aef6acc157dac5a1dc15d26d295a7
[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 = 'root';
17
18 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
19     root: {
20         background: theme.palette.background.paper,
21         borderRight: `1px solid ${theme.palette.divider}`,
22         height: '100%',
23         overflowX: 'auto',
24         width: DRAWER_WITDH,
25     }
26 });
27
28 const mapDispatchToProps = (dispatch: Dispatch): SidePanelTreeProps => ({
29     onItemActivation: id => {
30         dispatch<any>(navigateFromSidePanel(id));
31     }
32 });
33
34 export const SidePanel = compose(
35     withStyles(styles),
36     connect(undefined, mapDispatchToProps)
37 )(({ classes, ...props }: WithStyles<CssRules> & SidePanelTreeProps) =>
38     <div className={classes.root}>
39         <SidePanelTree {...props} />
40     </div>);