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