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, TextField, Button
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 * as CopyToClipboard from 'react-copy-to-clipboard';
18 import { createCollectionTag } from '../../store/collection-panel/collection-panel-action';
19 import { LinkResource } from '../../models/link';
21 type CssRules = 'card' | 'iconHeader' | 'tag' | 'copyIcon';
23 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
29 color: theme.customs.colors.yellow700
32 marginRight: theme.spacing.unit
35 marginLeft: theme.spacing.unit,
37 color: theme.palette.grey["500"],
42 interface CollectionPanelDataProps {
43 item: CollectionResource;
47 interface CollectionPanelActionProps {
48 onItemRouteChange: (collectionId: string) => void;
49 onContextMenu: (event: React.MouseEvent<HTMLElement>, item: CollectionResource) => void;
52 type CollectionPanelProps = CollectionPanelDataProps & CollectionPanelActionProps & DispatchProp
53 & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
56 export const CollectionPanel = withStyles(styles)(
57 connect((state: RootState) => ({
58 item: state.collectionPanel.item,
59 tags: state.collectionPanel.tags
61 class extends React.Component<CollectionPanelProps> {
64 const { classes, item, tags, onContextMenu } = this.props;
66 <Card className={classes.card}>
68 avatar={ <CollectionIcon className={classes.iconHeader} /> }
71 aria-label="More options"
72 onClick={event => onContextMenu(event, item)}>
76 title={item && item.name }
77 subheader={item && item.description} />
79 <Grid container direction="column">
81 <DetailsAttribute label='Collection UUID' value={item && item.uuid}>
82 <CopyToClipboard text={item && item.uuid}>
83 <CopyIcon className={classes.copyIcon} />
86 <DetailsAttribute label='Content size' value='54 MB' />
87 <DetailsAttribute label='Owner' value={item && item.ownerUuid} />
93 <Card className={classes.card}>
94 <CardHeader title="Tags" />
96 <Grid container direction="column">
98 {/* Temporarty button to add new tag */}
99 <Button onClick={this.addTag}>Add Tag</Button>
104 return <Chip key={tag.etag} className={classes.tag}
105 label={renderTagLabel(tag)} />;
113 <Card className={classes.card}>
114 <CardHeader title="Files" />
116 <Grid container direction="column">
126 // Temporary method to add new tag
128 this.props.dispatch<any>(createCollectionTag(this.props.item.uuid, 'dodalem nowy'));
131 componentWillReceiveProps({ match, item, onItemRouteChange }: CollectionPanelProps) {
132 if (!item || match.params.id !== item.uuid) {
133 onItemRouteChange(match.params.id);
141 const renderTagLabel = (tag: LinkResource) => {
142 const { properties } = tag;
143 return `${properties.key}: ${properties.value}`;