1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as 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 } from '~/store/context-menu/context-menu-actions';
23 import { ContextMenuKind } from '~/views-components/context-menu/context-menu';
24 import { formatDate, formatFileSize } from "~/common/formatters";
25 import { openDetailsPanel } from '~/store/details-panel/details-panel-action';
26 import { snackbarActions, SnackbarKind } from '~/store/snackbar/snackbar-actions';
27 import { getPropertyChip } from '~/views-components/resource-properties-form/property-chip';
28 import { IllegalNamingWarning } from '~/components/warning/warning';
29 import { GroupResource } from '~/models/group';
30 import { UserResource } from '~/models/user';
31 import { getUserUuid } from '~/common/getuser';
32 import { getProgressIndicator } from '~/store/progress-indicator/progress-indicator-reducer';
33 import { COLLECTION_PANEL_LOAD_FILES, loadCollectionFiles, COLLECTION_PANEL_LOAD_FILES_THRESHOLD } from '~/store/collection-panel/collection-panel-files/collection-panel-files-actions';
34 import { Link } from 'react-router-dom';
35 import { Link as ButtonLink } from '@material-ui/core';
37 type CssRules = 'root'
50 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
54 height: 'calc(100vh - 130px)', // (100% viewport height) - (top bar + breadcrumbs)
60 marginBottom: theme.spacing.unit * 2,
65 color: theme.customs.colors.yellow700
68 marginRight: theme.spacing.unit,
69 marginBottom: theme.spacing.unit
82 flexDirection: 'column',
85 textTransform: 'none',
90 color: theme.palette.primary.main,
96 marginLeft: theme.spacing.unit,
101 interface CollectionPanelDataProps {
102 item: CollectionResource;
104 isOldVersion: boolean;
105 isLoadingFiles: boolean;
106 tooManyFiles: boolean;
109 type CollectionPanelProps = CollectionPanelDataProps & DispatchProp
110 & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
112 export const CollectionPanel = withStyles(styles)(
113 connect((state: RootState, props: RouteComponentProps<{ id: string }>) => {
114 const currentUserUUID = getUserUuid(state);
115 const item = getResource<CollectionResource>(props.match.params.id)(state.resources);
116 let isWritable = false;
117 const isOldVersion = item && item.currentVersionUuid !== item.uuid;
118 if (item && !isOldVersion) {
119 if (item.ownerUuid === currentUserUUID) {
122 const itemOwner = getResource<GroupResource | UserResource>(item.ownerUuid)(state.resources);
124 isWritable = itemOwner.writableBy.indexOf(currentUserUUID || '') >= 0;
128 const loadingFilesIndicator = getProgressIndicator(COLLECTION_PANEL_LOAD_FILES)(state.progressIndicator);
129 const isLoadingFiles = loadingFilesIndicator && loadingFilesIndicator!.working || false;
130 const tooManyFiles = !state.collectionPanel.loadBigCollections && item && item.fileCount > COLLECTION_PANEL_LOAD_FILES_THRESHOLD || false;
131 return { item, isWritable, isOldVersion, isLoadingFiles, tooManyFiles };
133 class extends React.Component<CollectionPanelProps> {
135 const { classes, item, dispatch, isWritable, isOldVersion, isLoadingFiles, tooManyFiles } = this.props;
137 ? <div className={classes.root}>
138 <ExpansionPanel data-cy='collection-info-panel' defaultExpanded>
139 <ExpansionPanelSummary expandIcon={<ExpandIcon />}>
140 <Grid container justify="space-between">
141 <Grid item xs={11}><span>
142 <IconButton onClick={this.openCollectionDetails}>
144 ? <CollectionOldVersionIcon className={classes.iconHeader} />
145 : <CollectionIcon className={classes.iconHeader} />}
147 <IllegalNamingWarning name={item.name} />
151 <Tooltip title="Read-only">
152 <ReadOnlyIcon data-cy="read-only-icon" className={classes.readOnlyIcon} />
157 <Grid item xs={1} style={{ textAlign: "right" }}>
158 <Tooltip title="Actions" disableFocusListener>
160 data-cy='collection-panel-options-btn'
162 onClick={this.handleContextMenu}>
168 </ExpansionPanelSummary>
169 <ExpansionPanelDetails>
170 <Grid container justify="space-between">
172 <Typography variant="caption">
175 <CollectionDetailsAttributes item={item} classes={classes} twoCol={true} showVersionBrowser={() => dispatch<any>(openDetailsPanel(item.uuid, 1))} />
176 {(item.properties.container_request || item.properties.containerRequest) &&
177 <span onClick={() => dispatch<any>(navigateToProcess(item.properties.container_request || item.properties.containerRequest))}>
178 <DetailsAttribute classLabel={classes.link} label='Link to process' />
182 <Typography className={classes.warningLabel} variant="caption">
183 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.
188 </ExpansionPanelDetails>
191 <ExpansionPanel data-cy='collection-properties-panel' defaultExpanded>
192 <ExpansionPanelSummary expandIcon={<ExpandIcon />}>
194 </ExpansionPanelSummary>
195 <ExpansionPanelDetails>
197 {isWritable && <Grid item xs={12}>
198 <CollectionTagForm />
201 {Object.keys(item.properties).length > 0
202 ? Object.keys(item.properties).map(k =>
203 Array.isArray(item.properties[k])
204 ? item.properties[k].map((v: string) =>
208 ? this.handleDelete(k, v)
212 k, item.properties[k],
214 ? this.handleDelete(k, item.properties[k])
218 : <div className={classes.centeredLabel}>No properties set on this collection.</div>
222 </ExpansionPanelDetails>
224 <div className={classes.filesCard}>
225 <CollectionPanelFiles
226 isWritable={isWritable}
227 isLoading={isLoadingFiles}
228 tooManyFiles={tooManyFiles}
229 loadFilesFunc={() => {
230 dispatch(collectionPanelActions.LOAD_BIG_COLLECTIONS(true));
231 dispatch<any>(loadCollectionFiles(this.props.item.uuid));
239 handleContextMenu = (event: React.MouseEvent<any>) => {
240 const { uuid, ownerUuid, name, description, kind, isTrashed } = this.props.item;
241 const { isWritable } = this.props;
250 ? ContextMenuKind.TRASHED_COLLECTION
251 : ContextMenuKind.COLLECTION
252 : ContextMenuKind.READONLY_COLLECTION
254 // Avoid expanding/collapsing the panel
255 event.stopPropagation();
256 this.props.dispatch<any>(openContextMenu(event, resource));
259 onCopy = (message: string) =>
260 this.props.dispatch(snackbarActions.OPEN_SNACKBAR({
263 kind: SnackbarKind.SUCCESS
266 handleDelete = (key: string, value: string) => () => {
267 this.props.dispatch<any>(deleteCollectionTag(key, value));
270 openCollectionDetails = (e: React.MouseEvent<HTMLElement>) => {
271 const { item } = this.props;
274 this.props.dispatch<any>(openDetailsPanel(item.uuid));
279 onClick: this.openCollectionDetails
286 export const CollectionDetailsAttributes = (props: { item: CollectionResource, twoCol: boolean, classes?: Record<CssRules, string>, showVersionBrowser?: () => void }) => {
287 const item = props.item;
288 const classes = props.classes || { label: '', value: '', button: '' };
289 const isOldVersion = item && item.currentVersionUuid !== item.uuid;
290 const mdSize = props.twoCol ? 6 : 12;
291 const showVersionBrowser = props.showVersionBrowser;
292 return <Grid container>
293 <Grid item xs={12} md={mdSize}>
294 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
295 label={isOldVersion ? "This version's UUID" : "Collection UUID"}
296 linkToUuid={item.uuid} />
298 <Grid item xs={12} md={mdSize}>
299 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
300 label={isOldVersion ? "This version's PDH" : "Portable data hash"}
301 linkToUuid={item.portableDataHash} />
303 <Grid item xs={12} md={mdSize}>
304 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
305 label='Owner' linkToUuid={item.ownerUuid} />
307 <Grid item xs={12} md={mdSize}>
308 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
310 value={isOldVersion ? undefined : 'this one'}
311 linkToUuid={isOldVersion ? item.currentVersionUuid : undefined} />
313 <Grid item xs={12} md={mdSize}>
315 classLabel={classes.label} classValue={classes.value}
316 label='Version number'
317 value={ showVersionBrowser !== undefined
318 ? <Tooltip title="Open version browser"><ButtonLink underline='none' className={classes.button} onClick={() => showVersionBrowser()}>
319 {<span data-cy='collection-version-number'>{item.version}</span>}
320 </ButtonLink></Tooltip>
325 <Grid item xs={12} md={mdSize}>
326 <DetailsAttribute label='Created at' value={formatDate(item.createdAt)} />
328 <Grid item xs={12} md={mdSize}>
329 <DetailsAttribute label='Last modified' value={formatDate(item.modifiedAt)} />
331 <Grid item xs={12} md={mdSize}>
332 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
333 label='Number of files' value={item.fileCount} />
335 <Grid item xs={12} md={mdSize}>
336 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
337 label='Content size' value={formatFileSize(item.fileSizeTotal)} />