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' | 'label' | '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"],
47 textTransform: 'none',
52 interface CollectionPanelDataProps {
53 item: CollectionResource;
57 interface CollectionPanelActionProps {
58 onItemRouteChange: (collectionId: string) => void;
59 onContextMenu: (event: React.MouseEvent<HTMLElement>, item: CollectionResource) => void;
62 type CollectionPanelProps = CollectionPanelDataProps & CollectionPanelActionProps & DispatchProp
63 & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
66 export const CollectionPanel = withStyles(styles)(
67 connect((state: RootState) => ({
68 item: state.collectionPanel.item,
69 tags: state.collectionPanel.tags
71 class extends React.Component<CollectionPanelProps> {
74 const { classes, item, tags, onContextMenu } = this.props;
76 <Card className={classes.card}>
78 avatar={ <CollectionIcon className={classes.iconHeader} /> }
81 aria-label="More options"
82 onClick={event => onContextMenu(event, item)}>
86 title={item && item.name }
87 subheader={item && item.description} />
89 <Grid container direction="column">
91 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
92 label='Collection UUID'
93 value={item && item.uuid}>
94 <CopyToClipboard text={item && item.uuid}>
95 <CopyIcon className={classes.copyIcon} />
98 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
99 label='Number of files' value='14' />
100 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
101 label='Content size' value='54 MB' />
102 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
103 label='Owner' value={item && item.ownerUuid} />
109 <Card className={classes.card}>
110 <CardHeader title="Properties" />
112 <Grid container direction="column">
113 <Grid item xs={12}><CollectionTagForm /></Grid>
117 return <Chip key={tag.etag} className={classes.tag}
118 onDelete={this.handleDelete(tag.uuid)}
119 label={renderTagLabel(tag)} />;
126 <div className={classes.card}>
127 <CollectionPanelFiles/>
132 handleDelete = (uuid: string) => () => {
133 this.props.dispatch<any>(deleteCollectionTag(uuid));
136 componentWillReceiveProps({ match, item, onItemRouteChange }: CollectionPanelProps) {
137 if (!item || match.params.id !== item.uuid) {
138 onItemRouteChange(match.params.id);
146 const renderTagLabel = (tag: TagResource) => {
147 const { properties } = tag;
148 return `${properties.key}: ${properties.value}`;