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 { CollectionTagForm } from './collection-tag-form';
20 import { deleteCollectionTag, navigateToProcess } from '~/store/collection-panel/collection-panel-action';
21 import { snackbarActions } from '~/store/snackbar/snackbar-actions';
22 import { getResource } from '~/store/resources/resources';
23 import { openContextMenu } from '~/store/context-menu/context-menu-actions';
24 import { ContextMenuKind } from '~/views-components/context-menu/context-menu';
25 import { formatFileSize } from "~/common/formatters";
26 import { getResourceData } from "~/store/resources-data/resources-data";
27 import { ResourceData } from "~/store/resources-data/resources-data-reducer";
29 type CssRules = 'card' | 'iconHeader' | 'tag' | 'copyIcon' | 'label' | 'value' | 'link';
31 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
33 marginBottom: theme.spacing.unit * 2
37 color: theme.customs.colors.yellow700
40 marginRight: theme.spacing.unit,
41 marginBottom: theme.spacing.unit
44 marginLeft: theme.spacing.unit,
46 color: theme.palette.grey["500"],
53 textTransform: 'none',
58 color: theme.palette.primary.main,
65 interface CollectionPanelDataProps {
66 item: CollectionResource;
70 type CollectionPanelProps = CollectionPanelDataProps & DispatchProp
71 & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
73 export const CollectionPanel = withStyles(styles)(
74 connect((state: RootState, props: RouteComponentProps<{ id: string }>) => {
75 const item = getResource(props.match.params.id)(state.resources);
76 const data = getResourceData(props.match.params.id)(state.resourcesData);
77 return { item, data };
79 class extends React.Component<CollectionPanelProps> {
81 const { classes, item, data, dispatch } = this.props;
84 <Card className={classes.card}>
86 avatar={<CollectionIcon className={classes.iconHeader} />}
88 <Tooltip title="More options" disableFocusListener>
90 aria-label="More options"
91 onClick={this.handleContextMenu}>
96 title={item && item.name}
97 subheader={item && item.description} />
99 <Grid container direction="column">
101 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
102 label='Collection UUID'
103 value={item && item.uuid}>
104 <Tooltip title="Copy uuid">
105 <CopyToClipboard text={item && item.uuid} onCopy={() => this.onCopy()}>
106 <CopyIcon className={classes.copyIcon} />
110 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
111 label='Number of files' value={data && data.fileCount} />
112 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
113 label='Content size' value={data && formatFileSize(data.fileSize)} />
114 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
115 label='Owner' value={item && item.ownerUuid} />
116 <span onClick={() => dispatch<any>(navigateToProcess(item.properties.container_request || item.properties.containerRequest))}>
117 <DetailsAttribute classLabel={classes.link} label='Link to process' />
124 <Card className={classes.card}>
125 <CardHeader title="Properties" />
127 <Grid container direction="column">
129 <CollectionTagForm />
133 Object.keys(item.properties).map(k => {
134 return <Chip key={k} className={classes.tag}
135 onDelete={this.handleDelete(k)}
136 label={`${k}: ${item.properties[k]}`} />;
143 <div className={classes.card}>
144 <CollectionPanelFiles />
150 handleContextMenu = (event: React.MouseEvent<any>) => {
151 const { uuid, ownerUuid, name, description, kind, isTrashed } = this.props.item;
159 ? ContextMenuKind.TRASHED_COLLECTION
160 : ContextMenuKind.COLLECTION
162 this.props.dispatch<any>(openContextMenu(event, resource));
165 handleDelete = (key: string) => () => {
166 this.props.dispatch<any>(deleteCollectionTag(key));
170 this.props.dispatch(snackbarActions.OPEN_SNACKBAR({
171 message: "Uuid has been copied",