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';
25 import { ResourceData } from "~/store/resources-data/resources-data-reducer";
26 import { getResourceData } from "~/store/resources-data/resources-data";
28 type CssRules = 'root' | 'container' | 'opened' | 'headerContainer' | 'headerIcon' | 'tabContainer';
30 const DRAWER_WIDTH = 320;
31 const SLIDE_TIMEOUT = 500;
32 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
34 background: theme.palette.background.paper,
35 borderLeft: `1px solid ${theme.palette.divider}`,
38 transition: `width ${SLIDE_TIMEOUT}ms ease`,
49 color: theme.palette.grey["600"],
50 margin: `${theme.spacing.unit}px 0`,
58 padding: theme.spacing.unit * 3,
62 const getItem = (resource: DetailsResource, resourceData?: ResourceData): DetailsData => {
63 const res = resource || { kind: undefined, name: 'Projects' };
65 case ResourceKind.PROJECT:
66 return new ProjectDetails(res);
67 case ResourceKind.COLLECTION:
68 return new CollectionDetails(res, resourceData);
69 case ResourceKind.PROCESS:
70 return new ProcessDetails(res);
72 return new EmptyDetails(res as EmptyResource);
76 const mapStateToProps = ({ detailsPanel, resources, resourcesData }: RootState) => {
77 const resource = getResource(detailsPanel.resourceUuid)(resources) as DetailsResource;
78 const resourceData = getResourceData(detailsPanel.resourceUuid)(resourcesData);
80 isOpened: detailsPanel.isOpened,
81 item: getItem(resource, resourceData)
85 const mapDispatchToProps = (dispatch: Dispatch) => ({
86 onCloseDrawer: () => {
87 dispatch(detailsPanelActions.TOGGLE_DETAILS_PANEL());
91 export interface DetailsPanelDataProps {
92 onCloseDrawer: () => void;
97 type DetailsPanelProps = DetailsPanelDataProps & WithStyles<CssRules>;
99 export const DetailsPanel = withStyles(styles)(
100 connect(mapStateToProps, mapDispatchToProps)(
101 class extends React.Component<DetailsPanelProps> {
106 handleChange = (event: any, value: boolean) => {
107 this.setState({ tabsValue: value });
111 const { classes, isOpened } = this.props;
116 className={classnames([classes.root, { [classes.opened]: isOpened }])}>
119 timeout={SLIDE_TIMEOUT}
121 {this.renderContent()}
128 const { classes, onCloseDrawer, item } = this.props;
129 const { tabsValue } = this.state;
135 className={classes.container} >
138 className={classes.headerContainer}
141 justify='space-around'
144 {item.getIcon(classes.headerIcon)}
147 <Tooltip title={item.getTitle()}>
148 <Typography variant="title" noWrap>
154 <IconButton color="inherit" onClick={onCloseDrawer}>
160 <Tabs value={tabsValue} onChange={this.handleChange}>
161 <Tab disableRipple label="Details" />
162 <Tab disableRipple label="Activity" disabled />
165 <Grid item xs className={this.props.classes.tabContainer} >