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 { MoreVerticalIcon, 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';
40 import { NotFoundView } from 'views/not-found-panel/not-found-panel';
42 type CssRules = 'root'
61 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
78 color: theme.customs.colors.greyL
81 marginRight: theme.spacing.unit / 2,
82 marginBottom: theme.spacing.unit / 2
95 flexDirection: 'column',
98 textTransform: 'none',
102 fontSize: '0.875rem',
103 color: theme.palette.primary.main,
109 marginLeft: theme.spacing.unit,
113 paddingTop: theme.spacing.unit,
114 paddingBottom: theme.spacing.unit,
118 paddingTop: theme.spacing.unit * 0.5,
119 color: theme.customs.colors.green700,
122 alignSelf: 'flex-start',
123 paddingTop: theme.spacing.unit * 0.5
126 padding: theme.spacing.unit * 1.0,
127 paddingTop: theme.spacing.unit * 0.5,
129 paddingBottom: theme.spacing.unit * 1,
134 interface CollectionPanelDataProps {
135 item: CollectionResource;
137 isOldVersion: boolean;
138 isLoadingFiles: boolean;
141 type CollectionPanelProps = CollectionPanelDataProps & DispatchProp & WithStyles<CssRules>
143 export const CollectionPanel = withStyles(styles)(connect(
144 (state: RootState, props: RouteComponentProps<{ id: string }>) => {
145 const currentUserUUID = getUserUuid(state);
146 const item = getResource<CollectionResource>(props.match.params.id)(state.resources);
147 let isWritable = false;
148 const isOldVersion = item && item.currentVersionUuid !== item.uuid;
149 if (item && !isOldVersion) {
150 if (item.ownerUuid === currentUserUUID) {
153 const itemOwner = getResource<GroupResource | UserResource>(item.ownerUuid)(state.resources);
155 isWritable = itemOwner.canWrite;
160 if (item && isWritable) {
161 isWritable = !resourceIsFrozen(item, state.resources);
164 return { item, isWritable, isOldVersion };
166 class extends React.Component<CollectionPanelProps> {
168 const { classes, item, dispatch, isWritable, isOldVersion } = this.props;
169 const panelsData: MPVPanelState[] = [
174 ? <MPVContainer className={classes.root} spacing={8} direction="column" justify-content="flex-start" wrap="nowrap" panelStates={panelsData}>
175 <MPVPanelContent xs="auto" data-cy='collection-info-panel'>
176 <Card className={classes.infoCard}>
178 className={classes.header}
180 content: classes.title,
181 avatar: classes.avatar,
183 avatar={<IconButton onClick={this.openCollectionDetails}>
185 ? <CollectionOldVersionIcon className={classes.iconHeader} />
186 : <CollectionIcon className={classes.iconHeader} />}
190 <IllegalNamingWarning name={item.name} />
193 <Tooltip title="Read-only">
194 <ReadOnlyIcon data-cy="read-only-icon" className={classes.readOnlyIcon} />
199 <Tooltip title="Actions" disableFocusListener>
201 data-cy='collection-panel-options-btn'
203 onClick={this.handleContextMenu}>
209 <CardContent className={classes.content}>
210 <Typography variant="caption">
213 <CollectionDetailsAttributes item={item} classes={classes} twoCol={true} showVersionBrowser={() => dispatch<any>(openDetailsPanel(item.uuid, 1))} />
214 {(item.properties.container_request || item.properties.containerRequest) &&
215 <span onClick={() => dispatch<any>(navigateToProcess(item.properties.container_request || item.properties.containerRequest))}>
216 <DetailsAttribute classLabel={classes.link} label='Link to process' />
220 <Typography className={classes.warningLabel} variant="caption">
221 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.
228 <Card className={classes.filesCard}>
229 <CollectionPanelFiles isWritable={isWritable} />
234 icon={CollectionIcon}
235 messages={["Collection not found"]}
240 handleContextMenu = (event: React.MouseEvent<any>) => {
241 const { uuid, ownerUuid, name, description,
242 kind, storageClassesDesired, properties } = this.props.item;
243 const menuKind = this.props.dispatch<any>(resourceUuidToContextMenuKind(uuid));
249 storageClassesDesired,
254 // Avoid expanding/collapsing the panel
255 event.stopPropagation();
256 this.props.dispatch<any>(openContextMenu(event, resource));
259 onCopy = (message: string) =>
260 this.props.dispatch(snackbarActions.OPEN_SNACKBAR({
263 kind: SnackbarKind.SUCCESS
266 openCollectionDetails = (e: React.MouseEvent<HTMLElement>) => {
267 const { item } = this.props;
270 this.props.dispatch<any>(openDetailsPanel(item.uuid));
275 onClick: this.openCollectionDetails
282 interface CollectionDetailsProps {
283 item: CollectionResource;
286 showVersionBrowser?: () => void;
289 export const CollectionDetailsAttributes = (props: CollectionDetailsProps) => {
290 const item = props.item;
291 const classes = props.classes || { label: '', value: '', button: '', tag: '' };
292 const isOldVersion = item && item.currentVersionUuid !== item.uuid;
293 const mdSize = props.twoCol ? 6 : 12;
294 const showVersionBrowser = props.showVersionBrowser;
295 const responsiblePersonRef = React.useRef(null);
296 return <Grid container>
297 <Grid item xs={12} md={mdSize}>
298 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
299 label={isOldVersion ? "This version's UUID" : "Collection UUID"}
300 linkToUuid={item.uuid} />
302 <Grid item xs={12} md={mdSize}>
303 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
304 label={isOldVersion ? "This version's PDH" : "Portable data hash"}
305 linkToUuid={item.portableDataHash} />
307 <Grid item xs={12} md={mdSize}>
308 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
309 label='Owner' linkToUuid={item.ownerUuid}
310 uuidEnhancer={(uuid: string) => <ResourceWithName uuid={uuid} />} />
312 <div data-cy="responsible-person-wrapper" ref={responsiblePersonRef}>
313 <Grid item xs={12} md={12}>
314 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
315 label='Responsible person' linkToUuid={item.ownerUuid}
316 uuidEnhancer={(uuid: string) => <ResponsiblePerson uuid={item.uuid} parentRef={responsiblePersonRef.current} />} />
319 <Grid item xs={12} md={mdSize}>
320 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
322 value={isOldVersion ? undefined : 'this one'}
323 linkToUuid={isOldVersion ? item.currentVersionUuid : undefined} />
325 <Grid item xs={12} md={mdSize}>
327 classLabel={classes.label} classValue={classes.value}
328 label='Version number'
329 value={showVersionBrowser !== undefined
330 ? <Tooltip title="Open version browser"><ButtonLink underline='none' className={classes.button} onClick={() => showVersionBrowser()}>
331 {<span data-cy='collection-version-number'>{item.version}</span>}
332 </ButtonLink></Tooltip>
337 <Grid item xs={12} md={mdSize}>
338 <DetailsAttribute label='Created at' value={formatDate(item.createdAt)} />
340 <Grid item xs={12} md={mdSize}>
341 <DetailsAttribute label='Last modified' value={formatDate(item.modifiedAt)} />
343 <Grid item xs={12} md={mdSize}>
344 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
345 label='Number of files' value={<span data-cy='collection-file-count'>{item.fileCount}</span>} />
347 <Grid item xs={12} md={mdSize}>
348 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
349 label='Content size' value={formatFileSize(item.fileSizeTotal)} />
351 <Grid item xs={12} md={mdSize}>
352 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
353 label='Storage classes' value={item.storageClassesDesired ? item.storageClassesDesired.join(', ') : ["default"]} />
357 NOTE: The property list should be kept at the bottom, because it spans
358 the entire available width, without regards of the twoCol prop.
360 <Grid item xs={12} md={12}>
361 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
362 label='Properties' />
363 {Object.keys(item.properties).length > 0
364 ? Object.keys(item.properties).map(k =>
365 Array.isArray(item.properties[k])
366 ? item.properties[k].map((v: string) =>
367 getPropertyChip(k, v, undefined, classes.tag))
368 : getPropertyChip(k, item.properties[k], undefined, classes.tag))
369 : <div className={classes.value}>No properties</div>}