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, Tooltip
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';
22 import { snackbarActions } from '~/store/snackbar/snackbar-actions';
23 import { getResource } from '~/store/resources/resources';
24 import { openContextMenu } from '~/store/context-menu/context-menu-actions';
25 import { ContextMenuKind } from '~/views-components/context-menu/context-menu';
27 type CssRules = 'card' | 'iconHeader' | 'tag' | 'copyIcon' | 'label' | 'value';
29 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
31 marginBottom: theme.spacing.unit * 2
35 color: theme.customs.colors.yellow700
38 marginRight: theme.spacing.unit,
39 marginBottom: theme.spacing.unit
42 marginLeft: theme.spacing.unit,
44 color: theme.palette.grey["500"],
51 textTransform: 'none',
56 interface CollectionPanelDataProps {
57 item: CollectionResource;
61 type CollectionPanelProps = CollectionPanelDataProps & DispatchProp
62 & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
65 export const CollectionPanel = withStyles(styles)(
66 connect((state: RootState, props: RouteComponentProps<{ id: string }>) => {
67 const collection = getResource(props.match.params.id)(state.resources);
70 tags: state.collectionPanel.tags
73 class extends React.Component<CollectionPanelProps> {
75 const { classes, item, tags } = this.props;
77 <Card className={classes.card}>
79 avatar={<CollectionIcon className={classes.iconHeader} />}
81 <Tooltip title="More options">
83 aria-label="More options"
84 onClick={this.handleContextMenu}>
89 title={item && item.name}
90 subheader={item && item.description} />
92 <Grid container direction="column">
94 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
95 label='Collection UUID'
96 value={item && item.uuid}>
97 <Tooltip title="Copy uuid">
98 <CopyToClipboard text={item && item.uuid} onCopy={() => this.onCopy()}>
99 <CopyIcon className={classes.copyIcon} />
103 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
104 label='Number of files' value='14' />
105 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
106 label='Content size' value='54 MB' />
107 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
108 label='Owner' value={item && item.ownerUuid} />
114 <Card className={classes.card}>
115 <CardHeader title="Properties" />
117 <Grid container direction="column">
118 <Grid item xs={12}><CollectionTagForm /></Grid>
122 return <Chip key={tag.etag} className={classes.tag}
123 onDelete={this.handleDelete(tag.uuid)}
124 label={renderTagLabel(tag)} />;
131 <div className={classes.card}>
132 <CollectionPanelFiles />
137 handleContextMenu = (event: React.MouseEvent<any>) => {
138 const { uuid, ownerUuid, name, description, kind } = this.props.item;
145 menuKind: ContextMenuKind.COLLECTION
147 this.props.dispatch<any>(openContextMenu(event, resource));
150 handleDelete = (uuid: string) => () => {
151 this.props.dispatch<any>(deleteCollectionTag(uuid));
155 this.props.dispatch(snackbarActions.OPEN_SNACKBAR({
156 message: "Uuid has been copied",
164 const renderTagLabel = (tag: TagResource) => {
165 const { properties } = tag;
166 return `${properties.key}: ${properties.value}`;