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' | 'headerTitle' | '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 overflowWrap: 'break-word',
52 wordWrap: 'break-word'
55 padding: theme.spacing.unit * 3
59 const getItem = (resource: DetailsResource): DetailsData => {
60 const res = resource || { kind: undefined, name: 'Projects' };
62 case ResourceKind.PROJECT:
63 return new ProjectDetails(res);
64 case ResourceKind.COLLECTION:
65 return new CollectionDetails(res);
66 case ResourceKind.PROCESS:
67 return new ProcessDetails(res);
69 return new EmptyDetails(res as EmptyResource);
73 const mapStateToProps = ({ detailsPanel }: RootState) => ({
74 isOpened: detailsPanel.isOpened,
75 item: getItem(detailsPanel.item as DetailsResource)
78 const mapDispatchToProps = (dispatch: Dispatch) => ({
79 onCloseDrawer: () => {
80 dispatch(detailsPanelActions.TOGGLE_DETAILS_PANEL());
84 export interface DetailsPanelDataProps {
85 onCloseDrawer: () => void;
90 type DetailsPanelProps = DetailsPanelDataProps & WithStyles<CssRules>;
92 export const DetailsPanel = withStyles(styles)(
93 connect(mapStateToProps, mapDispatchToProps)(
94 class extends React.Component<DetailsPanelProps> {
99 handleChange = (event: any, value: boolean) => {
100 this.setState({ tabsValue: value });
103 renderTabContainer = (children: React.ReactElement<any>) =>
104 <Typography className={this.props.classes.tabContainer} component="div">
109 const { classes, onCloseDrawer, isOpened, item } = this.props;
110 const { tabsValue } = this.state;
112 <Typography component="div"
113 className={classnames([classes.container, { [classes.opened]: isOpened }])}>
114 <Drawer variant="permanent" anchor="right" classes={{ paper: classes.drawerPaper }}>
115 <Typography component="div" className={classes.headerContainer}>
116 <Grid container alignItems='center' justify='space-around'>
118 {item.getIcon(classes.headerIcon)}
121 <Typography variant="title" className={classes.headerTitle}>
126 <IconButton color="inherit" onClick={onCloseDrawer}>
132 <Tabs value={tabsValue} onChange={this.handleChange}>
133 <Tab disableRipple label="Details"/>
134 <Tab disableRipple label="Activity" disabled/>
136 {tabsValue === 0 && this.renderTabContainer(
137 <Grid container direction="column">
141 {tabsValue === 1 && this.renderTabContainer(
142 <Grid container direction="column"/>