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 { getResourceData } from "~/store/resources-data/resources-data";
25 import { ResourceData } from "~/store/resources-data/resources-data-reducer";
26 import { openDetailsPanel } from '~/store/details-panel/details-panel-action';
27 import { snackbarActions, SnackbarKind } from '~/store/snackbar/snackbar-actions';
28 import { PropertyChipComponent } from '~/views-components/resource-properties-form/property-chip';
29 import { IllegalNamingWarning } from '~/components/warning/warning';
31 type CssRules = 'card' | 'iconHeader' | 'tag' | 'label' | 'value' | 'link';
33 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
35 marginBottom: theme.spacing.unit * 2
39 color: theme.customs.colors.yellow700
42 marginRight: theme.spacing.unit,
43 marginBottom: theme.spacing.unit
49 textTransform: 'none',
54 color: theme.palette.primary.main,
61 interface CollectionPanelDataProps {
62 item: CollectionResource;
66 type CollectionPanelProps = CollectionPanelDataProps & DispatchProp
67 & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
69 export const CollectionPanel = withStyles(styles)(
70 connect((state: RootState, props: RouteComponentProps<{ id: string }>) => {
71 const item = getResource(props.match.params.id)(state.resources);
72 const data = getResourceData(props.match.params.id)(state.resourcesData);
73 return { item, data };
75 class extends React.Component<CollectionPanelProps> {
78 const { classes, item, data, dispatch } = this.props;
81 <Card className={classes.card}>
84 <IconButton onClick={this.openCollectionDetails}>
85 <CollectionIcon className={classes.iconHeader} />
89 <Tooltip title="More options" disableFocusListener>
91 aria-label="More options"
92 onClick={this.handleContextMenu}>
97 title={item && <span><IllegalNamingWarning name={item.name}/>{item.name}</span>}
98 titleTypographyProps={this.titleProps}
99 subheader={item && item.description}
100 subheaderTypographyProps={this.titleProps} />
102 <Grid container direction="column">
104 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
105 label='Collection UUID'
106 linkToUuid={item && item.uuid} />
107 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
108 label='Portable data hash'
109 linkToUuid={item && item.portableDataHash} />
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' linkToUuid={item && item.ownerUuid} />
116 {(item.properties.container_request || item.properties.containerRequest) &&
117 <span onClick={() => dispatch<any>(navigateToProcess(item.properties.container_request || item.properties.containerRequest))}>
118 <DetailsAttribute classLabel={classes.link} label='Link to process' />
126 <Card className={classes.card}>
127 <CardHeader title="Properties" />
129 <Grid container direction="column">
131 <CollectionTagForm />
134 {Object.keys(item.properties).map(k =>
135 <PropertyChipComponent
136 key={k} className={classes.tag}
137 onDelete={this.handleDelete(k)}
138 propKey={k} propValue={item.properties[k]} />
144 <div className={classes.card}>
145 <CollectionPanelFiles />
151 handleContextMenu = (event: React.MouseEvent<any>) => {
152 const { uuid, ownerUuid, name, description, kind, isTrashed } = this.props.item;
160 ? ContextMenuKind.TRASHED_COLLECTION
161 : ContextMenuKind.COLLECTION
163 this.props.dispatch<any>(openContextMenu(event, resource));
166 onCopy = (message: string) =>
167 this.props.dispatch(snackbarActions.OPEN_SNACKBAR({
170 kind: SnackbarKind.SUCCESS
173 handleDelete = (key: string) => () => {
174 this.props.dispatch<any>(deleteCollectionTag(key));
177 openCollectionDetails = () => {
178 const { item } = this.props;
180 this.props.dispatch(openDetailsPanel(item.uuid));
185 onClick: this.openCollectionDetails