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 { 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";
23 import { getResource } from '~/store/resources/resources';
24 import { ResourceData } from "~/store/resources-data/resources-data-reducer";
25 import { getResourceData } from "~/store/resources-data/resources-data";
26 import { toggleDetailsPanel, SLIDE_TIMEOUT } from '~/store/details-panel/details-panel-action';
28 type CssRules = 'root' | 'container' | 'opened' | 'headerContainer' | 'headerIcon' | 'tabContainer';
30 const DRAWER_WIDTH = 320;
31 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
33 background: theme.palette.background.paper,
34 borderLeft: `1px solid ${theme.palette.divider}`,
37 transition: `width ${SLIDE_TIMEOUT}ms ease`,
48 color: theme.palette.grey["600"],
49 margin: `${theme.spacing.unit}px 0`,
57 padding: theme.spacing.unit * 3,
61 const getItem = (resource: DetailsResource, resourceData?: ResourceData): DetailsData => {
62 const res = resource || { kind: undefined, name: 'Projects' };
64 case ResourceKind.PROJECT:
65 return new ProjectDetails(res);
66 case ResourceKind.COLLECTION:
67 return new CollectionDetails(res, resourceData);
68 case ResourceKind.PROCESS:
69 return new ProcessDetails(res);
71 return new EmptyDetails(res as EmptyResource);
75 const mapStateToProps = ({ detailsPanel, resources, resourcesData }: RootState) => {
76 const resource = getResource(detailsPanel.resourceUuid)(resources) as DetailsResource;
77 const resourceData = getResourceData(detailsPanel.resourceUuid)(resourcesData);
79 isOpened: detailsPanel.isOpened,
80 item: getItem(resource, resourceData)
84 const mapDispatchToProps = (dispatch: Dispatch) => ({
85 onCloseDrawer: () => {
86 dispatch<any>(toggleDetailsPanel());
90 export interface DetailsPanelDataProps {
91 onCloseDrawer: () => void;
96 type DetailsPanelProps = DetailsPanelDataProps & WithStyles<CssRules>;
98 export const DetailsPanel = withStyles(styles)(
99 connect(mapStateToProps, mapDispatchToProps)(
100 class extends React.Component<DetailsPanelProps> {
105 handleChange = (event: any, value: boolean) => {
106 this.setState({ tabsValue: value });
110 const { classes, isOpened } = this.props;
115 className={classnames([classes.root, { [classes.opened]: isOpened }])}>
118 timeout={SLIDE_TIMEOUT}
120 {this.renderContent()}
127 const { classes, onCloseDrawer, item } = this.props;
128 const { tabsValue } = this.state;
134 className={classes.container} >
137 className={classes.headerContainer}
140 justify='space-around'
143 {item.getIcon(classes.headerIcon)}
146 <Tooltip title={item.getTitle()}>
147 <Typography variant="title" noWrap>
153 <IconButton color="inherit" onClick={onCloseDrawer}>
159 <Tabs value={tabsValue} onChange={this.handleChange}>
160 <Tab disableRipple label="Details" />
161 <Tab disableRipple label="Activity" disabled />
164 <Grid item xs className={this.props.classes.tabContainer} >