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 EmptyState from '../../components/empty-state/empty-state';
17 import { RootState } from '../../store/store';
18 import actions from "../../store/details-panel/details-panel-action";
19 import { ProjectResource } from '../../models/project';
20 import { CollectionResource } from '../../models/collection';
21 import IconBase, { IconTypes } from '../../components/icon/icon';
22 import { ProcessResource } from '../../models/process';
23 import DetailsPanelFactory from '../../components/details-panel-factory/details-panel-factory';
25 export interface DetailsPanelDataProps {
26 onCloseDrawer: () => void;
30 details: React.ReactElement<any>;
33 type DetailsPanelProps = DetailsPanelDataProps & WithStyles<CssRules>;
35 class DetailsPanel extends React.Component<DetailsPanelProps, {}> {
40 handleChange = (event: any, value: boolean) => {
41 this.setState({ tabsValue: value });
44 renderTabContainer = (children: React.ReactElement<any>) =>
45 <Typography className={this.props.classes.tabContainer} component="div">
50 const { classes, onCloseDrawer, isOpened, icon, title, details } = this.props;
51 const { tabsValue } = this.state;
53 <Typography component="div" className={classnames([classes.container, { [classes.opened]: isOpened }])}>
54 <Drawer variant="permanent" anchor="right" classes={{ paper: classes.drawerPaper }}>
55 <Typography component="div" className={classes.headerContainer}>
56 <Grid container alignItems='center' justify='space-around'>
57 <IconBase className={classes.headerIcon} icon={icon} />
58 <Typography variant="title">
61 <IconButton color="inherit" onClick={onCloseDrawer}>
62 <IconBase icon={IconTypes.CLOSE} />
66 <Tabs value={tabsValue} onChange={this.handleChange}>
67 <Tab disableRipple label="Details" />
68 <Tab disableRipple label="Activity" disabled />
70 {tabsValue === 0 && this.renderTabContainer(
71 <Grid container direction="column">
75 {tabsValue === 1 && this.renderTabContainer(
76 <Grid container direction="column" />
85 type CssRules = 'drawerPaper' | 'container' | 'opened' | 'headerContainer' | 'headerIcon' | 'tabContainer';
87 const drawerWidth = 320;
88 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
93 transition: 'width 0.5s ease',
100 position: 'relative',
104 color: theme.palette.grey["600"],
105 margin: `${theme.spacing.unit}px 0`
111 padding: theme.spacing.unit * 3
115 // TODO: move to models
116 type DetailsPanelResource = ProjectResource | CollectionResource | ProcessResource;
118 const getEmptyState = () => {
119 return <EmptyState icon={ IconTypes.ANNOUNCEMENT }
120 message='Select a file or folder to view its details.' />;
123 const getItem = (res: DetailsPanelResource) => {
124 const item = DetailsPanelFactory.createItem(res);
126 title: item.getTitle(),
127 icon: item.getIcon(),
128 details: item.buildDetails()
132 const getDefaultItem = () => {
135 icon: IconTypes.FOLDER,
136 details: getEmptyState()
140 const mapStateToProps = ({ detailsPanel }: RootState) => {
141 const { isOpened, item } = detailsPanel;
142 const newItem = item ? getItem(item as DetailsPanelResource) : getDefaultItem();
149 const mapDispatchToProps = (dispatch: Dispatch) => ({
150 onCloseDrawer: () => {
151 dispatch(actions.TOGGLE_DETAILS_PANEL());
155 const DetailsPanelContainer = connect(mapStateToProps, mapDispatchToProps)(DetailsPanel);
157 export default withStyles(styles)(DetailsPanelContainer);