add 'New' button with 3 options and clean code
[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 { ArvadosTheme } from '~/common/custom-theme';
8 import { SidePanelTree, SidePanelTreeProps } from '~/views-components/side-panel-tree/side-panel-tree';
9 import { compose, Dispatch } from 'redux';
10 import { connect } from 'react-redux';
11 import { navigateFromSidePanel } from '../../store/side-panel/side-panel-action';
12 import { Grid } from '@material-ui/core';
13 import { SidePanelButton } from '~/views-components/side-panel-button/side-panel-button';
14
15 const DRAWER_WITDH = 240;
16
17 type CssRules = 'root';
18
19 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
20     root: {
21         background: theme.palette.background.paper,
22         borderRight: `1px solid ${theme.palette.divider}`,
23         height: '100%',
24         overflowX: 'auto',
25         width: DRAWER_WITDH,
26     }
27 });
28
29 const mapDispatchToProps = (dispatch: Dispatch): SidePanelTreeProps => ({
30     onItemActivation: id => {
31         dispatch<any>(navigateFromSidePanel(id));
32     }
33 });
34
35 export const SidePanel = compose(
36     withStyles(styles),
37     connect(undefined, mapDispatchToProps)
38 )(({ classes, ...props }: WithStyles<CssRules> & SidePanelTreeProps) =>
39     <Grid item xs>
40         <SidePanelButton />
41         <SidePanelTree {...props} />
42     </Grid>);