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, 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 } 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 { CollectionTagForm } from './collection-tag-form';
19 import { deleteCollectionTag, navigateToProcess } from '~/store/collection-panel/collection-panel-action';
20 import { getResource } from '~/store/resources/resources';
21 import { openContextMenu } from '~/store/context-menu/context-menu-actions';
22 import { ContextMenuKind } from '~/views-components/context-menu/context-menu';
23 import { formatFileSize } from "~/common/formatters";
24 import { openDetailsPanel } from '~/store/details-panel/details-panel-action';
25 import { snackbarActions, SnackbarKind } from '~/store/snackbar/snackbar-actions';
26 import { PropertyChipComponent } from '~/views-components/resource-properties-form/property-chip';
27 import { IllegalNamingWarning } from '~/components/warning/warning';
29 type CssRules = 'card' | 'iconHeader' | 'tag' | '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
47 textTransform: 'none',
52 color: theme.palette.primary.main,
59 interface CollectionPanelDataProps {
60 item: CollectionResource;
63 type CollectionPanelProps = CollectionPanelDataProps & DispatchProp
64 & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
66 export const CollectionPanel = withStyles(styles)(
67 connect((state: RootState, props: RouteComponentProps<{ id: string }>) => {
68 const item = getResource(props.match.params.id)(state.resources);
71 class extends React.Component<CollectionPanelProps> {
74 const { classes, item, dispatch } = this.props;
77 <Card className={classes.card}>
80 <IconButton onClick={this.openCollectionDetails}>
81 <CollectionIcon className={classes.iconHeader} />
85 <Tooltip title="More options" disableFocusListener>
87 aria-label="More options"
88 onClick={this.handleContextMenu}>
93 title={item && <span><IllegalNamingWarning name={item.name}/>{item.name}</span>}
94 titleTypographyProps={this.titleProps}
95 subheader={item && item.description}
96 subheaderTypographyProps={this.titleProps} />
98 <Grid container direction="column">
100 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
101 label='Collection UUID'
102 linkToUuid={item && item.uuid} />
103 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
104 label='Portable data hash'
105 linkToUuid={item && item.portableDataHash} />
106 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
107 label='Number of files' value={item && item.fileCount} />
108 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
109 label='Content size' value={item && formatFileSize(item.fileSizeTotal)} />
110 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
111 label='Owner' linkToUuid={item && item.ownerUuid} />
112 {(item.properties.container_request || item.properties.containerRequest) &&
113 <span onClick={() => dispatch<any>(navigateToProcess(item.properties.container_request || item.properties.containerRequest))}>
114 <DetailsAttribute classLabel={classes.link} label='Link to process' />
122 <Card className={classes.card}>
123 <CardHeader title="Properties" />
125 <Grid container direction="column">
127 <CollectionTagForm />
130 {Object.keys(item.properties).map(k =>
131 <PropertyChipComponent
132 key={k} className={classes.tag}
133 onDelete={this.handleDelete(k)}
134 propKey={k} propValue={item.properties[k]} />
140 <div className={classes.card}>
141 <CollectionPanelFiles />
147 handleContextMenu = (event: React.MouseEvent<any>) => {
148 const { uuid, ownerUuid, name, description, kind, isTrashed } = this.props.item;
156 ? ContextMenuKind.TRASHED_COLLECTION
157 : ContextMenuKind.COLLECTION
159 this.props.dispatch<any>(openContextMenu(event, resource));
162 onCopy = (message: string) =>
163 this.props.dispatch(snackbarActions.OPEN_SNACKBAR({
166 kind: SnackbarKind.SUCCESS
169 handleDelete = (key: string) => () => {
170 this.props.dispatch<any>(deleteCollectionTag(key));
173 openCollectionDetails = () => {
174 const { item } = this.props;
176 this.props.dispatch(openDetailsPanel(item.uuid));
181 onClick: this.openCollectionDetails