X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/e7ba429b7bec690811df51893817968c177853be..78e1b6a903071209acc47ba9272ce87a6561e67e:/src/views/collection-panel/collection-panel.tsx

diff --git a/src/views/collection-panel/collection-panel.tsx b/src/views/collection-panel/collection-panel.tsx
index 0b264b6b..26ee1887 100644
--- a/src/views/collection-panel/collection-panel.tsx
+++ b/src/views/collection-panel/collection-panel.tsx
@@ -22,6 +22,9 @@ import { snackbarActions } from '~/store/snackbar/snackbar-actions';
 import { getResource } from '~/store/resources/resources';
 import { openContextMenu } from '~/store/context-menu/context-menu-actions';
 import { ContextMenuKind } from '~/views-components/context-menu/context-menu';
+import { formatFileSize } from "~/common/formatters";
+import { getResourceData } from "~/store/resources-data/resources-data";
+import { ResourceData } from "~/store/resources-data/resources-data-reducer";
 
 type CssRules = 'card' | 'iconHeader' | 'tag' | 'copyIcon' | 'label' | 'value';
 
@@ -54,6 +57,7 @@ const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
 
 interface CollectionPanelDataProps {
     item: CollectionResource;
+    data: ResourceData;
 }
 
 type CollectionPanelProps = CollectionPanelDataProps & DispatchProp
@@ -62,84 +66,89 @@ type CollectionPanelProps = CollectionPanelDataProps & DispatchProp
 
 export const CollectionPanel = withStyles(styles)(
     connect((state: RootState, props: RouteComponentProps<{ id: string }>) => {
-        const collection = getResource(props.match.params.id)(state.resources);
-        return {
-            item: collection
-        };
+        const item = getResource(props.match.params.id)(state.resources);
+        const data = getResourceData(props.match.params.id)(state.resourcesData);
+        return { item, data };
     })(
         class extends React.Component<CollectionPanelProps> {
             render() {
-                const { classes, item } = this.props;
-                return <div>
-                    <Card className={classes.card}>
-                        <CardHeader
-                            avatar={<CollectionIcon className={classes.iconHeader} />}
-                            action={
-                                <Tooltip title="More options">
-                                    <IconButton
-                                        aria-label="More options"
-                                        onClick={this.handleContextMenu}>
-                                        <MoreOptionsIcon />
-                                    </IconButton>
-                                </Tooltip>
-                            }
-                            title={item && item.name}
-                            subheader={item && item.description} />
-                        <CardContent>
-                            <Grid container direction="column">
-                                <Grid item xs={6}>
-                                    <DetailsAttribute classLabel={classes.label} classValue={classes.value}
-                                        label='Collection UUID'
-                                        value={item && item.uuid}>
-                                        <Tooltip title="Copy uuid">
-                                            <CopyToClipboard text={item && item.uuid} onCopy={() => this.onCopy()}>
-                                                <CopyIcon className={classes.copyIcon} />
-                                            </CopyToClipboard>
-                                        </Tooltip>
-                                    </DetailsAttribute>
-                                    <DetailsAttribute classLabel={classes.label} classValue={classes.value}
-                                        label='Number of files' value='14' />
-                                    <DetailsAttribute classLabel={classes.label} classValue={classes.value}
-                                        label='Content size' value='54 MB' />
-                                    <DetailsAttribute classLabel={classes.label} classValue={classes.value}
-                                        label='Owner' value={item && item.ownerUuid} />
+                const { classes, item, data } = this.props;
+                return item
+                    ? <>
+                        <Card className={classes.card}>
+                            <CardHeader
+                                avatar={<CollectionIcon className={classes.iconHeader} />}
+                                action={
+                                    <Tooltip title="More options" disableFocusListener>
+                                        <IconButton
+                                            aria-label="More options"
+                                            onClick={this.handleContextMenu}>
+                                            <MoreOptionsIcon />
+                                        </IconButton>
+                                    </Tooltip>
+                                }
+                                title={item && item.name}
+                                subheader={item && item.description} />
+                            <CardContent>
+                                <Grid container direction="column">
+                                    <Grid item xs={6}>
+                                        <DetailsAttribute classLabel={classes.label} classValue={classes.value}
+                                            label='Collection UUID'
+                                            value={item && item.uuid}>
+                                            <Tooltip title="Copy uuid">
+                                                <CopyToClipboard text={item && item.uuid} onCopy={() => this.onCopy()}>
+                                                    <CopyIcon className={classes.copyIcon} />
+                                                </CopyToClipboard>
+                                            </Tooltip>
+                                        </DetailsAttribute>
+                                        <DetailsAttribute classLabel={classes.label} classValue={classes.value}
+                                            label='Number of files' value={data && data.fileCount} />
+                                        <DetailsAttribute classLabel={classes.label} classValue={classes.value}
+                                            label='Content size' value={data && formatFileSize(data.fileSize)} />
+                                        <DetailsAttribute classLabel={classes.label} classValue={classes.value}
+                                            label='Owner' value={item && item.ownerUuid} />
+                                    </Grid>
                                 </Grid>
-                            </Grid>
-                        </CardContent>
-                    </Card>
+                            </CardContent>
+                        </Card>
 
-                    <Card className={classes.card}>
-                        <CardHeader title="Properties" />
-                        <CardContent>
-                            <Grid container direction="column">
-                                <Grid item xs={12}><CollectionTagForm /></Grid>
-                                <Grid item xs={12}>
-                                    {
-                                        Object.keys(item.properties).map( key => {
-                                            return <Chip key={key} className={classes.tag}
-                                                onDelete={this.handleDelete(key)}
-                                                label={`${key}: ${item.properties[key]}`} />;
-                                        })
-                                    }
+                        <Card className={classes.card}>
+                            <CardHeader title="Properties" />
+                            <CardContent>
+                                <Grid container direction="column">
+                                    <Grid item xs={12}>
+                                        <CollectionTagForm />
+                                    </Grid>
+                                    <Grid item xs={12}>
+                                        {
+                                            Object.keys(item.properties).map(k => {
+                                                return <Chip key={k} className={classes.tag}
+                                                    onDelete={this.handleDelete(k)}
+                                                    label={`${k}: ${item.properties[k]}`} />;
+                                            })
+                                        }
+                                    </Grid>
                                 </Grid>
-                            </Grid>
-                        </CardContent>
-                    </Card>
-                    <div className={classes.card}>
-                        <CollectionPanelFiles />
-                    </div>
-                </div>;
+                            </CardContent>
+                        </Card>
+                        <div className={classes.card}>
+                            <CollectionPanelFiles />
+                        </div>
+                    </>
+                    : null;
             }
 
             handleContextMenu = (event: React.MouseEvent<any>) => {
-                const { uuid, ownerUuid, name, description, kind } = this.props.item;
+                const { uuid, ownerUuid, name, description, kind, isTrashed } = this.props.item;
                 const resource = {
                     uuid,
                     ownerUuid,
                     name,
                     description,
                     kind,
-                    menuKind: ContextMenuKind.COLLECTION
+                    menuKind: isTrashed
+                        ? ContextMenuKind.TRASHED_COLLECTION
+                        : ContextMenuKind.COLLECTION
                 };
                 this.props.dispatch<any>(openContextMenu(event, resource));
             }
