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 wordBreak: 'break-all'
54 padding: theme.spacing.unit * 3
58 const getItem = (resource: DetailsResource): DetailsData => {
59 const res = resource || { kind: undefined, name: 'Projects' };
61 case ResourceKind.PROJECT:
62 return new ProjectDetails(res);
63 case ResourceKind.COLLECTION:
64 return new CollectionDetails(res);
65 case ResourceKind.PROCESS:
66 return new ProcessDetails(res);
68 return new EmptyDetails(res as EmptyResource);
72 const mapStateToProps = ({ detailsPanel }: RootState) => ({
73 isOpened: detailsPanel.isOpened,
74 item: getItem(detailsPanel.item as DetailsResource)
77 const mapDispatchToProps = (dispatch: Dispatch) => ({
78 onCloseDrawer: () => {
79 dispatch(detailsPanelActions.TOGGLE_DETAILS_PANEL());
83 export interface DetailsPanelDataProps {
84 onCloseDrawer: () => void;
89 type DetailsPanelProps = DetailsPanelDataProps & WithStyles<CssRules>;
91 export const DetailsPanel = withStyles(styles)(
92 connect(mapStateToProps, mapDispatchToProps)(
93 class extends React.Component<DetailsPanelProps> {
98 handleChange = (event: any, value: boolean) => {
99 this.setState({ tabsValue: value });
102 renderTabContainer = (children: React.ReactElement<any>) =>
103 <Typography className={this.props.classes.tabContainer} component="div">
108 const { classes, onCloseDrawer, isOpened, item } = this.props;
109 const { tabsValue } = this.state;
111 <Typography component="div"
112 className={classnames([classes.container, { [classes.opened]: isOpened }])}>
113 <Drawer variant="permanent" anchor="right" classes={{ paper: classes.drawerPaper }}>
114 <Typography component="div" className={classes.headerContainer}>
115 <Grid container alignItems='center' justify='space-around'>
117 {item.getIcon(classes.headerIcon)}
120 <Typography variant="title" className={classes.headerTitle}>
125 <IconButton color="inherit" onClick={onCloseDrawer}>
131 <Tabs value={tabsValue} onChange={this.handleChange}>
132 <Tab disableRipple label="Details"/>
133 <Tab disableRipple label="Activity" disabled/>
135 {tabsValue === 0 && this.renderTabContainer(
136 <Grid container direction="column">
140 {tabsValue === 1 && this.renderTabContainer(
141 <Grid container direction="column"/>