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 { 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 { CollectionTagForm } from './collection-tag-form';
25 import { deleteCollectionTag, 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 } 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[] = [
151 {name: "Properties"},
155 ? <MPVContainer className={classes.root} spacing={8} direction="column" justify-content="flex-start" wrap="nowrap" panelStates={panelsData}>
156 <MPVPanelContent xs="auto" data-cy='collection-info-panel'>
157 <Card className={classes.infoCard}>
158 <Grid container justify="space-between">
159 <Grid item xs={11}><span>
160 <IconButton onClick={this.openCollectionDetails}>
162 ? <CollectionOldVersionIcon className={classes.iconHeader} />
163 : <CollectionIcon className={classes.iconHeader} />}
165 <IllegalNamingWarning name={item.name} />
169 <Tooltip title="Read-only">
170 <ReadOnlyIcon data-cy="read-only-icon" className={classes.readOnlyIcon} />
175 <Grid item xs={1} style={{ textAlign: "right" }}>
176 <Tooltip title="Actions" disableFocusListener>
178 data-cy='collection-panel-options-btn'
180 onClick={this.handleContextMenu}>
186 <Grid container justify="space-between">
188 <Typography variant="caption">
191 <CollectionDetailsAttributes item={item} classes={classes} twoCol={true} showVersionBrowser={() => dispatch<any>(openDetailsPanel(item.uuid, 1))} />
192 {(item.properties.container_request || item.properties.containerRequest) &&
193 <span onClick={() => dispatch<any>(navigateToProcess(item.properties.container_request || item.properties.containerRequest))}>
194 <DetailsAttribute classLabel={classes.link} label='Link to process' />
198 <Typography className={classes.warningLabel} variant="caption">
199 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 <MPVPanelContent xs="auto" data-cy='collection-properties-panel'>
207 <Card className={classes.propertiesCard}>
208 <CardHeader title="Properties" />
209 <CardContent><Grid container>
210 {isWritable && <Grid item xs={12}>
211 <CollectionTagForm />
214 {Object.keys(item.properties).length > 0
215 ? Object.keys(item.properties).map(k =>
216 Array.isArray(item.properties[k])
217 ? item.properties[k].map((v: string) =>
221 ? this.handleDelete(k, v)
225 k, item.properties[k],
227 ? this.handleDelete(k, item.properties[k])
231 : <div className={classes.centeredLabel}>No properties set on this collection.</div>
234 </Grid></CardContent>
238 <Card className={classes.filesCard}>
239 <CollectionPanelFiles
240 isWritable={isWritable}
241 isLoading={isLoadingFiles}
242 tooManyFiles={tooManyFiles}
243 loadFilesFunc={() => {
244 dispatch(collectionPanelActions.LOAD_BIG_COLLECTIONS(true));
245 dispatch<any>(loadCollectionFiles(this.props.item.uuid));
254 handleContextMenu = (event: React.MouseEvent<any>) => {
255 const { uuid, ownerUuid, name, description, kind, storageClassesDesired } = this.props.item;
256 const menuKind = this.props.dispatch<any>(resourceUuidToContextMenuKind(uuid));
262 storageClassesDesired,
266 // Avoid expanding/collapsing the panel
267 event.stopPropagation();
268 this.props.dispatch<any>(openContextMenu(event, resource));
271 onCopy = (message: string) =>
272 this.props.dispatch(snackbarActions.OPEN_SNACKBAR({
275 kind: SnackbarKind.SUCCESS
278 handleDelete = (key: string, value: string) => () => {
279 this.props.dispatch<any>(deleteCollectionTag(key, value));
282 openCollectionDetails = (e: React.MouseEvent<HTMLElement>) => {
283 const { item } = this.props;
286 this.props.dispatch<any>(openDetailsPanel(item.uuid));
291 onClick: this.openCollectionDetails
298 export const CollectionDetailsAttributes = (props: { item: CollectionResource, twoCol: boolean, classes?: Record<CssRules, string>, showVersionBrowser?: () => void }) => {
299 const item = props.item;
300 const classes = props.classes || { label: '', value: '', button: '' };
301 const isOldVersion = item && item.currentVersionUuid !== item.uuid;
302 const mdSize = props.twoCol ? 6 : 12;
303 const showVersionBrowser = props.showVersionBrowser;
304 const responsiblePersonRef = React.useRef(null);
305 return <Grid container>
306 <Grid item xs={12} md={mdSize}>
307 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
308 label={isOldVersion ? "This version's UUID" : "Collection UUID"}
309 linkToUuid={item.uuid} />
311 <Grid item xs={12} md={mdSize}>
312 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
313 label={isOldVersion ? "This version's PDH" : "Portable data hash"}
314 linkToUuid={item.portableDataHash} />
316 <Grid item xs={12} md={mdSize}>
317 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
318 label='Owner' linkToUuid={item.ownerUuid}
319 uuidEnhancer={(uuid: string) => <ResourceOwnerWithName uuid={uuid} />} />
321 <div data-cy="responsible-person-wrapper" ref={responsiblePersonRef}>
322 <Grid item xs={12} md={12}>
323 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
324 label='Responsible person' linkToUuid={item.ownerUuid}
325 uuidEnhancer={(uuid: string) => <ResponsiblePerson uuid={item.uuid} parentRef={responsiblePersonRef.current} />} />
328 <Grid item xs={12} md={mdSize}>
329 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
331 value={isOldVersion ? undefined : 'this one'}
332 linkToUuid={isOldVersion ? item.currentVersionUuid : undefined} />
334 <Grid item xs={12} md={mdSize}>
336 classLabel={classes.label} classValue={classes.value}
337 label='Version number'
338 value={showVersionBrowser !== undefined
339 ? <Tooltip title="Open version browser"><ButtonLink underline='none' className={classes.button} onClick={() => showVersionBrowser()}>
340 {<span data-cy='collection-version-number'>{item.version}</span>}
341 </ButtonLink></Tooltip>
346 <Grid item xs={12} md={mdSize}>
347 <DetailsAttribute label='Created at' value={formatDate(item.createdAt)} />
349 <Grid item xs={12} md={mdSize}>
350 <DetailsAttribute label='Last modified' value={formatDate(item.modifiedAt)} />
352 <Grid item xs={12} md={mdSize}>
353 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
354 label='Number of files' value={item.fileCount} />
356 <Grid item xs={12} md={mdSize}>
357 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
358 label='Content size' value={formatFileSize(item.fileSizeTotal)} />
360 <Grid item xs={12} md={mdSize}>
361 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
362 label='Storage classes' value={item.storageClassesDesired.join(', ')} />