Remove emptyIconSet
[arvados.git] / src / views-components / details-panel / details-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 Drawer from '@material-ui/core/Drawer';
7 import IconButton from "@material-ui/core/IconButton";
8 import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core/styles';
9 import { ArvadosTheme } from '../../common/custom-theme';
10 import Tabs from '@material-ui/core/Tabs';
11 import Tab from '@material-ui/core/Tab';
12 import Typography from '@material-ui/core/Typography';
13 import Grid from '@material-ui/core/Grid';
14 import * as classnames from "classnames";
15 import { connect, Dispatch } from 'react-redux';
16 import { RootState } from '../../store/store';
17 import actions from "../../store/details-panel/details-panel-action";
18 import { ProjectResource } from '../../models/project';
19 import { CollectionResource } from '../../models/collection';
20 import IconBase, { IconTypes } from '../../components/icon/icon';
21 import { ProcessResource } from '../../models/process';
22 import DetailsPanelFactory from '../../components/details-panel-factory/details-panel-factory';
23 import AbstractItem from '../../components/details-panel-factory/items/abstract-item';
24 import { EmptyResource } from '../../models/empty';
25
26 export interface DetailsPanelDataProps {
27     onCloseDrawer: () => void;
28     isOpened: boolean;
29     item: AbstractItem;
30 }
31
32 type DetailsPanelProps = DetailsPanelDataProps & WithStyles<CssRules>;
33
34 class DetailsPanel extends React.Component<DetailsPanelProps, {}> {
35     state = {
36         tabsValue: 0
37     };
38
39     handleChange = (event: any, value: boolean) => {
40         this.setState({ tabsValue: value });
41     }
42
43     renderTabContainer = (children: React.ReactElement<any>) =>
44         <Typography className={this.props.classes.tabContainer} component="div">
45             {children}
46         </Typography>
47
48     render() {
49         const { classes, onCloseDrawer, isOpened, item } = this.props;
50         const { tabsValue } = this.state;
51         return (
52             <Typography component="div" className={classnames([classes.container, { [classes.opened]: isOpened }])}>
53                 <Drawer variant="permanent" anchor="right" classes={{ paper: classes.drawerPaper }}>
54                     <Typography component="div" className={classes.headerContainer}>
55                         <Grid container alignItems='center' justify='space-around'>
56                             <Grid item xs={2}>
57                                 <IconBase className={classes.headerIcon} icon={item.getIcon()} />
58                             </Grid>
59                             <Grid item xs={8}>
60                                 <Typography variant="title">
61                                     {item.getTitle()}
62                                 </Typography>
63                             </Grid>
64                             <Grid item>
65                                 <IconButton color="inherit" onClick={onCloseDrawer}>
66                                     <IconBase icon={IconTypes.CLOSE} />
67                                 </IconButton>
68                             </Grid>
69                         </Grid>
70                     </Typography>
71                     <Tabs value={tabsValue} onChange={this.handleChange}>
72                         <Tab disableRipple label="Details" />
73                         <Tab disableRipple label="Activity" disabled />
74                     </Tabs>
75                     {tabsValue === 0 && this.renderTabContainer(
76                         <Grid container direction="column">
77                             {item.buildDetails()}
78                         </Grid>
79                     )}
80                     {tabsValue === 1 && this.renderTabContainer(
81                         <Grid container direction="column" />
82                     )}
83                 </Drawer>
84             </Typography>
85         );
86     }
87
88 }
89
90 type CssRules = 'drawerPaper' | 'container' | 'opened' | 'headerContainer' | 'headerIcon' | 'tabContainer';
91
92 const drawerWidth = 320;
93 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
94     container: {
95         width: 0,
96         position: 'relative',
97         height: 'auto',
98         transition: 'width 0.5s ease',
99         '&$opened': {
100             width: drawerWidth
101         }
102     },
103     opened: {},
104     drawerPaper: {
105         position: 'relative',
106         width: drawerWidth
107     },
108     headerContainer: {
109         color: theme.palette.grey["600"],
110         margin: `${theme.spacing.unit}px 0`,
111         textAlign: 'center'
112     },
113     headerIcon: {
114         fontSize: "34px"
115     },
116     tabContainer: {
117         padding: theme.spacing.unit * 3
118     }
119 });
120
121
122 export type DetailsPanelResource = ProjectResource | CollectionResource | ProcessResource | EmptyResource;
123
124 const getItem = (res: DetailsPanelResource) => {
125     return DetailsPanelFactory.createItem(res);
126 };
127
128 const getDefaultItem = () => {
129     return DetailsPanelFactory.createItem({ kind: undefined, name: 'Projects' });
130 };
131
132 const mapStateToProps = ({ detailsPanel }: RootState) => {
133     const { isOpened, item } = detailsPanel;
134     return {
135         isOpened,
136         item: item ? getItem(item as DetailsPanelResource) : getDefaultItem()
137     };
138 };
139
140 const mapDispatchToProps = (dispatch: Dispatch) => ({
141     onCloseDrawer: () => {
142         dispatch(actions.TOGGLE_DETAILS_PANEL());
143     }
144 });
145
146 const DetailsPanelContainer = connect(mapStateToProps, mapDispatchToProps)(DetailsPanel);
147
148 export default withStyles(styles)(DetailsPanelContainer);