1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from 'react';
14 Card, CardHeader, CardContent
15 } from '@material-ui/core';
16 import { connect, DispatchProp } from "react-redux";
17 import { RouteComponentProps } from 'react-router';
18 import { ArvadosTheme } from 'common/custom-theme';
19 import { RootState } from 'store/store';
20 import { MoreOptionsIcon, CollectionIcon, ReadOnlyIcon, CollectionOldVersionIcon } from 'components/icon/icon';
21 import { DetailsAttribute } from 'components/details-attribute/details-attribute';
22 import { CollectionResource, getCollectionUrl } from 'models/collection';
23 import { CollectionPanelFiles } from 'views-components/collection-panel-files/collection-panel-files';
24 import { navigateToProcess } from 'store/collection-panel/collection-panel-action';
25 import { getResource } from 'store/resources/resources';
26 import { openContextMenu, resourceUuidToContextMenuKind } from 'store/context-menu/context-menu-actions';
27 import { formatDate, formatFileSize } from "common/formatters";
28 import { openDetailsPanel } from 'store/details-panel/details-panel-action';
29 import { snackbarActions, SnackbarKind } from 'store/snackbar/snackbar-actions';
30 import { getPropertyChip } from 'views-components/resource-properties-form/property-chip';
31 import { IllegalNamingWarning } from 'components/warning/warning';
32 import { GroupResource } from 'models/group';
33 import { UserResource } from 'models/user';
34 import { getUserUuid } from 'common/getuser';
35 import { Link } from 'react-router-dom';
36 import { Link as ButtonLink } from '@material-ui/core';
37 import { ResourceWithName, ResponsiblePerson } from 'views-components/data-explorer/renderers';
38 import { MPVContainer, MPVPanelContent, MPVPanelState } from 'components/multi-panel-view/multi-panel-view';
39 import { resourceIsFrozen } from 'common/frozen-resources';
41 type CssRules = 'root'
60 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
77 color: theme.customs.colors.greyL
80 marginRight: theme.spacing.unit / 2,
81 marginBottom: theme.spacing.unit / 2
94 flexDirection: 'column',
97 textTransform: 'none',
101 fontSize: '0.875rem',
102 color: theme.palette.primary.main,
108 marginLeft: theme.spacing.unit,
112 paddingTop: theme.spacing.unit,
113 paddingBottom: theme.spacing.unit,
117 paddingTop: theme.spacing.unit * 0.5,
118 color: theme.customs.colors.green700,
121 alignSelf: 'flex-start',
122 paddingTop: theme.spacing.unit * 0.5
125 padding: theme.spacing.unit * 1.0,
126 paddingTop: theme.spacing.unit * 0.5,
128 paddingBottom: theme.spacing.unit * 1,
133 interface CollectionPanelDataProps {
134 item: CollectionResource;
136 isOldVersion: boolean;
137 isLoadingFiles: boolean;
140 type CollectionPanelProps = CollectionPanelDataProps & DispatchProp & WithStyles<CssRules>
142 export const CollectionPanel = withStyles(styles)(connect(
143 (state: RootState, props: RouteComponentProps<{ id: string }>) => {
144 const currentUserUUID = getUserUuid(state);
145 const item = getResource<CollectionResource>(props.match.params.id)(state.resources);
146 let isWritable = false;
147 const isOldVersion = item && item.currentVersionUuid !== item.uuid;
148 if (item && !isOldVersion) {
149 if (item.ownerUuid === currentUserUUID) {
152 const itemOwner = getResource<GroupResource | UserResource>(item.ownerUuid)(state.resources);
153 if (itemOwner && itemOwner.writableBy) {
154 isWritable = itemOwner.writableBy.indexOf(currentUserUUID || '') >= 0;
159 if (item && isWritable) {
160 isWritable = !resourceIsFrozen(item, state.resources);
163 return { item, isWritable, isOldVersion };
165 class extends React.Component<CollectionPanelProps> {
167 const { classes, item, dispatch, isWritable, isOldVersion } = this.props;
168 const panelsData: MPVPanelState[] = [
173 ? <MPVContainer className={classes.root} spacing={8} direction="column" justify-content="flex-start" wrap="nowrap" panelStates={panelsData}>
174 <MPVPanelContent xs="auto" data-cy='collection-info-panel'>
175 <Card className={classes.infoCard}>
177 className={classes.header}
179 content: classes.title,
180 avatar: classes.avatar,
182 avatar={<IconButton onClick={this.openCollectionDetails}>
184 ? <CollectionOldVersionIcon className={classes.iconHeader} />
185 : <CollectionIcon className={classes.iconHeader} />}
189 <IllegalNamingWarning name={item.name} />
192 <Tooltip title="Read-only">
193 <ReadOnlyIcon data-cy="read-only-icon" className={classes.readOnlyIcon} />
198 <Tooltip title="Actions" disableFocusListener>
200 data-cy='collection-panel-options-btn'
202 onClick={this.handleContextMenu}>
208 <CardContent className={classes.content}>
209 <Typography variant="caption">
212 <CollectionDetailsAttributes item={item} classes={classes} twoCol={true} showVersionBrowser={() => dispatch<any>(openDetailsPanel(item.uuid, 1))} />
213 {(item.properties.container_request || item.properties.containerRequest) &&
214 <span onClick={() => dispatch<any>(navigateToProcess(item.properties.container_request || item.properties.containerRequest))}>
215 <DetailsAttribute classLabel={classes.link} label='Link to process' />
219 <Typography className={classes.warningLabel} variant="caption">
220 This is an old version. Make a copy to make changes. Go to the <Link to={getCollectionUrl(item.currentVersionUuid)}>head version</Link> for sharing options.
227 <Card className={classes.filesCard}>
228 <CollectionPanelFiles isWritable={isWritable} />
235 handleContextMenu = (event: React.MouseEvent<any>) => {
236 const { uuid, ownerUuid, name, description,
237 kind, storageClassesDesired, properties } = this.props.item;
238 const menuKind = this.props.dispatch<any>(resourceUuidToContextMenuKind(uuid));
244 storageClassesDesired,
249 // Avoid expanding/collapsing the panel
250 event.stopPropagation();
251 this.props.dispatch<any>(openContextMenu(event, resource));
254 onCopy = (message: string) =>
255 this.props.dispatch(snackbarActions.OPEN_SNACKBAR({
258 kind: SnackbarKind.SUCCESS
261 openCollectionDetails = (e: React.MouseEvent<HTMLElement>) => {
262 const { item } = this.props;
265 this.props.dispatch<any>(openDetailsPanel(item.uuid));
270 onClick: this.openCollectionDetails
277 interface CollectionDetailsProps {
278 item: CollectionResource;
281 showVersionBrowser?: () => void;
284 export const CollectionDetailsAttributes = (props: CollectionDetailsProps) => {
285 const item = props.item;
286 const classes = props.classes || { label: '', value: '', button: '', tag: '' };
287 const isOldVersion = item && item.currentVersionUuid !== item.uuid;
288 const mdSize = props.twoCol ? 6 : 12;
289 const showVersionBrowser = props.showVersionBrowser;
290 const responsiblePersonRef = React.useRef(null);
291 return <Grid container>
292 <Grid item xs={12} md={mdSize}>
293 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
294 label={isOldVersion ? "This version's UUID" : "Collection UUID"}
295 linkToUuid={item.uuid} />
297 <Grid item xs={12} md={mdSize}>
298 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
299 label={isOldVersion ? "This version's PDH" : "Portable data hash"}
300 linkToUuid={item.portableDataHash} />
302 <Grid item xs={12} md={mdSize}>
303 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
304 label='Owner' linkToUuid={item.ownerUuid}
305 uuidEnhancer={(uuid: string) => <ResourceWithName uuid={uuid} />} />
307 <div data-cy="responsible-person-wrapper" ref={responsiblePersonRef}>
308 <Grid item xs={12} md={12}>
309 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
310 label='Responsible person' linkToUuid={item.ownerUuid}
311 uuidEnhancer={(uuid: string) => <ResponsiblePerson uuid={item.uuid} parentRef={responsiblePersonRef.current} />} />
314 <Grid item xs={12} md={mdSize}>
315 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
317 value={isOldVersion ? undefined : 'this one'}
318 linkToUuid={isOldVersion ? item.currentVersionUuid : undefined} />
320 <Grid item xs={12} md={mdSize}>
322 classLabel={classes.label} classValue={classes.value}
323 label='Version number'
324 value={showVersionBrowser !== undefined
325 ? <Tooltip title="Open version browser"><ButtonLink underline='none' className={classes.button} onClick={() => showVersionBrowser()}>
326 {<span data-cy='collection-version-number'>{item.version}</span>}
327 </ButtonLink></Tooltip>
332 <Grid item xs={12} md={mdSize}>
333 <DetailsAttribute label='Created at' value={formatDate(item.createdAt)} />
335 <Grid item xs={12} md={mdSize}>
336 <DetailsAttribute label='Last modified' value={formatDate(item.modifiedAt)} />
338 <Grid item xs={12} md={mdSize}>
339 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
340 label='Number of files' value={<span data-cy='collection-file-count'>{item.fileCount}</span>} />
342 <Grid item xs={12} md={mdSize}>
343 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
344 label='Content size' value={formatFileSize(item.fileSizeTotal)} />
346 <Grid item xs={12} md={mdSize}>
347 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
348 label='Storage classes' value={item.storageClassesDesired.join(', ')} />
352 NOTE: The property list should be kept at the bottom, because it spans
353 the entire available width, without regards of the twoCol prop.
355 <Grid item xs={12} md={12}>
356 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
357 label='Properties' />
358 {Object.keys(item.properties).length > 0
359 ? Object.keys(item.properties).map(k =>
360 Array.isArray(item.properties[k])
361 ? item.properties[k].map((v: string) =>
362 getPropertyChip(k, v, undefined, classes.tag))
363 : getPropertyChip(k, item.properties[k], undefined, classes.tag))
364 : <div className={classes.value}>No properties</div>}