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 '@mui/material';
7 import { CustomStyleRulesCallback } from 'common/custom-theme';
8 import { WithStyles } from '@mui/styles';
9 import withStyles from '@mui/styles/withStyles';
10 import { Transition } from 'react-transition-group';
11 import { ArvadosTheme } from 'common/custom-theme';
12 import classnames from "classnames";
13 import { connect } from 'react-redux';
14 import { RootState } from 'store/store';
15 import { CloseIcon } from 'components/icon/icon';
16 import { EmptyResource } from 'models/empty';
17 import { Dispatch } from "redux";
18 import { ResourceKind } from "models/resource";
19 import { ProjectDetails } from "./project-details";
20 import { RootProjectDetails } from './root-project-details';
21 import { CollectionDetails } from "./collection-details";
22 import { ProcessDetails } from "./process-details";
23 import { EmptyDetails } from "./empty-details";
24 import { WorkflowDetails } from "./workflow-details";
25 import { DetailsData } from "./details-data";
26 import { DetailsResource } from "models/details";
27 import { Config } from 'common/config';
28 import { isInlineFileUrlSafe } from "../context-menu/actions/helpers";
29 import { getResource } from 'store/resources/resources';
30 import { toggleDetailsPanel, SLIDE_TIMEOUT, openDetailsPanel } from 'store/details-panel/details-panel-action';
31 import { FileDetails } from 'views-components/details-panel/file-details';
32 import { getNode } from 'models/tree';
33 import { resourceIsFrozen } from 'common/frozen-resources';
34 import { CLOSE_DRAWER } from 'store/details-panel/details-panel-action';
36 type CssRules = 'root' | 'container' | 'opened' | 'headerContainer' | 'headerIcon' | 'tabContainer';
38 const DRAWER_WIDTH = 320;
39 const styles: CustomStyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
41 background: theme.palette.background.paper,
42 borderLeft: `1px solid ${theme.palette.divider}`,
45 transition: `width ${SLIDE_TIMEOUT}ms ease`,
56 color: theme.palette.grey["600"],
57 margin: `${theme.spacing(1)} 0`,
65 padding: theme.spacing(1),
69 const EMPTY_RESOURCE: EmptyResource = { kind: undefined, name: 'Projects' };
71 const getItem = (res: DetailsResource, pathName: string): DetailsData => {
74 case ResourceKind.PROJECT:
75 return new ProjectDetails(res);
76 case ResourceKind.COLLECTION:
77 return new CollectionDetails(res);
78 case ResourceKind.PROCESS:
79 return new ProcessDetails(res);
80 case ResourceKind.WORKFLOW:
81 return new WorkflowDetails(res);
82 case ResourceKind.USER:
83 if(pathName.includes('projects')) {
84 return new RootProjectDetails(res);
86 return new EmptyDetails(EMPTY_RESOURCE);
88 return new EmptyDetails(res as EmptyResource);
91 return new FileDetails(res);
95 const mapStateToProps = ({ auth, detailsPanel, resources, collectionPanelFiles, selectedResourceUuid, properties, router }: RootState) => {
96 const resource = getResource(selectedResourceUuid ?? properties.currentRouteUuid)(resources) as DetailsResource | undefined;
99 : getNode(detailsPanel.resourceUuid)(collectionPanelFiles);
101 let isFrozen = false;
103 isFrozen = resourceIsFrozen(resource, resources);
108 authConfig: auth.config,
109 isOpened: detailsPanel.isOpened,
110 tabNr: detailsPanel.tabNr,
111 res: resource || (file && file.value) || EMPTY_RESOURCE,
112 pathname: router.location ? router.location.pathname : "",
116 const mapDispatchToProps = (dispatch: Dispatch) => ({
117 onCloseDrawer: (currentItemId) => {
118 dispatch<any>(toggleDetailsPanel(currentItemId));
120 setActiveTab: (tabNr: number) => {
121 dispatch<any>(openDetailsPanel(undefined, tabNr));
125 export interface DetailsPanelDataProps {
126 onCloseDrawer: (currentItemId) => void;
127 setActiveTab: (tabNr: number) => void;
131 res: DetailsResource;
136 type DetailsPanelProps = DetailsPanelDataProps & WithStyles<CssRules>;
138 export const DetailsPanel = withStyles(styles)(
139 connect(mapStateToProps, mapDispatchToProps)(
140 class extends React.Component<DetailsPanelProps> {
141 shouldComponentUpdate(nextProps: DetailsPanelProps) {
142 if ('etag' in nextProps.res && 'etag' in this.props.res &&
143 nextProps.res.etag === this.props.res.etag &&
144 nextProps.isOpened === this.props.isOpened &&
145 nextProps.tabNr === this.props.tabNr) {
151 handleChange = (event: any, value: number) => {
152 this.props.setActiveTab(value);
156 const { classes, isOpened } = this.props;
161 className={classnames([classes.root, { [classes.opened]: isOpened }])}>
164 timeout={SLIDE_TIMEOUT}
166 {isOpened ? this.renderContent() : <div />}
173 const { classes, onCloseDrawer, res, tabNr, authConfig, pathname } = this.props;
174 let shouldShowInlinePreview = false;
175 if (!('kind' in res)) {
176 shouldShowInlinePreview = isInlineFileUrlSafe(
178 authConfig.keepWebServiceUrl,
179 authConfig.keepWebInlineServiceUrl
180 ) || authConfig.clusterConfig.Collections.TrustAllContent;
183 const item = getItem(res, pathname);
186 data-cy='details-panel'
191 className={classes.container} >
194 className={classes.headerContainer}
197 justifyContent='space-around'
200 {item.getIcon(classes.headerIcon)}
203 <Tooltip title={item.getTitle()}>
204 <Typography variant='h6' noWrap>
210 <IconButton data-cy="close-details-btn" color="inherit" onClick={()=>onCloseDrawer(CLOSE_DRAWER)} size="large">
216 <Tabs onChange={this.handleChange}
218 value={(item.getTabLabels().length >= tabNr + 1) ? tabNr : 0}>
219 {item.getTabLabels().map((tabLabel, idx) =>
220 <Tab key={`tab-label-${idx}`} data-cy={`details-panel-tab-${tabLabel}`} disableRipple label={tabLabel} />)
224 <Grid item xs className={this.props.classes.tabContainer} >
225 {item.getDetails({ tabNr, showPreview: shouldShowInlinePreview })}