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 { CustomStyleRulesCallback } from 'common/custom-theme';
8 import { WithStyles, withStyles } from '@material-ui/core/styles';
9 import { Transition } from 'react-transition-group';
10 import { ArvadosTheme } from 'common/custom-theme';
11 import classnames from "classnames";
12 import { connect } from 'react-redux';
13 import { RootState } from 'store/store';
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 { RootProjectDetails } from './root-project-details';
20 import { CollectionDetails } from "./collection-details";
21 import { ProcessDetails } from "./process-details";
22 import { EmptyDetails } from "./empty-details";
23 import { WorkflowDetails } from "./workflow-details";
24 import { DetailsData } from "./details-data";
25 import { DetailsResource } from "models/details";
26 import { Config } from 'common/config';
27 import { isInlineFileUrlSafe } from "../context-menu/actions/helpers";
28 import { getResource } from 'store/resources/resources';
29 import { toggleDetailsPanel, SLIDE_TIMEOUT, openDetailsPanel } from 'store/details-panel/details-panel-action';
30 import { FileDetails } from 'views-components/details-panel/file-details';
31 import { getNode } from 'models/tree';
32 import { resourceIsFrozen } from 'common/frozen-resources';
33 import { CLOSE_DRAWER } from 'store/details-panel/details-panel-action';
35 type CssRules = 'root' | 'container' | 'opened' | 'headerContainer' | 'headerIcon' | 'tabContainer';
37 const DRAWER_WIDTH = 320;
38 const styles: CustomStyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
40 background: theme.palette.background.paper,
41 borderLeft: `1px solid ${theme.palette.divider}`,
44 transition: `width ${SLIDE_TIMEOUT}ms ease`,
55 color: theme.palette.grey["600"],
56 margin: `${theme.spacing(1)}px 0`,
64 padding: theme.spacing(1),
68 const EMPTY_RESOURCE: EmptyResource = { kind: undefined, name: 'Projects' };
70 const getItem = (res: DetailsResource, pathName: string): DetailsData => {
73 case ResourceKind.PROJECT:
74 return new ProjectDetails(res);
75 case ResourceKind.COLLECTION:
76 return new CollectionDetails(res);
77 case ResourceKind.PROCESS:
78 return new ProcessDetails(res);
79 case ResourceKind.WORKFLOW:
80 return new WorkflowDetails(res);
81 case ResourceKind.USER:
82 if(pathName.includes('projects')) {
83 return new RootProjectDetails(res);
85 return new EmptyDetails(EMPTY_RESOURCE);
87 return new EmptyDetails(res as EmptyResource);
90 return new FileDetails(res);
94 const mapStateToProps = ({ auth, detailsPanel, resources, collectionPanelFiles, selectedResourceUuid, properties, router }: RootState) => {
95 const resource = getResource(selectedResourceUuid ?? properties.currentRouteUuid)(resources) as DetailsResource | undefined;
98 : getNode(detailsPanel.resourceUuid)(collectionPanelFiles);
100 let isFrozen = false;
102 isFrozen = resourceIsFrozen(resource, resources);
107 authConfig: auth.config,
108 isOpened: detailsPanel.isOpened,
109 tabNr: detailsPanel.tabNr,
110 res: resource || (file && file.value) || EMPTY_RESOURCE,
111 pathname: router.location ? router.location.pathname : "",
115 const mapDispatchToProps = (dispatch: Dispatch) => ({
116 onCloseDrawer: (currentItemId) => {
117 dispatch<any>(toggleDetailsPanel(currentItemId));
119 setActiveTab: (tabNr: number) => {
120 dispatch<any>(openDetailsPanel(undefined, tabNr));
124 export interface DetailsPanelDataProps {
125 onCloseDrawer: (currentItemId) => void;
126 setActiveTab: (tabNr: number) => void;
130 res: DetailsResource;
135 type DetailsPanelProps = DetailsPanelDataProps & WithStyles<CssRules>;
137 export const DetailsPanel = withStyles(styles)(
138 connect(mapStateToProps, mapDispatchToProps)(
139 class extends React.Component<DetailsPanelProps> {
140 shouldComponentUpdate(nextProps: DetailsPanelProps) {
141 if ('etag' in nextProps.res && 'etag' in this.props.res &&
142 nextProps.res.etag === this.props.res.etag &&
143 nextProps.isOpened === this.props.isOpened &&
144 nextProps.tabNr === this.props.tabNr) {
150 handleChange = (event: any, value: number) => {
151 this.props.setActiveTab(value);
155 const { classes, isOpened } = this.props;
160 className={classnames([classes.root, { [classes.opened]: isOpened }])}>
163 timeout={SLIDE_TIMEOUT}
165 {isOpened ? this.renderContent() : <div />}
172 const { classes, onCloseDrawer, res, tabNr, authConfig, pathname } = this.props;
173 let shouldShowInlinePreview = false;
174 if (!('kind' in res)) {
175 shouldShowInlinePreview = isInlineFileUrlSafe(
177 authConfig.keepWebServiceUrl,
178 authConfig.keepWebInlineServiceUrl
179 ) || authConfig.clusterConfig.Collections.TrustAllContent;
182 const item = getItem(res, pathname);
184 data-cy='details-panel'
189 className={classes.container} >
192 className={classes.headerContainer}
195 justify='space-around'
198 {item.getIcon(classes.headerIcon)}
201 <Tooltip title={item.getTitle()}>
202 <Typography variant='h6' noWrap>
208 <IconButton color="inherit" onClick={()=>onCloseDrawer(CLOSE_DRAWER)}>
214 <Tabs onChange={this.handleChange}
215 value={(item.getTabLabels().length >= tabNr + 1) ? tabNr : 0}>
216 {item.getTabLabels().map((tabLabel, idx) =>
217 <Tab key={`tab-label-${idx}`} disableRipple label={tabLabel} />)
221 <Grid item xs className={this.props.classes.tabContainer} >
222 {item.getDetails({ tabNr, showPreview: shouldShowInlinePreview })}