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';
27 import { FileDetails } from '~/views-components/details-panel/file-details';
28 import { getNode } from '~/models/tree';
30 type CssRules = 'root' | 'container' | 'opened' | 'headerContainer' | 'headerIcon' | 'tabContainer';
32 const DRAWER_WIDTH = 320;
33 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
35 background: theme.palette.background.paper,
36 borderLeft: `1px solid ${theme.palette.divider}`,
39 transition: `width ${SLIDE_TIMEOUT}ms ease`,
50 color: theme.palette.grey["600"],
51 margin: `${theme.spacing.unit}px 0`,
59 padding: theme.spacing.unit * 3,
63 const EMPTY_RESOURCE: EmptyResource = { kind: undefined, name: 'Projects' };
65 const getItem = (res: DetailsResource, resourceData?: ResourceData): DetailsData => {
68 case ResourceKind.PROJECT:
69 return new ProjectDetails(res);
70 case ResourceKind.COLLECTION:
71 return new CollectionDetails(res, resourceData);
72 case ResourceKind.PROCESS:
73 return new ProcessDetails(res);
75 return new EmptyDetails(res);
78 return new FileDetails(res);
82 const mapStateToProps = ({ detailsPanel, resources, resourcesData, collectionPanelFiles }: RootState) => {
83 const resource = getResource(detailsPanel.resourceUuid)(resources) as DetailsResource | undefined;
84 const file = getNode(detailsPanel.resourceUuid)(collectionPanelFiles);
85 const resourceData = getResourceData(detailsPanel.resourceUuid)(resourcesData);
87 isOpened: detailsPanel.isOpened,
88 item: getItem(resource || (file && file.value) || EMPTY_RESOURCE, resourceData)
92 const mapDispatchToProps = (dispatch: Dispatch) => ({
93 onCloseDrawer: () => {
94 dispatch<any>(toggleDetailsPanel());
98 export interface DetailsPanelDataProps {
99 onCloseDrawer: () => void;
104 type DetailsPanelProps = DetailsPanelDataProps & WithStyles<CssRules>;
106 export const DetailsPanel = withStyles(styles)(
107 connect(mapStateToProps, mapDispatchToProps)(
108 class extends React.Component<DetailsPanelProps> {
113 handleChange = (event: any, value: boolean) => {
114 this.setState({ tabsValue: value });
118 const { classes, isOpened } = this.props;
123 className={classnames([classes.root, { [classes.opened]: isOpened }])}>
126 timeout={SLIDE_TIMEOUT}
128 {this.renderContent()}
135 const { classes, onCloseDrawer, item } = this.props;
136 const { tabsValue } = this.state;
142 className={classes.container} >
145 className={classes.headerContainer}
148 justify='space-around'
151 {item.getIcon(classes.headerIcon)}
154 <Tooltip title={item.getTitle()}>
155 <Typography variant="title" noWrap>
161 <IconButton color="inherit" onClick={onCloseDrawer}>
167 <Tabs value={tabsValue} onChange={this.handleChange}>
168 <Tab disableRipple label="Details" />
169 <Tab disableRipple label="Activity" disabled />
172 <Grid item xs className={this.props.classes.tabContainer} >