import * as React from 'react';
import {
StyleRulesCallback, WithStyles, withStyles, Card,
- CardHeader, IconButton, CardContent, Grid, Chip, Tooltip
+ CardHeader, IconButton, CardContent, Grid, Tooltip
} from '@material-ui/core';
import { connect, DispatchProp } from "react-redux";
import { RouteComponentProps } from 'react-router';
import { ArvadosTheme } from '~/common/custom-theme';
import { RootState } from '~/store/store';
-import { MoreOptionsIcon, CollectionIcon, CopyIcon } from '~/components/icon/icon';
+import { MoreOptionsIcon, CollectionIcon, ReadOnlyIcon } from '~/components/icon/icon';
import { DetailsAttribute } from '~/components/details-attribute/details-attribute';
import { CollectionResource } from '~/models/collection';
import { CollectionPanelFiles } from '~/views-components/collection-panel-files/collection-panel-files';
-import * as CopyToClipboard from 'react-copy-to-clipboard';
import { CollectionTagForm } from './collection-tag-form';
-import { deleteCollectionTag } from '~/store/collection-panel/collection-panel-action';
-import { snackbarActions } from '~/store/snackbar/snackbar-actions';
+import { deleteCollectionTag, navigateToProcess, collectionPanelActions } from '~/store/collection-panel/collection-panel-action';
import { getResource } from '~/store/resources/resources';
import { openContextMenu } from '~/store/context-menu/context-menu-actions';
import { ContextMenuKind } from '~/views-components/context-menu/context-menu';
import { formatFileSize } from "~/common/formatters";
+import { openDetailsPanel } from '~/store/details-panel/details-panel-action';
+import { snackbarActions, SnackbarKind } from '~/store/snackbar/snackbar-actions';
+import { getPropertyChip } from '~/views-components/resource-properties-form/property-chip';
+import { IllegalNamingWarning } from '~/components/warning/warning';
+import { GroupResource } from '~/models/group';
+import { UserResource } from '~/models/user';
+import { getUserUuid } from '~/common/getuser';
+import { getProgressIndicator } from '~/store/progress-indicator/progress-indicator-reducer';
+import { COLLECTION_PANEL_LOAD_FILES, loadCollectionFiles, COLLECTION_PANEL_LOAD_FILES_THRESHOLD } from '~/store/collection-panel/collection-panel-files/collection-panel-files-actions';
-type CssRules = 'card' | 'iconHeader' | 'tag' | 'copyIcon' | 'label' | 'value';
+type CssRules = 'root'
+ | 'card'
+ | 'cardHeader'
+ | 'filesCard'
+ | 'cardContent'
+ | 'iconHeader'
+ | 'tag'
+ | 'label'
+ | 'value'
+ | 'link'
+ | 'centeredLabel'
+ | 'readOnlyIcon';
const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
+ root: {
+ display: 'flex',
+ flexFlow: 'column',
+ height: 'calc(100vh - 130px)', // (100% viewport height) - (top bar + breadcrumbs)
+ },
card: {
- marginBottom: theme.spacing.unit * 2
+ marginBottom: theme.spacing.unit * 2,
+ },
+ cardHeader: {
+ paddingTop: theme.spacing.unit,
+ paddingBottom: 0,
+ },
+ filesCard: {
+ marginBottom: theme.spacing.unit * 2,
+ flex: 1,
+ },
+ cardContent: {
+ paddingTop: 0,
+ paddingBottom: theme.spacing.unit,
+ '&:last-child': {
+ paddingBottom: theme.spacing.unit,
+ }
},
iconHeader: {
fontSize: '1.875rem',
marginRight: theme.spacing.unit,
marginBottom: theme.spacing.unit
},
- copyIcon: {
- marginLeft: theme.spacing.unit,
- fontSize: '1.125rem',
- color: theme.palette.grey["500"],
- cursor: 'pointer'
- },
label: {
fontSize: '0.875rem'
},
+ centeredLabel: {
+ fontSize: '0.875rem',
+ textAlign: 'center'
+ },
value: {
textTransform: 'none',
fontSize: '0.875rem'
+ },
+ link: {
+ fontSize: '0.875rem',
+ color: theme.palette.primary.main,
+ '&:hover': {
+ cursor: 'pointer'
+ }
+ },
+ readOnlyIcon: {
+ marginLeft: theme.spacing.unit,
+ fontSize: 'small',
}
});
interface CollectionPanelDataProps {
item: CollectionResource;
+ isWritable: boolean;
+ isLoadingFiles: boolean;
+ tooManyFiles: boolean;
}
type CollectionPanelProps = CollectionPanelDataProps & DispatchProp
& WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
-
export const CollectionPanel = withStyles(styles)(
connect((state: RootState, props: RouteComponentProps<{ id: string }>) => {
- const collection = getResource(props.match.params.id)(state.resources);
- return {
- item: collection
- };
+ const currentUserUUID = getUserUuid(state);
+ const item = getResource<CollectionResource>(props.match.params.id)(state.resources);
+ let isWritable = false;
+ if (item && item.ownerUuid === currentUserUUID) {
+ isWritable = true;
+ } else if (item) {
+ const itemOwner = getResource<GroupResource|UserResource>(item.ownerUuid)(state.resources);
+ if (itemOwner) {
+ isWritable = itemOwner.writableBy.indexOf(currentUserUUID || '') >= 0;
+ }
+ }
+ const loadingFilesIndicator = getProgressIndicator(COLLECTION_PANEL_LOAD_FILES)(state.progressIndicator);
+ const isLoadingFiles = loadingFilesIndicator && loadingFilesIndicator!.working || false;
+ const tooManyFiles = !state.collectionPanel.loadBigCollections && item && item.fileCount > COLLECTION_PANEL_LOAD_FILES_THRESHOLD || false;
+ return { item, isWritable, isLoadingFiles, tooManyFiles };
})(
class extends React.Component<CollectionPanelProps> {
render() {
- const { classes, item } = this.props;
+ const { classes, item, dispatch, isWritable, isLoadingFiles, tooManyFiles } = this.props;
return item
- ? <>
- <Card className={classes.card}>
+ ? <div className={classes.root}>
+ <Card data-cy='collection-info-panel' className={classes.card}>
<CardHeader
- avatar={<CollectionIcon className={classes.iconHeader} />}
+ className={classes.cardHeader}
+ avatar={
+ <IconButton onClick={this.openCollectionDetails}>
+ <CollectionIcon className={classes.iconHeader} />
+ </IconButton>
+ }
action={
- <Tooltip title="More options">
+ <Tooltip title="More options" disableFocusListener>
<IconButton
+ data-cy='collection-panel-options-btn'
aria-label="More options"
onClick={this.handleContextMenu}>
<MoreOptionsIcon />
</IconButton>
</Tooltip>
}
- title={item && item.name}
- subheader={item && item.description} />
- <CardContent>
+ title={
+ <span>
+ <IllegalNamingWarning name={item.name}/>
+ {item.name}
+ {isWritable ||
+ <Tooltip title="Read-only">
+ <ReadOnlyIcon data-cy="read-only-icon" className={classes.readOnlyIcon} />
+ </Tooltip>
+ }
+ </span>
+ }
+ titleTypographyProps={this.titleProps}
+ subheader={item.description}
+ subheaderTypographyProps={this.titleProps} />
+ <CardContent className={classes.cardContent}>
<Grid container direction="column">
- <Grid item xs={6}>
+ <Grid item xs={10}>
<DetailsAttribute classLabel={classes.label} classValue={classes.value}
label='Collection UUID'
- value={item && item.uuid}>
- <Tooltip title="Copy uuid">
- <CopyToClipboard text={item && item.uuid} onCopy={() => this.onCopy()}>
- <CopyIcon className={classes.copyIcon} />
- </CopyToClipboard>
- </Tooltip>
- </DetailsAttribute>
+ linkToUuid={item.uuid} />
+ <DetailsAttribute classLabel={classes.label} classValue={classes.value}
+ label='Portable data hash'
+ linkToUuid={item.portableDataHash} />
<DetailsAttribute classLabel={classes.label} classValue={classes.value}
- label='Number of files' value={item && item.fileCount} />
+ label='Number of files' value={item.fileCount} />
<DetailsAttribute classLabel={classes.label} classValue={classes.value}
- label='Content size' value={item && formatFileSize(item.fileSize)} />
+ label='Content size' value={formatFileSize(item.fileSizeTotal)} />
<DetailsAttribute classLabel={classes.label} classValue={classes.value}
- label='Owner' value={item && item.ownerUuid} />
+ label='Owner' linkToUuid={item.ownerUuid} />
+ {(item.properties.container_request || item.properties.containerRequest) &&
+ <span onClick={() => dispatch<any>(navigateToProcess(item.properties.container_request || item.properties.containerRequest))}>
+ <DetailsAttribute classLabel={classes.link} label='Link to process' />
+ </span>
+ }
</Grid>
</Grid>
</CardContent>
</Card>
- <Card className={classes.card}>
+ <Card data-cy='collection-properties-panel' className={classes.card}>
<CardHeader title="Properties" />
- <CardContent>
+ <CardContent className={classes.cardContent}>
<Grid container direction="column">
- <Grid item xs={12}>
+ {isWritable && <Grid item xs={12}>
<CollectionTagForm />
- </Grid>
+ </Grid>}
<Grid item xs={12}>
- {
- Object.keys(item.properties).map(k => {
- return <Chip key={k} className={classes.tag}
- onDelete={this.handleDelete(k)}
- label={`${k}: ${item.properties[k]}`} />;
- })
- }
+ { Object.keys(item.properties).length > 0
+ ? Object.keys(item.properties).map(k =>
+ Array.isArray(item.properties[k])
+ ? item.properties[k].map((v: string) =>
+ getPropertyChip(
+ k, v,
+ isWritable
+ ? this.handleDelete(k, item.properties[k])
+ : undefined,
+ classes.tag))
+ : getPropertyChip(
+ k, item.properties[k],
+ isWritable
+ ? this.handleDelete(k, item.properties[k])
+ : undefined,
+ classes.tag)
+ )
+ : <div className={classes.centeredLabel}>No properties set on this collection.</div>
+ }
</Grid>
</Grid>
</CardContent>
</Card>
- <div className={classes.card}>
- <CollectionPanelFiles />
+ <div className={classes.filesCard}>
+ <CollectionPanelFiles
+ isWritable={isWritable}
+ isLoading={isLoadingFiles}
+ tooManyFiles={tooManyFiles}
+ loadFilesFunc={() => {
+ dispatch(collectionPanelActions.LOAD_BIG_COLLECTIONS(true));
+ dispatch<any>(loadCollectionFiles(this.props.item.uuid));
+ }
+ } />
</div>
- </>
+ </div>
: null;
}
handleContextMenu = (event: React.MouseEvent<any>) => {
const { uuid, ownerUuid, name, description, kind, isTrashed } = this.props.item;
+ const { isWritable } = this.props;
const resource = {
uuid,
ownerUuid,
name,
description,
kind,
- menuKind: isTrashed
- ? ContextMenuKind.TRASHED_COLLECTION
- : ContextMenuKind.COLLECTION
+ menuKind: isWritable
+ ? isTrashed
+ ? ContextMenuKind.TRASHED_COLLECTION
+ : ContextMenuKind.COLLECTION
+ : ContextMenuKind.READONLY_COLLECTION
};
this.props.dispatch<any>(openContextMenu(event, resource));
}
- handleDelete = (key: string) => () => {
- this.props.dispatch<any>(deleteCollectionTag(key));
+ onCopy = (message: string) =>
+ this.props.dispatch(snackbarActions.OPEN_SNACKBAR({
+ message,
+ hideDuration: 2000,
+ kind: SnackbarKind.SUCCESS
+ }))
+
+ handleDelete = (key: string, value: string) => () => {
+ this.props.dispatch<any>(deleteCollectionTag(key, value));
}
- onCopy = () => {
- this.props.dispatch(snackbarActions.OPEN_SNACKBAR({
- message: "Uuid has been copied",
- hideDuration: 2000
- }));
+ openCollectionDetails = () => {
+ const { item } = this.props;
+ if (item) {
+ this.props.dispatch(openDetailsPanel(item.uuid));
+ }
}
+
+ titleProps = {
+ onClick: this.openCollectionDetails
+ };
+
}
)
);