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, 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 } from 'react-redux';
11 import { RootState } from '~/store/store';
12 import { detailsPanelActions } from "~/store/details-panel/details-panel-action";
13 import { CloseIcon } from '~/components/icon/icon';
14 import { EmptyResource } from '~/models/empty';
15 import { Dispatch } from "redux";
16 import { ResourceKind } from "~/models/resource";
17 import { ProjectDetails } from "./project-details";
18 import { CollectionDetails } from "./collection-details";
19 import { ProcessDetails } from "./process-details";
20 import { EmptyDetails } from "./empty-details";
21 import { DetailsData } from "./details-data";
22 import { DetailsResource } from "~/models/details";
24 type CssRules = 'drawerPaper' | 'container' | 'opened' | 'headerContainer' | 'headerIcon' | 'tabContainer';
26 const drawerWidth = 320;
27 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
32 transition: 'width 0.5s ease',
43 color: theme.palette.grey["600"],
44 margin: `${theme.spacing.unit}px 0`,
51 padding: theme.spacing.unit * 3
55 const getItem = (resource: DetailsResource): DetailsData => {
56 const res = resource || { kind: undefined, name: 'Projects' };
58 case ResourceKind.PROJECT:
59 return new ProjectDetails(res);
60 case ResourceKind.COLLECTION:
61 return new CollectionDetails(res);
62 case ResourceKind.PROCESS:
63 return new ProcessDetails(res);
65 return new EmptyDetails(res as EmptyResource);
69 const mapStateToProps = ({ detailsPanel }: RootState) => ({
70 isOpened: detailsPanel.isOpened,
71 item: getItem(detailsPanel.item as DetailsResource)
74 const mapDispatchToProps = (dispatch: Dispatch) => ({
75 onCloseDrawer: () => {
76 dispatch(detailsPanelActions.TOGGLE_DETAILS_PANEL());
80 export interface DetailsPanelDataProps {
81 onCloseDrawer: () => void;
86 type DetailsPanelProps = DetailsPanelDataProps & WithStyles<CssRules>;
88 export const DetailsPanel = withStyles(styles)(
89 connect(mapStateToProps, mapDispatchToProps)(
90 class extends React.Component<DetailsPanelProps> {
95 handleChange = (event: any, value: boolean) => {
96 this.setState({ tabsValue: value });
99 renderTabContainer = (children: React.ReactElement<any>) =>
100 <Typography className={this.props.classes.tabContainer} component="div">
105 const { classes, onCloseDrawer, isOpened, item } = this.props;
106 const { tabsValue } = this.state;
108 <Typography component="div"
109 className={classnames([classes.container, { [classes.opened]: isOpened }])}>
110 <Drawer variant="permanent" anchor="right" classes={{ paper: classes.drawerPaper }}>
111 <Typography component="div" className={classes.headerContainer}>
112 <Grid container alignItems='center' justify='space-around'>
114 {item.getIcon(classes.headerIcon)}
117 <Typography variant="title">
122 <IconButton color="inherit" onClick={onCloseDrawer}>
128 <Tabs value={tabsValue} onChange={this.handleChange}>
129 <Tab disableRipple label="Details"/>
130 <Tab disableRipple label="Activity" disabled/>
132 {tabsValue === 0 && this.renderTabContainer(
133 <Grid container direction="column">
137 {tabsValue === 1 && this.renderTabContainer(
138 <Grid container direction="column"/>