Merge branch 'main' of git.arvados.org:arvados-workbench2 into 16073-process-io-panels
[arvados.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 } from '@material-ui/core';
13 import { SidePanelButton } from 'views-components/side-panel-button/side-panel-button';
14 import { RootState } from 'store/store';
15
16 const DRAWER_WITDH = 240;
17
18 type CssRules = 'root';
19
20 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
21     root: {
22         background: theme.palette.background.paper,
23         borderRight: `1px solid ${theme.palette.divider}`,
24         height: '100%',
25         overflowX: 'auto',
26         width: DRAWER_WITDH,
27     }
28 });
29
30 const mapDispatchToProps = (dispatch: Dispatch): SidePanelTreeProps => ({
31     onItemActivation: id => {
32         dispatch<any>(navigateFromSidePanel(id));
33     }
34 });
35
36 const mapStateToProps = ({ router }: RootState) => ({
37     currentRoute: router.location ? router.location.pathname : '',
38 });
39
40 export const SidePanel = withStyles(styles)(
41     connect(mapStateToProps, mapDispatchToProps)(
42         ({ classes, ...props }: WithStyles<CssRules> & SidePanelTreeProps & { currentRoute: string }) =>
43             <Grid item xs>
44                 <SidePanelButton key={props.currentRoute} />
45                 <SidePanelTree {...props} />
46             </Grid>
47     ));