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, Card,
8 CardHeader, IconButton, CardContent, Grid, Chip
9 } from '@material-ui/core';
10 import { connect, DispatchProp } from "react-redux";
11 import { RouteComponentProps } from 'react-router';
12 import { ArvadosTheme } from '~/common/custom-theme';
13 import { RootState } from '~/store/store';
14 import { MoreOptionsIcon, CollectionIcon, CopyIcon } from '~/components/icon/icon';
15 import { DetailsAttribute } from '~/components/details-attribute/details-attribute';
16 import { CollectionResource } from '~/models/collection';
17 import { CollectionPanelFiles } from '~/views-components/collection-panel-files/collection-panel-files';
18 import * as CopyToClipboard from 'react-copy-to-clipboard';
19 import { TagResource } from '~/models/tag';
20 import { CollectionTagForm } from './collection-tag-form';
21 import { deleteCollectionTag } from '~/store/collection-panel/collection-panel-action';
23 type CssRules = 'card' | 'iconHeader' | 'tag' | 'copyIcon' | 'value';
25 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
27 marginBottom: theme.spacing.unit * 2
31 color: theme.customs.colors.yellow700
34 marginRight: theme.spacing.unit,
35 marginBottom: theme.spacing.unit
38 marginLeft: theme.spacing.unit,
40 color: theme.palette.grey["500"],
48 interface CollectionPanelDataProps {
49 item: CollectionResource;
53 interface CollectionPanelActionProps {
54 onItemRouteChange: (collectionId: string) => void;
55 onContextMenu: (event: React.MouseEvent<HTMLElement>, item: CollectionResource) => void;
58 type CollectionPanelProps = CollectionPanelDataProps & CollectionPanelActionProps & DispatchProp
59 & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
62 export const CollectionPanel = withStyles(styles)(
63 connect((state: RootState) => ({
64 item: state.collectionPanel.item,
65 tags: state.collectionPanel.tags
67 class extends React.Component<CollectionPanelProps> {
70 const { classes, item, tags, onContextMenu } = this.props;
72 <Card className={classes.card}>
74 avatar={ <CollectionIcon className={classes.iconHeader} /> }
77 aria-label="More options"
78 onClick={event => onContextMenu(event, item)}>
82 title={item && item.name }
83 subheader={item && item.description} />
85 <Grid container direction="column">
87 <DetailsAttribute classValue={classes.value}
88 label='Collection UUID'
89 value={item && item.uuid}>
90 <CopyToClipboard text={item && item.uuid}>
91 <CopyIcon className={classes.copyIcon} />
94 <DetailsAttribute label='Number of files' value='14' />
95 <DetailsAttribute label='Content size' value='54 MB' />
96 <DetailsAttribute classValue={classes.value} label='Owner' value={item && item.ownerUuid} />
102 <Card className={classes.card}>
103 <CardHeader title="Tags" />
105 <Grid container direction="column">
106 <Grid item xs={12}><CollectionTagForm /></Grid>
110 return <Chip key={tag.etag} className={classes.tag}
111 onDelete={this.handleDelete(tag.uuid)}
112 label={renderTagLabel(tag)} />;
119 <div className={classes.card}>
120 <CollectionPanelFiles/>
125 handleDelete = (uuid: string) => () => {
126 this.props.dispatch<any>(deleteCollectionTag(uuid));
129 componentWillReceiveProps({ match, item, onItemRouteChange }: CollectionPanelProps) {
130 if (!item || match.params.id !== item.uuid) {
131 onItemRouteChange(match.params.id);
139 const renderTagLabel = (tag: TagResource) => {
140 const { properties } = tag;
141 return `${properties.key}: ${properties.value}`;