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, collectionPanelActions } 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, COLLECTION_PANEL_LOAD_FILES_THRESHOLD } 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 { ResourceOwnerWithName, 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;
118 tooManyFiles: boolean;
121 type CollectionPanelProps = CollectionPanelDataProps & DispatchProp
122 & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
124 export const CollectionPanel = withStyles(styles)(
125 connect((state: RootState, props: RouteComponentProps<{ id: string }>) => {
126 const currentUserUUID = getUserUuid(state);
127 const item = getResource<CollectionResource>(props.match.params.id)(state.resources);
128 let isWritable = false;
129 const isOldVersion = item && item.currentVersionUuid !== item.uuid;
130 if (item && !isOldVersion) {
131 if (item.ownerUuid === currentUserUUID) {
134 const itemOwner = getResource<GroupResource | UserResource>(item.ownerUuid)(state.resources);
135 if (itemOwner && itemOwner.writableBy) {
136 isWritable = itemOwner.writableBy.indexOf(currentUserUUID || '') >= 0;
140 const loadingFilesIndicator = getProgressIndicator(COLLECTION_PANEL_LOAD_FILES)(state.progressIndicator);
141 const isLoadingFiles = (loadingFilesIndicator && loadingFilesIndicator!.working) || false;
142 const tooManyFiles = (!state.collectionPanel.loadBigCollections && item && item.fileCount > COLLECTION_PANEL_LOAD_FILES_THRESHOLD) || false;
143 return { item, isWritable, isOldVersion, isLoadingFiles, tooManyFiles };
145 class extends React.Component<CollectionPanelProps> {
147 const { classes, item, dispatch, isWritable, isOldVersion, isLoadingFiles, tooManyFiles } = this.props;
148 const panelsData: MPVPanelState[] = [
153 ? <MPVContainer className={classes.root} spacing={8} direction="column" justify-content="flex-start" wrap="nowrap" panelStates={panelsData}>
154 <MPVPanelContent xs="auto" data-cy='collection-info-panel'>
155 <Card className={classes.infoCard}>
156 <Grid container justify="space-between">
157 <Grid item xs={11}><span>
158 <IconButton onClick={this.openCollectionDetails}>
160 ? <CollectionOldVersionIcon className={classes.iconHeader} />
161 : <CollectionIcon className={classes.iconHeader} />}
163 <IllegalNamingWarning name={item.name} />
167 <Tooltip title="Read-only">
168 <ReadOnlyIcon data-cy="read-only-icon" className={classes.readOnlyIcon} />
173 <Grid item xs={1} style={{ textAlign: "right" }}>
174 <Tooltip title="Actions" disableFocusListener>
176 data-cy='collection-panel-options-btn'
178 onClick={this.handleContextMenu}>
184 <Grid container justify="space-between">
186 <Typography variant="caption">
189 <CollectionDetailsAttributes item={item} classes={classes} twoCol={true} showVersionBrowser={() => dispatch<any>(openDetailsPanel(item.uuid, 1))} />
190 {(item.properties.container_request || item.properties.containerRequest) &&
191 <span onClick={() => dispatch<any>(navigateToProcess(item.properties.container_request || item.properties.containerRequest))}>
192 <DetailsAttribute classLabel={classes.link} label='Link to process' />
196 <Typography className={classes.warningLabel} variant="caption">
197 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.
205 <Card className={classes.filesCard}>
206 <CollectionPanelFiles
207 isWritable={isWritable}
208 isLoading={isLoadingFiles}
209 tooManyFiles={tooManyFiles}
210 loadFilesFunc={() => {
211 dispatch(collectionPanelActions.LOAD_BIG_COLLECTIONS(true));
212 dispatch<any>(loadCollectionFiles(this.props.item.uuid));
221 handleContextMenu = (event: React.MouseEvent<any>) => {
222 const { uuid, ownerUuid, name, description,
223 kind, storageClassesDesired, properties } = this.props.item;
224 const menuKind = this.props.dispatch<any>(resourceUuidToContextMenuKind(uuid));
230 storageClassesDesired,
235 // Avoid expanding/collapsing the panel
236 event.stopPropagation();
237 this.props.dispatch<any>(openContextMenu(event, resource));
240 onCopy = (message: string) =>
241 this.props.dispatch(snackbarActions.OPEN_SNACKBAR({
244 kind: SnackbarKind.SUCCESS
247 openCollectionDetails = (e: React.MouseEvent<HTMLElement>) => {
248 const { item } = this.props;
251 this.props.dispatch<any>(openDetailsPanel(item.uuid));
256 onClick: this.openCollectionDetails
263 interface CollectionDetailsProps {
264 item: CollectionResource;
267 showVersionBrowser?: () => void;
270 export const CollectionDetailsAttributes = (props: CollectionDetailsProps) => {
271 const item = props.item;
272 const classes = props.classes || { label: '', value: '', button: '', tag: '' };
273 const isOldVersion = item && item.currentVersionUuid !== item.uuid;
274 const mdSize = props.twoCol ? 6 : 12;
275 const showVersionBrowser = props.showVersionBrowser;
276 const responsiblePersonRef = React.useRef(null);
277 return <Grid container>
278 <Grid item xs={12} md={mdSize}>
279 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
280 label={isOldVersion ? "This version's UUID" : "Collection UUID"}
281 linkToUuid={item.uuid} />
283 <Grid item xs={12} md={mdSize}>
284 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
285 label={isOldVersion ? "This version's PDH" : "Portable data hash"}
286 linkToUuid={item.portableDataHash} />
288 <Grid item xs={12} md={mdSize}>
289 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
290 label='Owner' linkToUuid={item.ownerUuid}
291 uuidEnhancer={(uuid: string) => <ResourceOwnerWithName uuid={uuid} />} />
293 <div data-cy="responsible-person-wrapper" ref={responsiblePersonRef}>
294 <Grid item xs={12} md={12}>
295 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
296 label='Responsible person' linkToUuid={item.ownerUuid}
297 uuidEnhancer={(uuid: string) => <ResponsiblePerson uuid={item.uuid} parentRef={responsiblePersonRef.current} />} />
300 <Grid item xs={12} md={mdSize}>
301 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
303 value={isOldVersion ? undefined : 'this one'}
304 linkToUuid={isOldVersion ? item.currentVersionUuid : undefined} />
306 <Grid item xs={12} md={mdSize}>
308 classLabel={classes.label} classValue={classes.value}
309 label='Version number'
310 value={showVersionBrowser !== undefined
311 ? <Tooltip title="Open version browser"><ButtonLink underline='none' className={classes.button} onClick={() => showVersionBrowser()}>
312 {<span data-cy='collection-version-number'>{item.version}</span>}
313 </ButtonLink></Tooltip>
318 <Grid item xs={12} md={mdSize}>
319 <DetailsAttribute label='Created at' value={formatDate(item.createdAt)} />
321 <Grid item xs={12} md={mdSize}>
322 <DetailsAttribute label='Last modified' value={formatDate(item.modifiedAt)} />
324 <Grid item xs={12} md={mdSize}>
325 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
326 label='Number of files' value={<span data-cy='collection-file-count'>{item.fileCount}</span>} />
328 <Grid item xs={12} md={mdSize}>
329 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
330 label='Content size' value={formatFileSize(item.fileSizeTotal)} />
332 <Grid item xs={12} md={mdSize}>
333 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
334 label='Storage classes' value={item.storageClassesDesired.join(', ')} />
338 NOTE: The property list should be kept at the bottom, because it spans
339 the entire available width, without regards of the twoCol prop.
341 <Grid item xs={12} md={12}>
342 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
343 label='Properties' />
344 { Object.keys(item.properties).length > 0
345 ? Object.keys(item.properties).map(k =>
346 Array.isArray(item.properties[k])
347 ? item.properties[k].map((v: string) =>
348 getPropertyChip(k, v, undefined, classes.tag))
349 : getPropertyChip(k, item.properties[k], undefined, classes.tag))
350 : <div className={classes.value}>No properties</div> }