X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/284058e97bb25593f057902eb46af1c8c51b1e27..180c2c37b635cbb7a33257d2ee9b4395553ce5e7:/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 15ca8f3643..b61a1e41ac 100644
--- a/src/views-components/details-panel/details-panel.tsx
+++ b/src/views-components/details-panel/details-panel.tsx
@@ -3,90 +3,21 @@
 // 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 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 * as classnames from "classnames";
-import { connect, Dispatch } from 'react-redux';
+import { connect } from 'react-redux';
 import { RootState } from '../../store/store';
-import actions from "../../store/details-panel/details-panel-action";
+import { detailsPanelActions } from "../../store/details-panel/details-panel-action";
 import { ProjectResource } from '../../models/project';
 import { CollectionResource } from '../../models/collection';
-import IconBase, { IconTypes } from '../../components/icon/icon';
+import { CloseIcon } from '../../components/icon/icon';
 import { ProcessResource } from '../../models/process';
-import DetailsPanelFactory from '../../components/details-panel-factory/details-panel-factory';
-import AbstractItem from '../../components/details-panel-factory/items/abstract-item';
-import { ResourceKind } from '../../models/resource';
+import { DetailsPanelFactory } from '../../components/details-panel-factory/details-panel-factory';
+import { AbstractItem } from '../../components/details-panel-factory/items/abstract-item';
 import { EmptyResource } from '../../models/empty';
-
-export interface DetailsPanelDataProps {
-    onCloseDrawer: () => void;
-    isOpened: boolean;
-    item: AbstractItem;
-}
-
-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, 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 wrap="nowrap" alignItems='center' justify='space-around'>
-                            <Grid item>
-                                <IconBase className={classes.headerIcon} icon={item.getIcon()} />
-                            </Grid>
-                            <Grid item xs={8}>
-                                <Typography variant="title">
-                                    {item.getTitle()}
-                                </Typography>
-                            </Grid>
-                            <Grid item>
-                                <IconButton color="inherit" onClick={onCloseDrawer}>
-                                    <IconBase icon={IconTypes.CLOSE} />
-                                </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.buildDetails()}
-                        </Grid>
-                    )}
-                    {tabsValue === 1 && this.renderTabContainer(
-                        <Grid container direction="column" />
-                    )}
-                </Drawer>
-            </Typography>
-        );
-    }
-
-}
+import { Dispatch } from "redux";
 
 type CssRules = 'drawerPaper' | 'container' | 'opened' | 'headerContainer' | 'headerIcon' | 'tabContainer';
 
@@ -119,7 +50,7 @@ const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
     }
 });
 
-// TODO: move to models
+
 export type DetailsPanelResource = ProjectResource | CollectionResource | ProcessResource | EmptyResource;
 
 const getItem = (res: DetailsPanelResource) => {
@@ -127,7 +58,7 @@ const getItem = (res: DetailsPanelResource) => {
 };
 
 const getDefaultItem = () => {
-    return DetailsPanelFactory.createItem({ kind: ResourceKind.UNKNOWN, name: 'Projects'});
+    return DetailsPanelFactory.createItem({ kind: undefined, name: 'Projects' });
 };
 
 const mapStateToProps = ({ detailsPanel }: RootState) => {
@@ -140,10 +71,74 @@ const mapStateToProps = ({ detailsPanel }: RootState) => {
 
 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: AbstractItem;
+}
+
+type DetailsPanelProps = DetailsPanelDataProps & WithStyles<CssRules>;
 
-export default withStyles(styles)(DetailsPanelContainer);
\ No newline at end of file
+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.buildDetails()}
+                                </Grid>
+                            )}
+                            {tabsValue === 1 && this.renderTabContainer(
+                                <Grid container direction="column"/>
+                            )}
+                        </Drawer>
+                    </Typography>
+                );
+            }
+        }
+    )
+);
