Merge branch '19899-cache-control-fix' refs #19899
[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 } from '@material-ui/core';
13 import { SidePanelButton } from 'views-components/side-panel-button/side-panel-button';
14 import { RootState } from 'store/store';
15 import SidePanelToggle from 'views-components/side-panel-toggle/side-panel-toggle';
16
17 const DRAWER_WIDTH = 240;
18
19 type CssRules = 'root' | 'topButtonContainer';
20
21 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
22     root: {
23         background: theme.palette.background.paper,
24         borderRight: `1px solid ${theme.palette.divider}`,
25         height: '100%',
26         overflowX: 'auto',
27         width: DRAWER_WIDTH,
28     },
29     topButtonContainer: {
30         display: 'flex',
31         justifyContent: 'space-between'
32     }
33 });
34
35 const mapDispatchToProps = (dispatch: Dispatch): SidePanelTreeProps => ({
36     onItemActivation: id => {
37         dispatch<any>(navigateFromSidePanel(id));
38     }
39 });
40
41 const mapStateToProps = ({ router, sidePanel }: RootState) => ({
42     currentRoute: router.location ? router.location.pathname : '',
43     isCollapsed: sidePanel.collapsedState
44 });
45
46 export const SidePanel = withStyles(styles)(
47     connect(mapStateToProps, mapDispatchToProps)(
48         ({ classes, ...props }: WithStyles<CssRules> & SidePanelTreeProps & { currentRoute: string }) =>
49             <Grid item xs>
50                 {props.isCollapsed ? <SidePanelToggle /> :
51                 <>
52                     <Grid className={classes.topButtonContainer}>
53                         <SidePanelButton key={props.currentRoute} />
54                         <SidePanelToggle/>
55                     </Grid>
56                     <SidePanelTree {...props} />
57                 </>}
58             </Grid>
59     ));