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';
61 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
75 color: theme.customs.colors.greyL
78 marginRight: theme.spacing.unit / 2,
79 marginBottom: theme.spacing.unit / 2
92 flexDirection: 'column',
95 textTransform: 'none',
100 color: theme.palette.primary.main,
106 marginLeft: theme.spacing.unit,
110 paddingTop: theme.spacing.unit,
111 paddingBottom: theme.spacing.unit,
115 paddingTop: theme.spacing.unit * 0.5,
116 color: theme.customs.colors.green700,
119 alignSelf: 'flex-start',
120 paddingTop: theme.spacing.unit * 0.5
123 padding: theme.spacing.unit * 1.0,
124 paddingTop: theme.spacing.unit * 0.5,
126 paddingBottom: theme.spacing.unit * 1,
131 interface CollectionPanelDataProps {
132 item: CollectionResource;
134 isOldVersion: boolean;
135 isLoadingFiles: boolean;
138 type CollectionPanelProps = CollectionPanelDataProps & DispatchProp & WithStyles<CssRules>
140 export const CollectionPanel = withStyles(styles)(connect(
141 (state: RootState, props: RouteComponentProps<{ id: string }>) => {
142 const currentUserUUID = getUserUuid(state);
143 const item = getResource<CollectionResource>(props.match.params.id)(state.resources);
144 let isWritable = false;
145 const isOldVersion = item && item.currentVersionUuid !== item.uuid;
146 if (item && !isOldVersion) {
147 if (item.ownerUuid === currentUserUUID) {
150 const itemOwner = getResource<GroupResource | UserResource>(item.ownerUuid)(state.resources);
152 isWritable = itemOwner.canWrite;
157 if (item && isWritable) {
158 isWritable = !resourceIsFrozen(item, state.resources);
161 return { item, isWritable, isOldVersion };
163 class extends React.Component<CollectionPanelProps> {
165 const { classes, item, dispatch, isWritable, isOldVersion } = this.props;
166 const panelsData: MPVPanelState[] = [
171 ? <MPVContainer spacing={8} direction="column" justify-content="flex-start" wrap="nowrap" panelStates={panelsData}>
172 <MPVPanelContent xs="auto" data-cy='collection-info-panel'>
173 <Card className={classes.infoCard}>
175 className={classes.header}
177 content: classes.title,
178 avatar: classes.avatar,
180 avatar={<IconButton onClick={this.openCollectionDetails}>
182 ? <CollectionOldVersionIcon className={classes.iconHeader} />
183 : <CollectionIcon className={classes.iconHeader} />}
187 <IllegalNamingWarning name={item.name} />
190 <Tooltip title="Read-only">
191 <ReadOnlyIcon data-cy="read-only-icon" className={classes.readOnlyIcon} />
196 <Tooltip title="Actions" disableFocusListener>
198 data-cy='collection-panel-options-btn'
200 onClick={this.handleContextMenu}>
206 <CardContent className={classes.content}>
207 <Typography variant="caption">
210 <CollectionDetailsAttributes item={item} classes={classes} twoCol={true} showVersionBrowser={() => dispatch<any>(openDetailsPanel(item.uuid, 1))} />
211 {(item.properties.container_request || item.properties.containerRequest) &&
212 <span onClick={() => dispatch<any>(navigateToProcess(item.properties.container_request || item.properties.containerRequest))}>
213 <DetailsAttribute classLabel={classes.link} label='Link to process' />
217 <Typography className={classes.warningLabel} variant="caption">
218 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.
225 <Card className={classes.filesCard}>
226 <CollectionPanelFiles isWritable={isWritable} />
231 icon={CollectionIcon}
232 messages={["Collection not found"]}
237 handleContextMenu = (event: React.MouseEvent<any>) => {
238 const { uuid, ownerUuid, name, description,
239 kind, storageClassesDesired, properties } = this.props.item;
240 const menuKind = this.props.dispatch<any>(resourceUuidToContextMenuKind(uuid));
246 storageClassesDesired,
251 // Avoid expanding/collapsing the panel
252 event.stopPropagation();
253 this.props.dispatch<any>(openContextMenu(event, resource));
256 onCopy = (message: string) =>
257 this.props.dispatch(snackbarActions.OPEN_SNACKBAR({
260 kind: SnackbarKind.SUCCESS
263 openCollectionDetails = (e: React.MouseEvent<HTMLElement>) => {
264 const { item } = this.props;
267 this.props.dispatch<any>(openDetailsPanel(item.uuid));
272 onClick: this.openCollectionDetails
279 interface CollectionDetailsProps {
280 item: CollectionResource;
283 showVersionBrowser?: () => void;
286 export const CollectionDetailsAttributes = (props: CollectionDetailsProps) => {
287 const item = props.item;
288 const classes = props.classes || { label: '', value: '', button: '', tag: '' };
289 const isOldVersion = item && item.currentVersionUuid !== item.uuid;
290 const mdSize = props.twoCol ? 6 : 12;
291 const showVersionBrowser = props.showVersionBrowser;
292 const responsiblePersonRef = React.useRef(null);
293 return <Grid container>
294 <Grid item xs={12} md={mdSize}>
295 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
296 label={isOldVersion ? "This version's UUID" : "Collection UUID"}
297 linkToUuid={item.uuid} />
299 <Grid item xs={12} md={mdSize}>
300 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
301 label={isOldVersion ? "This version's PDH" : "Portable data hash"}
302 linkToUuid={item.portableDataHash} />
304 <Grid item xs={12} md={mdSize}>
305 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
306 label='Owner' linkToUuid={item.ownerUuid}
307 uuidEnhancer={(uuid: string) => <ResourceWithName uuid={uuid} />} />
309 <div data-cy="responsible-person-wrapper" ref={responsiblePersonRef}>
310 <Grid item xs={12} md={12}>
311 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
312 label='Responsible person' linkToUuid={item.ownerUuid}
313 uuidEnhancer={(uuid: string) => <ResponsiblePerson uuid={item.uuid} parentRef={responsiblePersonRef.current} />} />
316 <Grid item xs={12} md={mdSize}>
317 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
319 value={isOldVersion ? undefined : 'this one'}
320 linkToUuid={isOldVersion ? item.currentVersionUuid : undefined} />
322 <Grid item xs={12} md={mdSize}>
324 classLabel={classes.label} classValue={classes.value}
325 label='Version number'
326 value={showVersionBrowser !== undefined
327 ? <Tooltip title="Open version browser"><ButtonLink underline='none' className={classes.button} onClick={() => showVersionBrowser()}>
328 {<span data-cy='collection-version-number'>{item.version}</span>}
329 </ButtonLink></Tooltip>
334 <Grid item xs={12} md={mdSize}>
335 <DetailsAttribute label='Created at' value={formatDate(item.createdAt)} />
337 <Grid item xs={12} md={mdSize}>
338 <DetailsAttribute label='Last modified' value={formatDate(item.modifiedAt)} />
340 <Grid item xs={12} md={mdSize}>
341 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
342 label='Number of files' value={<span data-cy='collection-file-count'>{item.fileCount}</span>} />
344 <Grid item xs={12} md={mdSize}>
345 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
346 label='Content size' value={formatFileSize(item.fileSizeTotal)} />
348 <Grid item xs={12} md={mdSize}>
349 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
350 label='Storage classes' value={item.storageClassesDesired ? item.storageClassesDesired.join(', ') : ["default"]} />
354 NOTE: The property list should be kept at the bottom, because it spans
355 the entire available width, without regards of the twoCol prop.
357 <Grid item xs={12} md={12}>
358 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
359 label='Properties' />
360 {item.properties && Object.keys(item.properties).length > 0
361 ? Object.keys(item.properties).map(k =>
362 Array.isArray(item.properties[k])
363 ? item.properties[k].map((v: string) =>
364 getPropertyChip(k, v, undefined, classes.tag))
365 : getPropertyChip(k, item.properties[k], undefined, classes.tag))
366 : <div className={classes.value}>No properties</div>}