1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
6 import { IconButton, Tabs, Tab, Typography, Grid, Tooltip } from '@material-ui/core';
7 import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core/styles';
8 import { Transition } from 'react-transition-group';
9 import { ArvadosTheme } from '~/common/custom-theme';
10 import * as classnames from "classnames";
11 import { connect } from 'react-redux';
12 import { RootState } from '~/store/store';
13 import { detailsPanelActions } from "~/store/details-panel/details-panel-action";
14 import { CloseIcon } from '~/components/icon/icon';
15 import { EmptyResource } from '~/models/empty';
16 import { Dispatch } from "redux";
17 import { ResourceKind } from "~/models/resource";
18 import { ProjectDetails } from "./project-details";
19 import { CollectionDetails } from "./collection-details";
20 import { ProcessDetails } from "./process-details";
21 import { EmptyDetails } from "./empty-details";
22 import { DetailsData } from "./details-data";
23 import { DetailsResource } from "~/models/details";
24 import { getResource } from '~/store/resources/resources';
26 type CssRules = 'root' | 'container' | 'opened' | 'headerContainer' | 'headerIcon' | 'tabContainer';
28 const DRAWER_WIDTH = 320;
29 const SLIDE_TIMEOUT = 500;
30 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
32 background: theme.palette.background.paper,
33 borderLeft: `1px solid ${theme.palette.divider}`,
36 transition: `width ${SLIDE_TIMEOUT}ms ease`,
47 color: theme.palette.grey["600"],
48 margin: `${theme.spacing.unit}px 0`,
56 padding: theme.spacing.unit * 3,
60 const getItem = (resource: DetailsResource): DetailsData => {
61 const res = resource || { kind: undefined, name: 'Projects' };
63 case ResourceKind.PROJECT:
64 return new ProjectDetails(res);
65 case ResourceKind.COLLECTION:
66 return new CollectionDetails(res);
67 case ResourceKind.PROCESS:
68 return new ProcessDetails(res);
70 return new EmptyDetails(res as EmptyResource);
74 const mapStateToProps = ({ detailsPanel, resources }: RootState) => {
75 const resource = getResource(detailsPanel.resourceUuid)(resources) as DetailsResource;
77 isOpened: detailsPanel.isOpened,
78 item: getItem(resource)
82 const mapDispatchToProps = (dispatch: Dispatch) => ({
83 onCloseDrawer: () => {
84 dispatch(detailsPanelActions.TOGGLE_DETAILS_PANEL());
88 export interface DetailsPanelDataProps {
89 onCloseDrawer: () => void;
94 type DetailsPanelProps = DetailsPanelDataProps & WithStyles<CssRules>;
96 export const DetailsPanel = withStyles(styles)(
97 connect(mapStateToProps, mapDispatchToProps)(
98 class extends React.Component<DetailsPanelProps> {
103 handleChange = (event: any, value: boolean) => {
104 this.setState({ tabsValue: value });
108 const { classes, isOpened } = this.props;
113 className={classnames([classes.root, { [classes.opened]: isOpened }])}>
116 timeout={SLIDE_TIMEOUT}
118 {this.renderContent()}
125 const { classes, onCloseDrawer, item } = this.props;
126 const { tabsValue } = this.state;
132 className={classes.container} >
135 className={classes.headerContainer}
138 justify='space-around'
141 {item.getIcon(classes.headerIcon)}
144 <Tooltip title={item.getTitle()}>
145 <Typography variant="title" noWrap>
151 <IconButton color="inherit" onClick={onCloseDrawer}>
157 <Tabs value={tabsValue} onChange={this.handleChange}>
158 <Tab disableRipple label="Details" />
159 <Tab disableRipple label="Activity" disabled />
162 <Grid item xs className={this.props.classes.tabContainer} >