1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import 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 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 { WorkflowDetails } from "./workflow-details";
22 import { DetailsData } from "./details-data";
23 import { DetailsResource } from "models/details";
24 import { Config } from 'common/config';
25 import { isInlineFileUrlSafe } from "../context-menu/actions/helpers";
26 import { getResource } from 'store/resources/resources';
27 import { toggleDetailsPanel, SLIDE_TIMEOUT, openDetailsPanel } from 'store/details-panel/details-panel-action';
28 import { FileDetails } from 'views-components/details-panel/file-details';
29 import { getNode } from 'models/tree';
31 type CssRules = 'root' | 'container' | 'opened' | 'headerContainer' | 'headerIcon' | 'tabContainer';
33 const DRAWER_WIDTH = 320;
34 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
36 background: theme.palette.background.paper,
37 borderLeft: `1px solid ${theme.palette.divider}`,
40 transition: `width ${SLIDE_TIMEOUT}ms ease`,
51 color: theme.palette.grey["600"],
52 margin: `${theme.spacing.unit}px 0`,
60 padding: theme.spacing.unit * 1,
64 const EMPTY_RESOURCE: EmptyResource = { kind: undefined, name: 'Projects' };
66 const getItem = (res: DetailsResource): DetailsData => {
69 case ResourceKind.PROJECT:
70 return new ProjectDetails(res);
71 case ResourceKind.COLLECTION:
72 return new CollectionDetails(res);
73 case ResourceKind.PROCESS:
74 return new ProcessDetails(res);
75 case ResourceKind.WORKFLOW:
76 return new WorkflowDetails(res);
78 return new EmptyDetails(res);
81 return new FileDetails(res);
85 const mapStateToProps = ({ auth, detailsPanel, resources, collectionPanelFiles }: RootState) => {
86 const resource = getResource(detailsPanel.resourceUuid)(resources) as DetailsResource | undefined;
89 : getNode(detailsPanel.resourceUuid)(collectionPanelFiles);
91 authConfig: auth.config,
92 isOpened: detailsPanel.isOpened,
93 tabNr: detailsPanel.tabNr,
94 res: resource || (file && file.value) || EMPTY_RESOURCE,
98 const mapDispatchToProps = (dispatch: Dispatch) => ({
99 onCloseDrawer: () => {
100 dispatch<any>(toggleDetailsPanel());
102 setActiveTab: (tabNr: number) => {
103 dispatch<any>(openDetailsPanel(undefined, tabNr));
107 export interface DetailsPanelDataProps {
108 onCloseDrawer: () => void;
109 setActiveTab: (tabNr: number) => void;
113 res: DetailsResource;
116 type DetailsPanelProps = DetailsPanelDataProps & WithStyles<CssRules>;
118 export const DetailsPanel = withStyles(styles)(
119 connect(mapStateToProps, mapDispatchToProps)(
120 class extends React.Component<DetailsPanelProps> {
121 shouldComponentUpdate(nextProps: DetailsPanelProps) {
122 if ('etag' in nextProps.res && 'etag' in this.props.res &&
123 nextProps.res.etag === this.props.res.etag &&
124 nextProps.isOpened === this.props.isOpened &&
125 nextProps.tabNr === this.props.tabNr) {
131 handleChange = (event: any, value: number) => {
132 this.props.setActiveTab(value);
136 const { classes, isOpened } = this.props;
141 className={classnames([classes.root, { [classes.opened]: isOpened }])}>
144 timeout={SLIDE_TIMEOUT}
146 {isOpened ? this.renderContent() : <div />}
153 const { classes, onCloseDrawer, res, tabNr, authConfig } = this.props;
155 let shouldShowInlinePreview = false;
156 if (!('kind' in res)) {
157 shouldShowInlinePreview = isInlineFileUrlSafe(
159 authConfig.keepWebServiceUrl,
160 authConfig.keepWebInlineServiceUrl
161 ) || authConfig.clusterConfig.Collections.TrustAllContent;
164 const item = getItem(res);
166 data-cy='details-panel'
171 className={classes.container} >
174 className={classes.headerContainer}
177 justify='space-around'
180 {item.getIcon(classes.headerIcon)}
183 <Tooltip title={item.getTitle()}>
184 <Typography variant='h6' noWrap>
190 <IconButton color="inherit" onClick={onCloseDrawer}>
196 <Tabs onChange={this.handleChange}
197 value={(item.getTabLabels().length >= tabNr + 1) ? tabNr : 0}>
198 {item.getTabLabels().map((tabLabel, idx) =>
199 <Tab key={`tab-label-${idx}`} disableRipple label={tabLabel} />)
203 <Grid item xs className={this.props.classes.tabContainer} >
204 {item.getDetails({ tabNr, showPreview: shouldShowInlinePreview })}