1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from 'react';
7 StyleRulesCallback, WithStyles, withStyles,
8 IconButton, Grid, Tooltip, Typography, ExpansionPanel,
9 ExpansionPanelSummary, ExpansionPanelDetails
10 } from '@material-ui/core';
11 import { connect, DispatchProp } from "react-redux";
12 import { RouteComponentProps } from 'react-router';
13 import { ArvadosTheme } from 'common/custom-theme';
14 import { RootState } from 'store/store';
15 import { MoreOptionsIcon, CollectionIcon, ReadOnlyIcon, ExpandIcon, CollectionOldVersionIcon } from 'components/icon/icon';
16 import { DetailsAttribute } from 'components/details-attribute/details-attribute';
17 import { CollectionResource, getCollectionUrl } from 'models/collection';
18 import { CollectionPanelFiles } from 'views-components/collection-panel-files/collection-panel-files';
19 import { CollectionTagForm } from './collection-tag-form';
20 import { deleteCollectionTag, navigateToProcess, collectionPanelActions } from 'store/collection-panel/collection-panel-action';
21 import { getResource } from 'store/resources/resources';
22 import { openContextMenu, resourceUuidToContextMenuKind } from 'store/context-menu/context-menu-actions';
23 import { formatDate, formatFileSize } from "common/formatters";
24 import { openDetailsPanel } from 'store/details-panel/details-panel-action';
25 import { snackbarActions, SnackbarKind } from 'store/snackbar/snackbar-actions';
26 import { getPropertyChip } from 'views-components/resource-properties-form/property-chip';
27 import { IllegalNamingWarning } from 'components/warning/warning';
28 import { GroupResource } from 'models/group';
29 import { UserResource } from 'models/user';
30 import { getUserUuid } from 'common/getuser';
31 import { getProgressIndicator } from 'store/progress-indicator/progress-indicator-reducer';
32 import { COLLECTION_PANEL_LOAD_FILES, loadCollectionFiles, COLLECTION_PANEL_LOAD_FILES_THRESHOLD } from 'store/collection-panel/collection-panel-files/collection-panel-files-actions';
33 import { Link } from 'react-router-dom';
34 import { Link as ButtonLink } from '@material-ui/core';
35 import { ResourceOwnerWithName, ResponsiblePerson } from 'views-components/data-explorer/renderers';
36 import { MPVContainer, MPVPanelContent, MPVPanelState } from 'components/multi-panel-view/multi-panel-view';
38 type CssRules = 'root'
51 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
59 marginBottom: theme.spacing.unit * 2,
64 color: theme.customs.colors.yellow700
67 marginRight: theme.spacing.unit,
68 marginBottom: theme.spacing.unit
81 flexDirection: 'column',
84 textTransform: 'none',
89 color: theme.palette.primary.main,
95 marginLeft: theme.spacing.unit,
100 interface CollectionPanelDataProps {
101 item: CollectionResource;
103 isOldVersion: boolean;
104 isLoadingFiles: boolean;
105 tooManyFiles: boolean;
108 type CollectionPanelProps = CollectionPanelDataProps & DispatchProp
109 & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
111 export const CollectionPanel = withStyles(styles)(
112 connect((state: RootState, props: RouteComponentProps<{ id: string }>) => {
113 const currentUserUUID = getUserUuid(state);
114 const item = getResource<CollectionResource>(props.match.params.id)(state.resources);
115 let isWritable = false;
116 const isOldVersion = item && item.currentVersionUuid !== item.uuid;
117 if (item && !isOldVersion) {
118 if (item.ownerUuid === currentUserUUID) {
121 const itemOwner = getResource<GroupResource | UserResource>(item.ownerUuid)(state.resources);
122 if (itemOwner && itemOwner.writableBy) {
123 isWritable = itemOwner.writableBy.indexOf(currentUserUUID || '') >= 0;
127 const loadingFilesIndicator = getProgressIndicator(COLLECTION_PANEL_LOAD_FILES)(state.progressIndicator);
128 const isLoadingFiles = (loadingFilesIndicator && loadingFilesIndicator!.working) || false;
129 const tooManyFiles = (!state.collectionPanel.loadBigCollections && item && item.fileCount > COLLECTION_PANEL_LOAD_FILES_THRESHOLD) || false;
130 return { item, isWritable, isOldVersion, isLoadingFiles, tooManyFiles };
132 class extends React.Component<CollectionPanelProps> {
134 const { classes, item, dispatch, isWritable, isOldVersion, isLoadingFiles, tooManyFiles } = this.props;
135 const panelsData: MPVPanelState[] = [
137 {name: "Properties", visible: false},
141 ? <MPVContainer className={classes.root} spacing={8} direction="column" justify-content="flex-start" wrap="nowrap" panelStates={panelsData}>
142 <MPVPanelContent xs="auto"><ExpansionPanel data-cy='collection-info-panel' defaultExpanded>
143 <ExpansionPanelSummary expandIcon={<ExpandIcon />}>
144 <Grid container justify="space-between">
145 <Grid item xs={11}><span>
146 <IconButton onClick={this.openCollectionDetails}>
148 ? <CollectionOldVersionIcon className={classes.iconHeader} />
149 : <CollectionIcon className={classes.iconHeader} />}
151 <IllegalNamingWarning name={item.name} />
155 <Tooltip title="Read-only">
156 <ReadOnlyIcon data-cy="read-only-icon" className={classes.readOnlyIcon} />
161 <Grid item xs={1} style={{ textAlign: "right" }}>
162 <Tooltip title="Actions" disableFocusListener>
164 data-cy='collection-panel-options-btn'
166 onClick={this.handleContextMenu}>
172 </ExpansionPanelSummary>
173 <ExpansionPanelDetails>
174 <Grid container justify="space-between">
176 <Typography variant="caption">
179 <CollectionDetailsAttributes item={item} classes={classes} twoCol={true} showVersionBrowser={() => dispatch<any>(openDetailsPanel(item.uuid, 1))} />
180 {(item.properties.container_request || item.properties.containerRequest) &&
181 <span onClick={() => dispatch<any>(navigateToProcess(item.properties.container_request || item.properties.containerRequest))}>
182 <DetailsAttribute classLabel={classes.link} label='Link to process' />
186 <Typography className={classes.warningLabel} variant="caption">
187 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.
192 </ExpansionPanelDetails>
193 </ExpansionPanel></MPVPanelContent>
195 <MPVPanelContent xs="auto"><ExpansionPanel data-cy='collection-properties-panel' defaultExpanded>
196 <ExpansionPanelSummary expandIcon={<ExpandIcon />}>
198 </ExpansionPanelSummary>
199 <ExpansionPanelDetails>
201 {isWritable && <Grid item xs={12}>
202 <CollectionTagForm />
205 {Object.keys(item.properties).length > 0
206 ? Object.keys(item.properties).map(k =>
207 Array.isArray(item.properties[k])
208 ? item.properties[k].map((v: string) =>
212 ? this.handleDelete(k, v)
216 k, item.properties[k],
218 ? this.handleDelete(k, item.properties[k])
222 : <div className={classes.centeredLabel}>No properties set on this collection.</div>
226 </ExpansionPanelDetails>
227 </ExpansionPanel></MPVPanelContent>
228 <MPVPanelContent xs className={classes.filesCard}>
229 <CollectionPanelFiles
230 isWritable={isWritable}
231 isLoading={isLoadingFiles}
232 tooManyFiles={tooManyFiles}
233 loadFilesFunc={() => {
234 dispatch(collectionPanelActions.LOAD_BIG_COLLECTIONS(true));
235 dispatch<any>(loadCollectionFiles(this.props.item.uuid));
243 handleContextMenu = (event: React.MouseEvent<any>) => {
244 const { uuid, ownerUuid, name, description, kind, storageClassesDesired } = this.props.item;
245 const menuKind = this.props.dispatch<any>(resourceUuidToContextMenuKind(uuid));
251 storageClassesDesired,
255 // Avoid expanding/collapsing the panel
256 event.stopPropagation();
257 this.props.dispatch<any>(openContextMenu(event, resource));
260 onCopy = (message: string) =>
261 this.props.dispatch(snackbarActions.OPEN_SNACKBAR({
264 kind: SnackbarKind.SUCCESS
267 handleDelete = (key: string, value: string) => () => {
268 this.props.dispatch<any>(deleteCollectionTag(key, value));
271 openCollectionDetails = (e: React.MouseEvent<HTMLElement>) => {
272 const { item } = this.props;
275 this.props.dispatch<any>(openDetailsPanel(item.uuid));
280 onClick: this.openCollectionDetails
287 export const CollectionDetailsAttributes = (props: { item: CollectionResource, twoCol: boolean, classes?: Record<CssRules, string>, showVersionBrowser?: () => void }) => {
288 const item = props.item;
289 const classes = props.classes || { label: '', value: '', button: '' };
290 const isOldVersion = item && item.currentVersionUuid !== item.uuid;
291 const mdSize = props.twoCol ? 6 : 12;
292 const showVersionBrowser = props.showVersionBrowser;
293 const responsiblePersonRef = React.useRef(null);
294 return <Grid container>
295 <Grid item xs={12} md={mdSize}>
296 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
297 label={isOldVersion ? "This version's UUID" : "Collection UUID"}
298 linkToUuid={item.uuid} />
300 <Grid item xs={12} md={mdSize}>
301 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
302 label={isOldVersion ? "This version's PDH" : "Portable data hash"}
303 linkToUuid={item.portableDataHash} />
305 <Grid item xs={12} md={mdSize}>
306 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
307 label='Owner' linkToUuid={item.ownerUuid}
308 uuidEnhancer={(uuid: string) => <ResourceOwnerWithName uuid={uuid} />} />
310 <div data-cy="responsible-person-wrapper" ref={responsiblePersonRef}>
311 <Grid item xs={12} md={12}>
312 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
313 label='Responsible person' linkToUuid={item.ownerUuid}
314 uuidEnhancer={(uuid: string) => <ResponsiblePerson uuid={item.uuid} parentRef={responsiblePersonRef.current} />} />
317 <Grid item xs={12} md={mdSize}>
318 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
320 value={isOldVersion ? undefined : 'this one'}
321 linkToUuid={isOldVersion ? item.currentVersionUuid : undefined} />
323 <Grid item xs={12} md={mdSize}>
325 classLabel={classes.label} classValue={classes.value}
326 label='Version number'
327 value={showVersionBrowser !== undefined
328 ? <Tooltip title="Open version browser"><ButtonLink underline='none' className={classes.button} onClick={() => showVersionBrowser()}>
329 {<span data-cy='collection-version-number'>{item.version}</span>}
330 </ButtonLink></Tooltip>
335 <Grid item xs={12} md={mdSize}>
336 <DetailsAttribute label='Created at' value={formatDate(item.createdAt)} />
338 <Grid item xs={12} md={mdSize}>
339 <DetailsAttribute label='Last modified' value={formatDate(item.modifiedAt)} />
341 <Grid item xs={12} md={mdSize}>
342 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
343 label='Number of files' value={item.fileCount} />
345 <Grid item xs={12} md={mdSize}>
346 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
347 label='Content size' value={formatFileSize(item.fileSizeTotal)} />
349 <Grid item xs={12} md={mdSize}>
350 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
351 label='Storage classes' value={item.storageClassesDesired.join(', ')} />