1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from 'react';
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 { getProgressIndicator } from 'store/progress-indicator/progress-indicator-reducer';
36 import { COLLECTION_PANEL_LOAD_FILES, loadCollectionFiles } from 'store/collection-panel/collection-panel-files/collection-panel-files-actions';
37 import { Link } from 'react-router-dom';
38 import { Link as ButtonLink } from '@material-ui/core';
39 import { ResourceWithName, ResponsiblePerson } from 'views-components/data-explorer/renderers';
40 import { MPVContainer, MPVPanelContent, MPVPanelState } from 'components/multi-panel-view/multi-panel-view';
42 type CssRules = 'root'
57 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
65 paddingLeft: theme.spacing.unit * 2,
66 paddingRight: theme.spacing.unit * 2,
67 paddingBottom: theme.spacing.unit * 2,
77 color: theme.customs.colors.yellow700
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,
113 interface CollectionPanelDataProps {
114 item: CollectionResource;
116 isOldVersion: boolean;
117 isLoadingFiles: boolean;
120 type CollectionPanelProps = CollectionPanelDataProps & DispatchProp
121 & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
123 export const CollectionPanel = withStyles(styles)(
124 connect((state: RootState, props: RouteComponentProps<{ id: string }>) => {
125 const currentUserUUID = getUserUuid(state);
126 const item = getResource<CollectionResource>(props.match.params.id)(state.resources);
127 let isWritable = false;
128 const isOldVersion = item && item.currentVersionUuid !== item.uuid;
129 if (item && !isOldVersion) {
130 if (item.ownerUuid === currentUserUUID) {
133 const itemOwner = getResource<GroupResource | UserResource>(item.ownerUuid)(state.resources);
134 if (itemOwner && itemOwner.writableBy) {
135 isWritable = itemOwner.writableBy.indexOf(currentUserUUID || '') >= 0;
139 const loadingFilesIndicator = getProgressIndicator(COLLECTION_PANEL_LOAD_FILES)(state.progressIndicator);
140 const isLoadingFiles = (loadingFilesIndicator && loadingFilesIndicator!.working) || false;
141 return { item, isWritable, isOldVersion, isLoadingFiles };
143 class extends React.Component<CollectionPanelProps> {
145 const { classes, item, dispatch, isWritable, isOldVersion, isLoadingFiles } = this.props;
146 const panelsData: MPVPanelState[] = [
151 ? <MPVContainer className={classes.root} spacing={8} direction="column" justify-content="flex-start" wrap="nowrap" panelStates={panelsData}>
152 <MPVPanelContent xs="auto" data-cy='collection-info-panel'>
153 <Card className={classes.infoCard}>
154 <Grid container justify="space-between">
155 <Grid item xs={11}><span>
156 <IconButton onClick={this.openCollectionDetails}>
158 ? <CollectionOldVersionIcon className={classes.iconHeader} />
159 : <CollectionIcon className={classes.iconHeader} />}
161 <IllegalNamingWarning name={item.name} />
165 <Tooltip title="Read-only">
166 <ReadOnlyIcon data-cy="read-only-icon" className={classes.readOnlyIcon} />
171 <Grid item xs={1} style={{ textAlign: "right" }}>
172 <Tooltip title="Actions" disableFocusListener>
174 data-cy='collection-panel-options-btn'
176 onClick={this.handleContextMenu}>
182 <Grid container justify="space-between">
184 <Typography variant="caption">
187 <CollectionDetailsAttributes item={item} classes={classes} twoCol={true} showVersionBrowser={() => dispatch<any>(openDetailsPanel(item.uuid, 1))} />
188 {(item.properties.container_request || item.properties.containerRequest) &&
189 <span onClick={() => dispatch<any>(navigateToProcess(item.properties.container_request || item.properties.containerRequest))}>
190 <DetailsAttribute classLabel={classes.link} label='Link to process' />
194 <Typography className={classes.warningLabel} variant="caption">
195 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.
203 <Card className={classes.filesCard}>
204 <CollectionPanelFiles
205 isWritable={isWritable}
206 isLoading={isLoadingFiles}
207 loadFilesFunc={() => {
208 dispatch<any>(loadCollectionFiles(this.props.item.uuid));
217 handleContextMenu = (event: React.MouseEvent<any>) => {
218 const { uuid, ownerUuid, name, description,
219 kind, storageClassesDesired, properties } = this.props.item;
220 const menuKind = this.props.dispatch<any>(resourceUuidToContextMenuKind(uuid));
226 storageClassesDesired,
231 // Avoid expanding/collapsing the panel
232 event.stopPropagation();
233 this.props.dispatch<any>(openContextMenu(event, resource));
236 onCopy = (message: string) =>
237 this.props.dispatch(snackbarActions.OPEN_SNACKBAR({
240 kind: SnackbarKind.SUCCESS
243 openCollectionDetails = (e: React.MouseEvent<HTMLElement>) => {
244 const { item } = this.props;
247 this.props.dispatch<any>(openDetailsPanel(item.uuid));
252 onClick: this.openCollectionDetails
259 interface CollectionDetailsProps {
260 item: CollectionResource;
263 showVersionBrowser?: () => void;
266 export const CollectionDetailsAttributes = (props: CollectionDetailsProps) => {
267 const item = props.item;
268 const classes = props.classes || { label: '', value: '', button: '', tag: '' };
269 const isOldVersion = item && item.currentVersionUuid !== item.uuid;
270 const mdSize = props.twoCol ? 6 : 12;
271 const showVersionBrowser = props.showVersionBrowser;
272 const responsiblePersonRef = React.useRef(null);
273 return <Grid container>
274 <Grid item xs={12} md={mdSize}>
275 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
276 label={isOldVersion ? "This version's UUID" : "Collection UUID"}
277 linkToUuid={item.uuid} />
279 <Grid item xs={12} md={mdSize}>
280 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
281 label={isOldVersion ? "This version's PDH" : "Portable data hash"}
282 linkToUuid={item.portableDataHash} />
284 <Grid item xs={12} md={mdSize}>
285 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
286 label='Owner' linkToUuid={item.ownerUuid}
287 uuidEnhancer={(uuid: string) => <ResourceWithName uuid={uuid} />} />
289 <div data-cy="responsible-person-wrapper" ref={responsiblePersonRef}>
290 <Grid item xs={12} md={12}>
291 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
292 label='Responsible person' linkToUuid={item.ownerUuid}
293 uuidEnhancer={(uuid: string) => <ResponsiblePerson uuid={item.uuid} parentRef={responsiblePersonRef.current} />} />
296 <Grid item xs={12} md={mdSize}>
297 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
299 value={isOldVersion ? undefined : 'this one'}
300 linkToUuid={isOldVersion ? item.currentVersionUuid : undefined} />
302 <Grid item xs={12} md={mdSize}>
304 classLabel={classes.label} classValue={classes.value}
305 label='Version number'
306 value={showVersionBrowser !== undefined
307 ? <Tooltip title="Open version browser"><ButtonLink underline='none' className={classes.button} onClick={() => showVersionBrowser()}>
308 {<span data-cy='collection-version-number'>{item.version}</span>}
309 </ButtonLink></Tooltip>
314 <Grid item xs={12} md={mdSize}>
315 <DetailsAttribute label='Created at' value={formatDate(item.createdAt)} />
317 <Grid item xs={12} md={mdSize}>
318 <DetailsAttribute label='Last modified' value={formatDate(item.modifiedAt)} />
320 <Grid item xs={12} md={mdSize}>
321 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
322 label='Number of files' value={<span data-cy='collection-file-count'>{item.fileCount}</span>} />
324 <Grid item xs={12} md={mdSize}>
325 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
326 label='Content size' value={formatFileSize(item.fileSizeTotal)} />
328 <Grid item xs={12} md={mdSize}>
329 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
330 label='Storage classes' value={item.storageClassesDesired.join(', ')} />
334 NOTE: The property list should be kept at the bottom, because it spans
335 the entire available width, without regards of the twoCol prop.
337 <Grid item xs={12} md={12}>
338 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
339 label='Properties' />
340 {Object.keys(item.properties).length > 0
341 ? Object.keys(item.properties).map(k =>
342 Array.isArray(item.properties[k])
343 ? item.properties[k].map((v: string) =>
344 getPropertyChip(k, v, undefined, classes.tag))
345 : getPropertyChip(k, item.properties[k], undefined, classes.tag))
346 : <div className={classes.value}>No properties</div>}