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';
30 import { resourceIsFrozen } from 'common/frozen-resources';
32 type CssRules = 'root' | 'container' | 'opened' | 'headerContainer' | 'headerIcon' | 'tabContainer';
34 const DRAWER_WIDTH = 320;
35 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
37 background: theme.palette.background.paper,
38 borderLeft: `1px solid ${theme.palette.divider}`,
41 transition: `width ${SLIDE_TIMEOUT}ms ease`,
52 color: theme.palette.grey["600"],
53 margin: `${theme.spacing.unit}px 0`,
61 padding: theme.spacing.unit * 1,
65 const EMPTY_RESOURCE: EmptyResource = { kind: undefined, name: 'Projects' };
67 const getItem = (res: DetailsResource): DetailsData => {
70 case ResourceKind.PROJECT:
71 return new ProjectDetails(res);
72 case ResourceKind.COLLECTION:
73 return new CollectionDetails(res);
74 case ResourceKind.PROCESS:
75 return new ProcessDetails(res);
76 case ResourceKind.WORKFLOW:
77 return new WorkflowDetails(res);
79 return new EmptyDetails(res);
82 return new FileDetails(res);
86 const mapStateToProps = ({ auth, detailsPanel, resources, collectionPanelFiles }: RootState) => {
87 const resource = getResource(detailsPanel.resourceUuid)(resources) as DetailsResource | undefined;
90 : getNode(detailsPanel.resourceUuid)(collectionPanelFiles);
94 isFrozen = resourceIsFrozen(resource, resources);
99 authConfig: auth.config,
100 isOpened: detailsPanel.isOpened,
101 tabNr: detailsPanel.tabNr,
102 res: resource || (file && file.value) || EMPTY_RESOURCE,
106 const mapDispatchToProps = (dispatch: Dispatch) => ({
107 onCloseDrawer: () => {
108 dispatch<any>(toggleDetailsPanel());
110 setActiveTab: (tabNr: number) => {
111 dispatch<any>(openDetailsPanel(undefined, tabNr));
115 export interface DetailsPanelDataProps {
116 onCloseDrawer: () => void;
117 setActiveTab: (tabNr: number) => void;
121 res: DetailsResource;
125 type DetailsPanelProps = DetailsPanelDataProps & WithStyles<CssRules>;
127 export const DetailsPanel = withStyles(styles)(
128 connect(mapStateToProps, mapDispatchToProps)(
129 class extends React.Component<DetailsPanelProps> {
130 shouldComponentUpdate(nextProps: DetailsPanelProps) {
131 if ('etag' in nextProps.res && 'etag' in this.props.res &&
132 nextProps.res.etag === this.props.res.etag &&
133 nextProps.isOpened === this.props.isOpened &&
134 nextProps.tabNr === this.props.tabNr) {
140 handleChange = (event: any, value: number) => {
141 this.props.setActiveTab(value);
145 const { classes, isOpened } = this.props;
150 className={classnames([classes.root, { [classes.opened]: isOpened }])}>
153 timeout={SLIDE_TIMEOUT}
155 {isOpened ? this.renderContent() : <div />}
162 const { classes, onCloseDrawer, res, tabNr, authConfig } = this.props;
164 let shouldShowInlinePreview = false;
165 if (!('kind' in res)) {
166 shouldShowInlinePreview = isInlineFileUrlSafe(
168 authConfig.keepWebServiceUrl,
169 authConfig.keepWebInlineServiceUrl
170 ) || authConfig.clusterConfig.Collections.TrustAllContent;
173 const item = getItem(res);
175 data-cy='details-panel'
180 className={classes.container} >
183 className={classes.headerContainer}
186 justify='space-around'
189 {item.getIcon(classes.headerIcon)}
192 <Tooltip title={item.getTitle()}>
193 <Typography variant='h6' noWrap>
199 <IconButton color="inherit" onClick={onCloseDrawer}>
205 <Tabs onChange={this.handleChange}
206 value={(item.getTabLabels().length >= tabNr + 1) ? tabNr : 0}>
207 {item.getTabLabels().map((tabLabel, idx) =>
208 <Tab key={`tab-label-${idx}`} disableRipple label={tabLabel} />)
212 <Grid item xs className={this.props.classes.tabContainer} >
213 {item.getDetails({ tabNr, showPreview: shouldShowInlinePreview })}