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";
28 import { openDetailsPanel } from '~/store/details-panel/details-panel-action';
30 type CssRules = 'card' | 'iconHeader' | 'tag' | 'copyIcon' | 'label' | 'value' | 'link';
32 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
34 marginBottom: theme.spacing.unit * 2
38 color: theme.customs.colors.yellow700
41 marginRight: theme.spacing.unit,
42 marginBottom: theme.spacing.unit
45 marginLeft: theme.spacing.unit,
47 color: theme.palette.grey["500"],
54 textTransform: 'none',
59 color: theme.palette.primary.main,
66 interface CollectionPanelDataProps {
67 item: CollectionResource;
71 type CollectionPanelProps = CollectionPanelDataProps & DispatchProp
72 & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
74 export const CollectionPanel = withStyles(styles)(
75 connect((state: RootState, props: RouteComponentProps<{ id: string }>) => {
76 const item = getResource(props.match.params.id)(state.resources);
77 const data = getResourceData(props.match.params.id)(state.resourcesData);
78 return { item, data };
80 class extends React.Component<CollectionPanelProps> {
83 const { classes, item, data, dispatch } = this.props;
86 <Card className={classes.card}>
89 <IconButton onClick={this.openCollectionDetails}>
90 <CollectionIcon className={classes.iconHeader} />
94 <Tooltip title="More options" disableFocusListener>
96 aria-label="More options"
97 onClick={this.handleContextMenu}>
102 title={item && item.name}
103 titleTypographyProps={this.titleProps}
104 subheader={item && item.description}
105 subheaderTypographyProps={this.titleProps} />
107 <Grid container direction="column">
109 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
110 label='Collection UUID'
111 value={item && item.uuid}>
112 <Tooltip title="Copy uuid">
113 <CopyToClipboard text={item && item.uuid} onCopy={() => this.onCopy()}>
114 <CopyIcon className={classes.copyIcon} />
118 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
119 label='Number of files' value={data && data.fileCount} />
120 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
121 label='Content size' value={data && formatFileSize(data.fileSize)} />
122 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
123 label='Owner' value={item && item.ownerUuid} />
124 <span onClick={() => dispatch<any>(navigateToProcess(item.properties.container_request || item.properties.containerRequest))}>
125 <DetailsAttribute classLabel={classes.link} label='Link to process' />
132 <Card className={classes.card}>
133 <CardHeader title="Properties" />
135 <Grid container direction="column">
137 <CollectionTagForm />
141 Object.keys(item.properties).map(k => {
142 return <Chip key={k} className={classes.tag}
143 onDelete={this.handleDelete(k)}
144 label={`${k}: ${item.properties[k]}`} />;
151 <div className={classes.card}>
152 <CollectionPanelFiles />
158 handleContextMenu = (event: React.MouseEvent<any>) => {
159 const { uuid, ownerUuid, name, description, kind, isTrashed } = this.props.item;
167 ? ContextMenuKind.TRASHED_COLLECTION
168 : ContextMenuKind.COLLECTION
170 this.props.dispatch<any>(openContextMenu(event, resource));
173 handleDelete = (key: string) => () => {
174 this.props.dispatch<any>(deleteCollectionTag(key));
178 this.props.dispatch(snackbarActions.OPEN_SNACKBAR({
179 message: "Uuid has been copied",
184 openCollectionDetails = () => {
185 const { item } = this.props;
187 this.props.dispatch(openDetailsPanel(item.uuid));
192 onClick: this.openCollectionDetails