X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/3429b49bb9ff70db11f3239c7fbbc03ac7c2e460..b3ed96a047c8db5febae40b6f186a656589167d8:/src/views/project-panel/project-panel.tsx?ds=sidebyside

diff --git a/src/views/project-panel/project-panel.tsx b/src/views/project-panel/project-panel.tsx
index b7c8b954..fbafdbe0 100644
--- a/src/views/project-panel/project-panel.tsx
+++ b/src/views/project-panel/project-panel.tsx
@@ -5,16 +5,19 @@
 import * as React from 'react';
 import { ProjectPanelItem } from './project-panel-item';
 import { Grid, Typography, Button, StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core';
-import { formatDate, formatFileSize } from '../../common/formatters';
+import { FORMAT_DATE, FORMAT_FILE_SIZE } from '../../common/formatters';
 import DataExplorer from "../../views-components/data-explorer/data-explorer";
 import { DispatchProp, connect } from 'react-redux';
 import { DataColumns } from '../../components/data-table/data-table';
 import { RouteComponentProps } from 'react-router';
 import { RootState } from '../../store/store';
-import { ResourceKind } from '../../models/kinds';
 import { DataTableFilterItem } from '../../components/data-table-filters/data-table-filters';
 import { ContainerRequestState } from '../../models/container-request';
 import { SortDirection } from '../../components/data-table/data-column';
+import { ResourceKind } from '../../models/resource';
+import { RESOURCE_LABEL } from '../../common/labels';
+import { ProjectIcon, CollectionIcon, ProcessIcon, DefaultIcon } from '../../components/icon/icon';
+import { ArvadosTheme } from '../../common/custom-theme';
 
 export const PROJECT_PANEL_ID = "projectPanel";
 
@@ -22,48 +25,58 @@ export interface ProjectPanelFilter extends DataTableFilterItem {
     type: ResourceKind | ContainerRequestState;
 }
 
-type ProjectPanelProps = {
-    currentItemId: string,
-    onItemClick: (item: ProjectPanelItem) => void,
-    onItemRouteChange: (itemId: string) => void,
+interface ProjectPanelDataProps {
+    currentItemId: string;
+}
+
+interface ProjectPanelActionProps {
+    onItemClick: (item: ProjectPanelItem) => void;
     onContextMenu: (event: React.MouseEvent<HTMLElement>, item: ProjectPanelItem) => void;
-    onDialogOpen: () => void;
+    onDialogOpen: (ownerUuid: string) => void;
+    onItemDoubleClick: (item: ProjectPanelItem) => void;
+    onItemRouteChange: (itemId: string) => void;
 }
-    & DispatchProp
-    & WithStyles<CssRules>
-    & RouteComponentProps<{ id: string }>;
 
-class ProjectPanel extends React.Component<ProjectPanelProps> {    
+type ProjectPanelProps = ProjectPanelDataProps & ProjectPanelActionProps & DispatchProp
+                        & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
+
+class ProjectPanel extends React.Component<ProjectPanelProps> {
     render() {
+        const { classes } = this.props;
         return <div>
-            <div className={this.props.classes.toolbar}>
-                <Button color="primary" variant="raised" className={this.props.classes.button}>
+            <div className={classes.toolbar}>
+                <Button color="primary" variant="raised" className={classes.button}>
                     Create a collection
                 </Button>
-                <Button color="primary" variant="raised" className={this.props.classes.button}>
+                <Button color="primary" variant="raised" className={classes.button}>
                     Run a process
                 </Button>
-                <Button color="primary" onClick={this.props.onDialogOpen} variant="raised" className={this.props.classes.button}>
+                <Button color="primary" onClick={this.handleNewProjectClick} variant="raised" className={classes.button}>
                     New project
                 </Button>
             </div>
             <DataExplorer
                 id={PROJECT_PANEL_ID}
                 onRowClick={this.props.onItemClick}
-                onContextMenu={this.props.onContextMenu} />;
+                onRowDoubleClick={this.props.onItemDoubleClick}
+                onContextMenu={this.props.onContextMenu}
+                extractKey={(item: ProjectPanelItem) => item.uuid} />
         </div>;
     }
-
-    componentWillReceiveProps({ match, currentItemId }: ProjectPanelProps) {
+    
+    handleNewProjectClick = () => {
+        this.props.onDialogOpen(this.props.currentItemId);
+    }
+    componentWillReceiveProps({ match, currentItemId, onItemRouteChange }: ProjectPanelProps) {
         if (match.params.id !== currentItemId) {
-            this.props.onItemRouteChange(match.params.id);
+            onItemRouteChange(match.params.id);
         }
     }
 }
 
 type CssRules = "toolbar" | "button";
 
-const styles: StyleRulesCallback<CssRules> = theme => ({
+const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
     toolbar: {
         paddingBottom: theme.spacing.unit * 3,
         textAlign: "right"
@@ -73,14 +86,10 @@ const styles: StyleRulesCallback<CssRules> = theme => ({
     },
 });
 
-const renderName = (item: ProjectPanelItem) =>
-    <Grid
-        container
-        alignItems="center"
-        wrap="nowrap"
-        spacing={16}>
+const RENDER_NAME = (item: ProjectPanelItem) =>
+    <Grid container alignItems="center" wrap="nowrap" spacing={16}>
         <Grid item>
-            {renderIcon(item)}
+            {RENDER_ICON(item)}
         </Grid>
         <Grid item>
             <Typography color="primary">
@@ -90,131 +99,127 @@ const renderName = (item: ProjectPanelItem) =>
     </Grid>;
 
 
-const renderIcon = (item: ProjectPanelItem) => {
+const RENDER_ICON = (item: ProjectPanelItem) => {
     switch (item.kind) {
         case ResourceKind.Project:
-            return <i className="fas fa-folder fa-lg" />;
+            return <ProjectIcon />;
         case ResourceKind.Collection:
-            return <i className="fas fa-archive fa-lg" />;
+            return <CollectionIcon />;
         case ResourceKind.Process:
-            return <i className="fas fa-cogs fa-lg" />;
+            return <ProcessIcon />;
         default:
-            return <i />;
+            return <DefaultIcon />;
     }
 };
 
-const renderDate = (date: string) =>
-    <Typography noWrap>
-        {formatDate(date)}
-    </Typography>;
+const RENDER_DATE = (date: string) => {
+    return <Typography noWrap>{FORMAT_DATE(date)}</Typography>;
+};
 
-const renderFileSize = (fileSize?: number) =>
+const RENDER_FILE_SIZE = (fileSize?: number) =>
     <Typography noWrap>
-        {formatFileSize(fileSize)}
+        {FORMAT_FILE_SIZE(fileSize)}
     </Typography>;
 
-const renderOwner = (owner: string) =>
-    <Typography noWrap color="primary">
+const RENDER_OWNER = (owner: string) =>
+    <Typography noWrap color="primary" >
         {owner}
     </Typography>;
 
-
-
-const typeToLabel = (type: string) => {
-    switch (type) {
-        case ResourceKind.Collection:
-            return "Data collection";
-        case ResourceKind.Project:
-            return "Project";
-        case ResourceKind.Process:
-            return "Process";
-        default:
-            return "Unknown";
-    }
-};
-
-const renderType = (type: string) => {
-    return <Typography noWrap>
-        {typeToLabel(type)}
+const RENDER_TYPE = (type: string) =>
+    <Typography noWrap>
+        {RESOURCE_LABEL(type)}
     </Typography>;
-};
 
-const renderStatus = (item: ProjectPanelItem) =>
-    <Typography noWrap align="center">
+const RENDER_STATUS = (item: ProjectPanelItem) =>
+    <Typography noWrap align="center" >
         {item.status || "-"}
     </Typography>;
 
-export enum ProjectPanelColumnNames {
-    Name = "Name",
-    Status = "Status",
-    Type = "Type",
-    Owner = "Owner",
-    FileSize = "File size",
-    LastModified = "Last modified"
+export enum ColumnNames {
+    NAME = "Name",
+    STATUS = "Status",
+    TYPE = "Type",
+    OWNER = "Owner",
+    FILE_SIZE = "File size",
+    LAST_MODIFIED = "Last modified"
 
 }
 
-export const columns: DataColumns<ProjectPanelItem, ProjectPanelFilter> = [{
-    name: ProjectPanelColumnNames.Name,
-    selected: true,
-    sortDirection: SortDirection.Asc,
-    render: renderName,
-    width: "450px"
-}, {
-    name: "Status",
-    selected: true,
-    filters: [{
-        name: ContainerRequestState.Committed,
+export const COLUMNS: DataColumns<ProjectPanelItem, ProjectPanelFilter> = [
+    {
+        name: ColumnNames.NAME,
         selected: true,
-        type: ContainerRequestState.Committed
-    }, {
-        name: ContainerRequestState.Final,
+        sortDirection: SortDirection.Asc,
+        render: RENDER_NAME,
+        width: "450px"
+    },
+    {
+        name: "Status",
         selected: true,
-        type: ContainerRequestState.Final
-    }, {
-        name: ContainerRequestState.Uncommitted,
+        filters: [
+            {
+                name: ContainerRequestState.Committed,
+                selected: true,
+                type: ContainerRequestState.Committed
+            },
+            {
+                name: ContainerRequestState.Final,
+                selected: true,
+                type: ContainerRequestState.Final
+            },
+            {
+                name: ContainerRequestState.Uncommitted,
+                selected: true,
+                type: ContainerRequestState.Uncommitted
+            }
+        ],
+        render: RENDER_STATUS,
+        width: "75px"
+    },
+    {
+        name: ColumnNames.TYPE,
         selected: true,
-        type: ContainerRequestState.Uncommitted
-    }],
-    render: renderStatus,
-    width: "75px"
-}, {
-    name: ProjectPanelColumnNames.Type,
-    selected: true,
-    filters: [{
-        name: typeToLabel(ResourceKind.Collection),
+        filters: [
+            {
+                name: RESOURCE_LABEL(ResourceKind.Collection),
+                selected: true,
+                type: ResourceKind.Collection
+            },
+            {
+                name: RESOURCE_LABEL(ResourceKind.Process),
+                selected: true,
+                type: ResourceKind.Process
+            },
+            {
+                name: RESOURCE_LABEL(ResourceKind.Project),
+                selected: true,
+                type: ResourceKind.Project
+            }
+        ],
+        render: item => RENDER_TYPE(item.kind),
+        width: "125px"
+    },
+    {
+        name: ColumnNames.OWNER,
         selected: true,
-        type: ResourceKind.Collection
-    }, {
-        name: typeToLabel(ResourceKind.Process),
+        render: item => RENDER_OWNER(item.owner),
+        width: "200px"
+    },
+    {
+        name: ColumnNames.FILE_SIZE,
         selected: true,
-        type: ResourceKind.Process
-    }, {
-        name: typeToLabel(ResourceKind.Project),
+        render: item => RENDER_FILE_SIZE(item.fileSize),
+        width: "50px"
+    },
+    {
+        name: ColumnNames.LAST_MODIFIED,
         selected: true,
-        type: ResourceKind.Project
-    }],
-    render: item => renderType(item.kind),
-    width: "125px"
-}, {
-    name: ProjectPanelColumnNames.Owner,
-    selected: true,
-    render: item => renderOwner(item.owner),
-    width: "200px"
-}, {
-    name: ProjectPanelColumnNames.FileSize,
-    selected: true,
-    render: item => renderFileSize(item.fileSize),
-    width: "50px"
-}, {
-    name: ProjectPanelColumnNames.LastModified,
-    selected: true,
-    sortDirection: SortDirection.None,
-    render: item => renderDate(item.lastModified),
-    width: "150px"
-}];
-
+        sortDirection: SortDirection.None,
+        render: item => RENDER_DATE(item.lastModified),
+        width: "150px"
+    }
+];
 
 export default withStyles(styles)(
-    connect((state: RootState) => ({ currentItemId: state.projects.currentItemId }))(
-        ProjectPanel));
+    connect((state: RootState) => ({ currentItemId: state.projects.currentItemId }))(ProjectPanel));
