1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
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';
26 export interface DetailsPanelDataProps {
27 onCloseDrawer: () => void;
32 type DetailsPanelProps = DetailsPanelDataProps & WithStyles<CssRules>;
34 class DetailsPanel extends React.Component<DetailsPanelProps, {}> {
39 handleChange = (event: any, value: boolean) => {
40 this.setState({ tabsValue: value });
43 renderTabContainer = (children: React.ReactElement<any>) =>
44 <Typography className={this.props.classes.tabContainer} component="div">
49 const { classes, onCloseDrawer, isOpened, item } = this.props;
50 const { tabsValue } = this.state;
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'>
57 <IconBase className={classes.headerIcon} icon={item.getIcon()} />
60 <Typography variant="title">
65 <IconButton color="inherit" onClick={onCloseDrawer}>
66 <IconBase icon={IconTypes.CLOSE} />
71 <Tabs value={tabsValue} onChange={this.handleChange}>
72 <Tab disableRipple label="Details" />
73 <Tab disableRipple label="Activity" disabled />
75 {tabsValue === 0 && this.renderTabContainer(
76 <Grid container direction="column">
80 {tabsValue === 1 && this.renderTabContainer(
81 <Grid container direction="column" />
90 type CssRules = 'drawerPaper' | 'container' | 'opened' | 'headerContainer' | 'headerIcon' | 'tabContainer';
92 const drawerWidth = 320;
93 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
98 transition: 'width 0.5s ease',
105 position: 'relative',
109 color: theme.palette.grey["600"],
110 margin: `${theme.spacing.unit}px 0`,
117 padding: theme.spacing.unit * 3
122 export type DetailsPanelResource = ProjectResource | CollectionResource | ProcessResource | EmptyResource;
124 const getItem = (res: DetailsPanelResource) => {
125 return DetailsPanelFactory.createItem(res);
128 const getDefaultItem = () => {
129 return DetailsPanelFactory.createItem({ kind: undefined, name: 'Projects' });
132 const mapStateToProps = ({ detailsPanel }: RootState) => {
133 const { isOpened, item } = detailsPanel;
136 item: item ? getItem(item as DetailsPanelResource) : getDefaultItem()
140 const mapDispatchToProps = (dispatch: Dispatch) => ({
141 onCloseDrawer: () => {
142 dispatch(actions.TOGGLE_DETAILS_PANEL());
146 const DetailsPanelContainer = connect(mapStateToProps, mapDispatchToProps)(DetailsPanel);
148 export default withStyles(styles)(DetailsPanelContainer);