1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from 'react';
6 import { Dispatch } from 'redux';
16 } from '@material-ui/core';
17 import { connect, DispatchProp } from "react-redux";
18 import { RouteComponentProps } from 'react-router';
19 import { ArvadosTheme } from 'common/custom-theme';
20 import { RootState } from 'store/store';
21 import { MoreOptionsIcon, CollectionIcon, ReadOnlyIcon, CollectionOldVersionIcon, RenameIcon } from 'components/icon/icon';
22 import { DetailsAttribute } from 'components/details-attribute/details-attribute';
23 import { CollectionResource, getCollectionUrl } from 'models/collection';
24 import { CollectionPanelFiles } from 'views-components/collection-panel-files/collection-panel-files';
25 import { navigateToProcess, collectionPanelActions } from 'store/collection-panel/collection-panel-action';
26 import { getResource } from 'store/resources/resources';
27 import { openContextMenu, resourceUuidToContextMenuKind } from 'store/context-menu/context-menu-actions';
28 import { formatDate, formatFileSize } from "common/formatters";
29 import { openDetailsPanel, openResourcePropertiesDialog } from 'store/details-panel/details-panel-action';
30 import { snackbarActions, SnackbarKind } from 'store/snackbar/snackbar-actions';
31 import { getPropertyChip } from 'views-components/resource-properties-form/property-chip';
32 import { IllegalNamingWarning } from 'components/warning/warning';
33 import { GroupResource } from 'models/group';
34 import { UserResource } from 'models/user';
35 import { getUserUuid } from 'common/getuser';
36 import { getProgressIndicator } from 'store/progress-indicator/progress-indicator-reducer';
37 import { COLLECTION_PANEL_LOAD_FILES, loadCollectionFiles, COLLECTION_PANEL_LOAD_FILES_THRESHOLD } from 'store/collection-panel/collection-panel-files/collection-panel-files-actions';
38 import { Link } from 'react-router-dom';
39 import { Link as ButtonLink } from '@material-ui/core';
40 import { ResourceOwnerWithName, ResponsiblePerson } from 'views-components/data-explorer/renderers';
41 import { MPVContainer, MPVPanelContent, MPVPanelState } from 'components/multi-panel-view/multi-panel-view';
43 type CssRules = 'root'
58 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
66 paddingLeft: theme.spacing.unit * 2,
67 paddingRight: theme.spacing.unit * 2,
68 paddingBottom: theme.spacing.unit * 2,
78 color: theme.customs.colors.yellow700
81 marginRight: theme.spacing.unit,
82 marginBottom: theme.spacing.unit
95 flexDirection: 'column',
98 textTransform: 'none',
102 fontSize: '0.875rem',
103 color: theme.palette.primary.main,
109 marginLeft: theme.spacing.unit,
114 interface CollectionPanelDataProps {
115 item: CollectionResource;
117 isOldVersion: boolean;
118 isLoadingFiles: boolean;
119 tooManyFiles: boolean;
122 type CollectionPanelProps = CollectionPanelDataProps & DispatchProp
123 & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
125 export const CollectionPanel = withStyles(styles)(
126 connect((state: RootState, props: RouteComponentProps<{ id: string }>) => {
127 const currentUserUUID = getUserUuid(state);
128 const item = getResource<CollectionResource>(props.match.params.id)(state.resources);
129 let isWritable = false;
130 const isOldVersion = item && item.currentVersionUuid !== item.uuid;
131 if (item && !isOldVersion) {
132 if (item.ownerUuid === currentUserUUID) {
135 const itemOwner = getResource<GroupResource | UserResource>(item.ownerUuid)(state.resources);
136 if (itemOwner && itemOwner.writableBy) {
137 isWritable = itemOwner.writableBy.indexOf(currentUserUUID || '') >= 0;
141 const loadingFilesIndicator = getProgressIndicator(COLLECTION_PANEL_LOAD_FILES)(state.progressIndicator);
142 const isLoadingFiles = (loadingFilesIndicator && loadingFilesIndicator!.working) || false;
143 const tooManyFiles = (!state.collectionPanel.loadBigCollections && item && item.fileCount > COLLECTION_PANEL_LOAD_FILES_THRESHOLD) || false;
144 return { item, isWritable, isOldVersion, isLoadingFiles, tooManyFiles };
146 class extends React.Component<CollectionPanelProps> {
148 const { classes, item, dispatch, isWritable, isOldVersion, isLoadingFiles, tooManyFiles } = this.props;
149 const panelsData: MPVPanelState[] = [
154 ? <MPVContainer className={classes.root} spacing={8} direction="column" justify-content="flex-start" wrap="nowrap" panelStates={panelsData}>
155 <MPVPanelContent xs="auto" data-cy='collection-info-panel'>
156 <Card className={classes.infoCard}>
157 <Grid container justify="space-between">
158 <Grid item xs={11}><span>
159 <IconButton onClick={this.openCollectionDetails}>
161 ? <CollectionOldVersionIcon className={classes.iconHeader} />
162 : <CollectionIcon className={classes.iconHeader} />}
164 <IllegalNamingWarning name={item.name} />
168 <Tooltip title="Read-only">
169 <ReadOnlyIcon data-cy="read-only-icon" className={classes.readOnlyIcon} />
174 <Grid item xs={1} style={{ textAlign: "right" }}>
175 <Tooltip title="Actions" disableFocusListener>
177 data-cy='collection-panel-options-btn'
179 onClick={this.handleContextMenu}>
185 <Grid container justify="space-between">
187 <Typography variant="caption">
190 <CollectionDetailsAttributes item={item} classes={classes} twoCol={true} showVersionBrowser={() => dispatch<any>(openDetailsPanel(item.uuid, 1))} />
191 {(item.properties.container_request || item.properties.containerRequest) &&
192 <span onClick={() => dispatch<any>(navigateToProcess(item.properties.container_request || item.properties.containerRequest))}>
193 <DetailsAttribute classLabel={classes.link} label='Link to process' />
197 <Typography className={classes.warningLabel} variant="caption">
198 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.
206 <Card className={classes.filesCard}>
207 <CollectionPanelFiles
208 isWritable={isWritable}
209 isLoading={isLoadingFiles}
210 tooManyFiles={tooManyFiles}
211 loadFilesFunc={() => {
212 dispatch(collectionPanelActions.LOAD_BIG_COLLECTIONS(true));
213 dispatch<any>(loadCollectionFiles(this.props.item.uuid));
222 handleContextMenu = (event: React.MouseEvent<any>) => {
223 const { uuid, ownerUuid, name, description, kind, storageClassesDesired } = this.props.item;
224 const menuKind = this.props.dispatch<any>(resourceUuidToContextMenuKind(uuid));
230 storageClassesDesired,
234 // Avoid expanding/collapsing the panel
235 event.stopPropagation();
236 this.props.dispatch<any>(openContextMenu(event, resource));
239 onCopy = (message: string) =>
240 this.props.dispatch(snackbarActions.OPEN_SNACKBAR({
243 kind: SnackbarKind.SUCCESS
246 openCollectionDetails = (e: React.MouseEvent<HTMLElement>) => {
247 const { item } = this.props;
250 this.props.dispatch<any>(openDetailsPanel(item.uuid));
255 onClick: this.openCollectionDetails
262 interface CollectionDetailsActionProps {
266 interface CollectionDetailsProps {
267 item: CollectionResource;
270 showVersionBrowser?: () => void;
273 const mapDispatchToProps = (dispatch: Dispatch) => ({
274 onClick: () => dispatch<any>(openResourcePropertiesDialog()),
277 export const CollectionDetailsAttributes = connect(null, mapDispatchToProps)(
278 (props: CollectionDetailsProps & CollectionDetailsActionProps) => {
279 const item = props.item;
280 const classes = props.classes || { label: '', value: '', button: '', tag: '' };
281 const isOldVersion = item && item.currentVersionUuid !== item.uuid;
282 const mdSize = props.twoCol ? 6 : 12;
283 const showVersionBrowser = props.showVersionBrowser;
284 const responsiblePersonRef = React.useRef(null);
285 return <Grid container>
286 <Grid item xs={12} md={mdSize}>
287 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
288 label={isOldVersion ? "This version's UUID" : "Collection UUID"}
289 linkToUuid={item.uuid} />
291 <Grid item xs={12} md={mdSize}>
292 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
293 label={isOldVersion ? "This version's PDH" : "Portable data hash"}
294 linkToUuid={item.portableDataHash} />
296 <Grid item xs={12} md={mdSize}>
297 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
298 label='Owner' linkToUuid={item.ownerUuid}
299 uuidEnhancer={(uuid: string) => <ResourceOwnerWithName uuid={uuid} />} />
301 <div data-cy="responsible-person-wrapper" ref={responsiblePersonRef}>
302 <Grid item xs={12} md={12}>
303 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
304 label='Responsible person' linkToUuid={item.ownerUuid}
305 uuidEnhancer={(uuid: string) => <ResponsiblePerson uuid={item.uuid} parentRef={responsiblePersonRef.current} />} />
308 <Grid item xs={12} md={mdSize}>
309 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
311 value={isOldVersion ? undefined : 'this one'}
312 linkToUuid={isOldVersion ? item.currentVersionUuid : undefined} />
314 <Grid item xs={12} md={mdSize}>
316 classLabel={classes.label} classValue={classes.value}
317 label='Version number'
318 value={showVersionBrowser !== undefined
319 ? <Tooltip title="Open version browser"><ButtonLink underline='none' className={classes.button} onClick={() => showVersionBrowser()}>
320 {<span data-cy='collection-version-number'>{item.version}</span>}
321 </ButtonLink></Tooltip>
326 <Grid item xs={12} md={mdSize}>
327 <DetailsAttribute label='Created at' value={formatDate(item.createdAt)} />
329 <Grid item xs={12} md={mdSize}>
330 <DetailsAttribute label='Last modified' value={formatDate(item.modifiedAt)} />
332 <Grid item xs={12} md={mdSize}>
333 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
334 label='Number of files' value={item.fileCount} />
336 <Grid item xs={12} md={mdSize}>
337 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
338 label='Content size' value={formatFileSize(item.fileSizeTotal)} />
340 <Grid item xs={12} md={mdSize}>
341 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
342 label='Storage classes' value={item.storageClassesDesired.join(', ')} />
344 <Grid item xs={12} md={mdSize}>
345 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
348 ? <div data-cy='property-editor-btn' onClick={props.onClick}>
349 <RenameIcon className={classes.editIcon} />
353 { Object.keys(item.properties).length > 0
354 ? Object.keys(item.properties).map(k =>
355 Array.isArray(item.properties[k])
356 ? item.properties[k].map((v: string) =>
357 getPropertyChip(k, v, undefined, classes.tag))
358 : getPropertyChip(k, item.properties[k], undefined, classes.tag))
359 : <div className={classes.value}>No properties</div> }