X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/f5e55e7a71f2fc2390d392af752c61b4d3135cb6..c956bd958d3fb90ce51d758fb99d1d88cf589062:/src/views-components/details-panel/details-panel.tsx

diff --git a/src/views-components/details-panel/details-panel.tsx b/src/views-components/details-panel/details-panel.tsx
index 138c91a5..a298d670 100644
--- a/src/views-components/details-panel/details-panel.tsx
+++ b/src/views-components/details-panel/details-panel.tsx
@@ -3,86 +3,23 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import * as React from 'react';
-import Drawer from '@material-ui/core/Drawer';
-import IconButton from "@material-ui/core/IconButton";
+import { Drawer, IconButton, Tabs, Tab, Typography, Grid } from '@material-ui/core';
 import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core/styles';
-import { ArvadosTheme } from '../../common/custom-theme';
-import Attribute from '../../components/attribute/attribute';
-import Tabs from '@material-ui/core/Tabs';
-import Tab from '@material-ui/core/Tab';
-import Typography from '@material-ui/core/Typography';
-import Grid from '@material-ui/core/Grid';
+import { ArvadosTheme } from '~/common/custom-theme';
 import * as classnames from "classnames";
-import { connect, Dispatch } from 'react-redux';
-import EmptyState from '../../components/empty-state/empty-state';
-import { RootState } from '../../store/store';
-import actions from "../../store/details-panel/details-panel-action";
-import { Resource } from '../../common/api/common-resource-service';
-import { ResourceKind } from '../../models/kinds';
-import { ProjectResource } from '../../models/project';
-import { CollectionResource } from '../../models/collection';
-import IconBase, { IconTypes } from '../../components/icon/icon';
-import { ProcessResource } from '../../models/process';
-
-export interface DetailsPanelDataProps {
-    onCloseDrawer: () => void;
-    isOpened: boolean;
-    icon: IconTypes;
-    title: string;
-    details: React.ReactElement<any>;
-}
-
-type DetailsPanelProps = DetailsPanelDataProps & WithStyles<CssRules>;
-
-class DetailsPanel extends React.Component<DetailsPanelProps, {}> {
-    state = {
-        tabsValue: 0
-    };
-
-    handleChange = (event: any, value: boolean) => {
-        this.setState({ tabsValue: value });
-    }
-
-    renderTabContainer = (children: React.ReactElement<any>) =>
-        <Typography className={this.props.classes.tabContainer} component="div">
-            {children}
-        </Typography>
-
-    render() {
-        const { classes, onCloseDrawer, isOpened, icon, title, details } = this.props;
-        const { tabsValue } = this.state;
-        return (
-            <Typography component="div" className={classnames([classes.container, { [classes.opened]: isOpened }])}>
-                <Drawer variant="permanent" anchor="right" classes={{ paper: classes.drawerPaper }}>
-                    <Typography component="div" className={classes.headerContainer}>
-                        <Grid container alignItems='center' justify='space-around'>
-                            <IconBase className={classes.headerIcon} icon={icon} />
-                            <Typography variant="title">
-                                {title}
-                            </Typography>
-                            <IconButton color="inherit" onClick={onCloseDrawer}>
-                                <IconBase icon={IconTypes.CLOSE} />
-                            </IconButton>
-                        </Grid>
-                    </Typography>
-                    <Tabs value={tabsValue} onChange={this.handleChange}>
-                        <Tab disableRipple label="Details" />
-                        <Tab disableRipple label="Activity" />
-                    </Tabs>
-                    {tabsValue === 0 && this.renderTabContainer(
-                        <Grid container direction="column">
-                            {details}
-                        </Grid>
-                    )}
-                    {tabsValue === 1 && this.renderTabContainer(
-                        <Grid container direction="column" />
-                    )}
-                </Drawer>
-            </Typography>
-        );
-    }
-
-}
+import { connect } from 'react-redux';
+import { RootState } from '~/store/store';
+import { detailsPanelActions } from "~/store/details-panel/details-panel-action";
+import { CloseIcon } from '~/components/icon/icon';
+import { EmptyResource } from '~/models/empty';
+import { Dispatch } from "redux";
+import { ResourceKind } from "~/models/resource";
+import { ProjectDetails } from "./project-details";
+import { CollectionDetails } from "./collection-details";
+import { ProcessDetails } from "./process-details";
+import { EmptyDetails } from "./empty-details";
+import { DetailsData } from "./details-data";
+import { DetailsResource } from "~/models/details";
 
 type CssRules = 'drawerPaper' | 'container' | 'opened' | 'headerContainer' | 'headerIcon' | 'tabContainer';
 
@@ -104,7 +41,8 @@ const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
     },
     headerContainer: {
         color: theme.palette.grey["600"],
-        margin: `${theme.spacing.unit}px 0`
+        margin: `${theme.spacing.unit}px 0`,
+        textAlign: 'center'
     },
     headerIcon: {
         fontSize: "34px"
@@ -114,99 +52,95 @@ const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
     }
 });
 
-type DetailsPanelResource = ProjectResource | CollectionResource | ProcessResource;
-
-const getIcon = (res: DetailsPanelResource) => {
+const getItem = (resource: DetailsResource): DetailsData => {
+    const res = resource || { kind: undefined, name: 'Projects' };
     switch (res.kind) {
-        case ResourceKind.Project:
-            return IconTypes.FOLDER;
-        case ResourceKind.Collection:
-            return IconTypes.COLLECTION;
-        case ResourceKind.Process:
-            return IconTypes.PROCESS;
+        case ResourceKind.PROJECT:
+            return new ProjectDetails(res);
+        case ResourceKind.COLLECTION:
+            return new CollectionDetails(res);
+        case ResourceKind.PROCESS:
+            return new ProcessDetails(res);
         default:
-            return IconTypes.FOLDER;
+            return new EmptyDetails(res as EmptyResource);
     }
 };
 
-const getDetails = (res: DetailsPanelResource) => {
-    switch (res.kind) {
-        case ResourceKind.Project:
-            return <div>
-                <Attribute label='Type' value='Project' />
-                <Attribute label='Size' value='---' />
-                <Attribute label="Location">
-                    <IconBase icon={IconTypes.FOLDER} />
-                    Projects
-                </Attribute>
-                <Attribute label='Owner' value='me' />
-                <Attribute label='Last modified' value='5:25 PM 5/23/2018' />
-                <Attribute label='Created at' value='1:25 PM 5/23/2018' />
-                <Attribute label='File size' value='1.4 GB' />
-            </div>;
-        case ResourceKind.Collection:
-            return <div>
-                <Attribute label='Type' value='Data Collection' />
-                <Attribute label='Size' value='---' />
-                <Attribute label="Location">
-                    <IconBase icon={IconTypes.FOLDER} />
-                    Projects
-                </Attribute>
-                <Attribute label='Owner' value='me' />
-                <Attribute label='Last modified' value='5:25 PM 5/23/2018' />
-                <Attribute label='Created at' value='1:25 PM 5/23/2018' />
-                <Attribute label='Number of files' value='20' />
-                <Attribute label='Content size' value='54 MB' />
-                <Attribute label='Collection UUID' link='http://www.google.pl' value='nfnz05wp63ibf8w' />
-                <Attribute label='Content address' link='http://www.google.pl' value='nfnz05wp63ibf8w' />
-                <Attribute label='Creator' value='Chrystian' />
-                <Attribute label='Used by' value='---' />
-            </div>;
-        case ResourceKind.Process:
-            return <div>
-                <Attribute label='Type' value='Process' />
-                <Attribute label='Size' value='---' />
-                <Attribute label="Location">
-                    <IconBase icon={IconTypes.FOLDER} />
-                    Projects
-                </Attribute>
-                <Attribute label='Owner' value='me' />
-                <Attribute label='Last modified' value='5:25 PM 5/23/2018' />
-                <Attribute label='Created at' value='1:25 PM 5/23/2018' />
-                <Attribute label='Finished at' value='1:25 PM 5/23/2018' />
-                <Attribute label='Outputs' link='http://www.google.pl' value='Container Output' />
-                <Attribute label='UUID' link='http://www.google.pl' value='nfnz05wp63ibf8w' />
-                <Attribute label='Container UUID' link='http://www.google.pl' value='nfnz05wp63ibf8w' />
-                <Attribute label='Priority' value='1' />
-                <Attribute label='Runtime constrains' value='1' />
-                <Attribute label='Docker image locator' link='http://www.google.pl' value='3838388226321' />
-            </div>;
-        default:
-            return getEmptyState();
-    }
-};
-
-const getEmptyState = () => {
-    return <EmptyState icon={ IconTypes.ANNOUNCEMENT } 
-        message='Select a file or folder to view its details.' />;
-};
-
-const mapStateToProps = ({ detailsPanel }: RootState) => {
-    const { isOpened, item } = detailsPanel;
-    return {
-        isOpened,
-        title: item ? (item as DetailsPanelResource).name : 'Projects',
-        icon: item ? getIcon(item as DetailsPanelResource) : IconTypes.FOLDER,
-        details: item ? getDetails(item as DetailsPanelResource) : getEmptyState()
-    };
-};
+const mapStateToProps = ({ detailsPanel }: RootState) => ({
+    isOpened: detailsPanel.isOpened,
+    item: getItem(detailsPanel.item as DetailsResource)
+});
 
 const mapDispatchToProps = (dispatch: Dispatch) => ({
     onCloseDrawer: () => {
-        dispatch(actions.TOGGLE_DETAILS_PANEL());
+        dispatch(detailsPanelActions.TOGGLE_DETAILS_PANEL());
     }
 });
 
-const DetailsPanelContainer = connect(mapStateToProps, mapDispatchToProps)(DetailsPanel);
+export interface DetailsPanelDataProps {
+    onCloseDrawer: () => void;
+    isOpened: boolean;
+    item: DetailsData;
+}
 
-export default withStyles(styles)(DetailsPanelContainer);
\ No newline at end of file
+type DetailsPanelProps = DetailsPanelDataProps & WithStyles<CssRules>;
+
+export const DetailsPanel = withStyles(styles)(
+    connect(mapStateToProps, mapDispatchToProps)(
+        class extends React.Component<DetailsPanelProps> {
+            state = {
+                tabsValue: 0
+            };
+
+            handleChange = (event: any, value: boolean) => {
+                this.setState({ tabsValue: value });
+            }
+
+            renderTabContainer = (children: React.ReactElement<any>) =>
+                <Typography className={this.props.classes.tabContainer} component="div">
+                    {children}
+                </Typography>
+
+            render() {
+                const { classes, onCloseDrawer, isOpened, item } = this.props;
+                const { tabsValue } = this.state;
+                return (
+                    <Typography component="div"
+                                className={classnames([classes.container, { [classes.opened]: isOpened }])}>
+                        <Drawer variant="permanent" anchor="right" classes={{ paper: classes.drawerPaper }}>
+                            <Typography component="div" className={classes.headerContainer}>
+                                <Grid container alignItems='center' justify='space-around'>
+                                    <Grid item xs={2}>
+                                        {item.getIcon(classes.headerIcon)}
+                                    </Grid>
+                                    <Grid item xs={8}>
+                                        <Typography variant="title">
+                                            {item.getTitle()}
+                                        </Typography>
+                                    </Grid>
+                                    <Grid item>
+                                        <IconButton color="inherit" onClick={onCloseDrawer}>
+                                            {<CloseIcon/>}
+                                        </IconButton>
+                                    </Grid>
+                                </Grid>
+                            </Typography>
+                            <Tabs value={tabsValue} onChange={this.handleChange}>
+                                <Tab disableRipple label="Details"/>
+                                <Tab disableRipple label="Activity" disabled/>
+                            </Tabs>
+                            {tabsValue === 0 && this.renderTabContainer(
+                                <Grid container direction="column">
+                                    {item.getDetails()}
+                                </Grid>
+                            )}
+                            {tabsValue === 1 && this.renderTabContainer(
+                                <Grid container direction="column"/>
+                            )}
+                        </Drawer>
+                    </Typography>
+                );
+            }
+        }
+    )
+);
