[ARVADOS-WORKBENCH2] created: 1.1.4-339-gb3ed96a

Git user git at public.curoverse.com
Thu Jul 19 10:21:29 EDT 2018


        at  b3ed96a047c8db5febae40b6f186a656589167d8 (commit)


commit b3ed96a047c8db5febae40b6f186a656589167d8
Author: Janicki Artur <artur.janicki at contractors.roche.com>
Date:   Thu Jul 19 16:21:10 2018 +0200

    refactoring project-panel
    
    Feature #13797
    
    Arvados-DCO-1.1-Signed-off-by: Janicki Artur <artur.janicki at contractors.roche.com>

diff --git a/src/common/formatters.ts b/src/common/formatters.ts
index fe7df14..823536f 100644
--- a/src/common/formatters.ts
+++ b/src/common/formatters.ts
@@ -2,15 +2,15 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-export const formatDate = (isoDate: string) => {
+export const FORMAT_DATE = (isoDate: string) => {
     const date = new Date(isoDate);
     const text = date.toLocaleString();
     return text === 'Invalid Date' ? "" : text;
 };
 
-export const formatFileSize = (size?: number) => {
+export const FORMAT_FILE_SIZE = (size?: number) => {
     if (typeof size === "number") {
-        for (const { base, unit } of fileSizes) {
+        for (const { base, unit } of FILE_SIZES) {
             if (size >= base) {
                 return `${(size / base).toFixed()} ${unit}`;
             }
@@ -19,7 +19,7 @@ export const formatFileSize = (size?: number) => {
     return "";
 };
 
-const fileSizes = [
+const FILE_SIZES = [
     {
         base: 1000000000000,
         unit: "TB"
diff --git a/src/common/labels.ts b/src/common/labels.ts
index 9567ce1..ecd7989 100644
--- a/src/common/labels.ts
+++ b/src/common/labels.ts
@@ -4,7 +4,7 @@
 
 import { ResourceKind } from "../models/resource";
 
-export const resourceLabel = (type: string) => {
+export const RESOURCE_LABEL = (type: string) => {
     switch (type) {
         case ResourceKind.Collection:
             return "Data collection";
diff --git a/src/components/details-panel-factory/items/collection-item.tsx b/src/components/details-panel-factory/items/collection-item.tsx
index dab8101..401a15e 100644
--- a/src/components/details-panel-factory/items/collection-item.tsx
+++ b/src/components/details-panel-factory/items/collection-item.tsx
@@ -7,8 +7,8 @@ import { CollectionIcon } from '../../icon/icon';
 import Attribute from '../../attribute/attribute';
 import AbstractItem from './abstract-item';
 import { CollectionResource } from '../../../models/collection';
-import { formatDate } from '../../../common/formatters';
-import { resourceLabel } from '../../../common/labels';
+import { FORMAT_DATE } from '../../../common/formatters';
+import { RESOURCE_LABEL } from '../../../common/labels';
 import { ResourceKind } from '../../../models/resource';
 
 export default class CollectionItem extends AbstractItem<CollectionResource> {
@@ -19,11 +19,11 @@ export default class CollectionItem extends AbstractItem<CollectionResource> {
 
     buildDetails() {
         return <div>
-            <Attribute label='Type' value={resourceLabel(ResourceKind.Collection)} />
+            <Attribute label='Type' value={RESOURCE_LABEL(ResourceKind.Collection)} />
             <Attribute label='Size' value='---' />
             <Attribute label='Owner' value={this.item.ownerUuid} />
-            <Attribute label='Last modified' value={formatDate(this.item.modifiedAt)} />
-            <Attribute label='Created at' value={formatDate(this.item.createdAt)} />
+            <Attribute label='Last modified' value={FORMAT_DATE(this.item.modifiedAt)} />
+            <Attribute label='Created at' value={FORMAT_DATE(this.item.createdAt)} />
             {/* Links but we dont have view */}
             <Attribute label='Collection UUID' link={this.item.uuid} value={this.item.uuid} />
             <Attribute label='Content address' link={this.item.portableDataHash} value={this.item.portableDataHash} />
diff --git a/src/components/details-panel-factory/items/process-item.tsx b/src/components/details-panel-factory/items/process-item.tsx
index 215c531..c2a7fe2 100644
--- a/src/components/details-panel-factory/items/process-item.tsx
+++ b/src/components/details-panel-factory/items/process-item.tsx
@@ -7,9 +7,9 @@ import { ProcessIcon } from '../../icon/icon';
 import Attribute from '../../attribute/attribute';
 import AbstractItem from './abstract-item';
 import { ProcessResource } from '../../../models/process';
-import { formatDate } from '../../../common/formatters';
+import { FORMAT_DATE } from '../../../common/formatters';
 import { ResourceKind } from '../../../models/resource';
-import { resourceLabel } from '../../../common/labels';
+import { RESOURCE_LABEL } from '../../../common/labels';
 
 export default class ProcessItem extends AbstractItem<ProcessResource> {
 
@@ -19,17 +19,17 @@ export default class ProcessItem extends AbstractItem<ProcessResource> {
 
     buildDetails() {
         return <div>
-            <Attribute label='Type' value={resourceLabel(ResourceKind.Process)} />
+            <Attribute label='Type' value={RESOURCE_LABEL(ResourceKind.Process)} />
             <Attribute label='Size' value='---' />
             <Attribute label='Owner' value={this.item.ownerUuid} />
 
             {/* Missing attr */}
             <Attribute label='Status' value={this.item.state} />
-            <Attribute label='Last modified' value={formatDate(this.item.modifiedAt)} />
+            <Attribute label='Last modified' value={FORMAT_DATE(this.item.modifiedAt)} />
             
             {/* Missing attrs */}
-            <Attribute label='Started at' value={formatDate(this.item.createdAt)} />
-            <Attribute label='Finished at' value={formatDate(this.item.expiresAt)} />
+            <Attribute label='Started at' value={FORMAT_DATE(this.item.createdAt)} />
+            <Attribute label='Finished at' value={FORMAT_DATE(this.item.expiresAt)} />
 
             {/* Links but we dont have view */}
             <Attribute label='Outputs' link={this.item.outputPath} value={this.item.outputPath} />
diff --git a/src/components/details-panel-factory/items/project-item.tsx b/src/components/details-panel-factory/items/project-item.tsx
index ae694e5..73ceafe 100644
--- a/src/components/details-panel-factory/items/project-item.tsx
+++ b/src/components/details-panel-factory/items/project-item.tsx
@@ -7,9 +7,9 @@ import { ProjectIcon } from '../../icon/icon';
 import Attribute from '../../attribute/attribute';
 import AbstractItem from './abstract-item';
 import { ProjectResource } from '../../../models/project';
-import { formatDate } from '../../../common/formatters';
+import { FORMAT_DATE } from '../../../common/formatters';
 import { ResourceKind } from '../../../models/resource';
-import { resourceLabel } from '../../../common/labels';
+import { RESOURCE_LABEL } from '../../../common/labels';
 
 export default class ProjectItem extends AbstractItem<ProjectResource> {
 
@@ -19,12 +19,12 @@ export default class ProjectItem extends AbstractItem<ProjectResource> {
 
     buildDetails() {
         return <div>
-            <Attribute label='Type' value={resourceLabel(ResourceKind.Project)} />
+            <Attribute label='Type' value={RESOURCE_LABEL(ResourceKind.Project)} />
             {/* Missing attr */}
             <Attribute label='Size' value='---' />
             <Attribute label='Owner' value={this.item.ownerUuid} />
-            <Attribute label='Last modified' value={formatDate(this.item.modifiedAt)} />
-            <Attribute label='Created at' value={formatDate(this.item.createdAt)} />
+            <Attribute label='Last modified' value={FORMAT_DATE(this.item.modifiedAt)} />
+            <Attribute label='Created at' value={FORMAT_DATE(this.item.createdAt)} />
             {/* Missing attr */}
             <Attribute label='File size' value='1.4 GB' />
             <Attribute label='Description' value={this.item.description} />
diff --git a/src/store/project-panel/project-panel-middleware.ts b/src/store/project-panel/project-panel-middleware.ts
index 80fb7fa..3ac3cc8 100644
--- a/src/store/project-panel/project-panel-middleware.ts
+++ b/src/store/project-panel/project-panel-middleware.ts
@@ -4,21 +4,20 @@
 
 import { Middleware } from "redux";
 import actions from "../data-explorer/data-explorer-action";
-import { PROJECT_PANEL_ID, columns, ProjectPanelFilter, ProjectPanelColumnNames } from "../../views/project-panel/project-panel";
+import { PROJECT_PANEL_ID, ProjectPanelFilter, COLUMNS, ColumnNames } from "../../views/project-panel/project-panel";
 import { groupsService } from "../../services/services";
 import { RootState } from "../store";
-import { getDataExplorer, DataExplorerState } from "../data-explorer/data-explorer-reducer";
+import { getDataExplorer } from "../data-explorer/data-explorer-reducer";
 import { resourceToDataItem, ProjectPanelItem } from "../../views/project-panel/project-panel-item";
 import FilterBuilder from "../../common/api/filter-builder";
 import { DataColumns } from "../../components/data-table/data-table";
 import { ProcessResource } from "../../models/process";
-import { CollectionResource } from "../../models/collection";
 import OrderBuilder from "../../common/api/order-builder";
 import { GroupContentsResource, GroupContentsResourcePrefix } from "../../services/groups-service/groups-service";
 import { SortDirection } from "../../components/data-table/data-column";
 
 export const projectPanelMiddleware: Middleware = store => next => {
-    next(actions.SET_COLUMNS({ id: PROJECT_PANEL_ID, columns }));
+    next(actions.SET_COLUMNS({ id: PROJECT_PANEL_ID, columns: COLUMNS }));
 
     return action => {
 
@@ -52,8 +51,8 @@ export const projectPanelMiddleware: Middleware = store => next => {
                 const state = store.getState() as RootState;
                 const dataExplorer = getDataExplorer(state.dataExplorer, PROJECT_PANEL_ID);
                 const columns = dataExplorer.columns as DataColumns<ProjectPanelItem, ProjectPanelFilter>;
-                const typeFilters = getColumnFilters(columns, ProjectPanelColumnNames.Type);
-                const statusFilters = getColumnFilters(columns, ProjectPanelColumnNames.Status);
+                const typeFilters = getColumnFilters(columns, ColumnNames.TYPE);
+                const statusFilters = getColumnFilters(columns, ColumnNames.STATUS);
                 const sortColumn = dataExplorer.columns.find(({ sortDirection }) => Boolean(sortDirection && sortDirection !== "none"));
                 const sortDirection = sortColumn && sortColumn.sortDirection === SortDirection.Asc ? SortDirection.Asc : SortDirection.Desc;
                 if (typeFilters.length > 0) {
@@ -62,7 +61,7 @@ export const projectPanelMiddleware: Middleware = store => next => {
                             limit: dataExplorer.rowsPerPage,
                             offset: dataExplorer.page * dataExplorer.rowsPerPage,
                             order: sortColumn
-                                ? sortColumn.name === ProjectPanelColumnNames.Name
+                                ? sortColumn.name === ColumnNames.NAME
                                     ? getOrder("name", sortDirection)
                                     : getOrder("createdAt", sortDirection)
                                 : OrderBuilder.create(),
diff --git a/src/views/project-panel/project-panel.tsx b/src/views/project-panel/project-panel.tsx
index 2fdb715..fbafdbe 100644
--- a/src/views/project-panel/project-panel.tsx
+++ b/src/views/project-panel/project-panel.tsx
@@ -5,7 +5,7 @@
 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';
@@ -15,7 +15,9 @@ import { DataTableFilterItem } from '../../components/data-table-filters/data-ta
 import { ContainerRequestState } from '../../models/container-request';
 import { SortDirection } from '../../components/data-table/data-column';
 import { ResourceKind } from '../../models/resource';
-import { resourceLabel } from '../../common/labels';
+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";
 
@@ -23,21 +25,24 @@ export interface ProjectPanelFilter extends DataTableFilterItem {
     type: ResourceKind | ContainerRequestState;
 }
 
-type ProjectPanelProps = {
-    currentItemId: string,
-    onItemClick: (item: ProjectPanelItem) => void,
+interface ProjectPanelDataProps {
+    currentItemId: string;
+}
+
+interface ProjectPanelActionProps {
+    onItemClick: (item: ProjectPanelItem) => void;
     onContextMenu: (event: React.MouseEvent<HTMLElement>, item: ProjectPanelItem) => void;
     onDialogOpen: (ownerUuid: string) => void;
-    onItemDoubleClick: (item: ProjectPanelItem) => void,
-    onItemRouteChange: (itemId: string) => void
+    onItemDoubleClick: (item: ProjectPanelItem) => void;
+    onItemRouteChange: (itemId: string) => void;
 }
-    & DispatchProp
-    & WithStyles<CssRules>
-    & RouteComponentProps<{ id: string }>;
+
+type ProjectPanelProps = ProjectPanelDataProps & ProjectPanelActionProps & DispatchProp
+                        & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
 
 class ProjectPanel extends React.Component<ProjectPanelProps> {
     render() {
-        const { classes, currentItemId, onItemClick, onItemDoubleClick, onContextMenu, onDialogOpen } = this.props;
+        const { classes } = this.props;
         return <div>
             <div className={classes.toolbar}>
                 <Button color="primary" variant="raised" className={classes.button}>
@@ -71,7 +76,7 @@ class ProjectPanel extends React.Component<ProjectPanelProps> {
 
 type CssRules = "toolbar" | "button";
 
-const styles: StyleRulesCallback<CssRules> = theme => ({
+const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
     toolbar: {
         paddingBottom: theme.spacing.unit * 3,
         textAlign: "right"
@@ -81,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">
@@ -98,116 +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 renderType = (type: string) => {
-    return <Typography noWrap>
-        {resourceLabel(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: resourceLabel(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: resourceLabel(ResourceKind.Process),
+        render: item => RENDER_OWNER(item.owner),
+        width: "200px"
+    },
+    {
+        name: ColumnNames.FILE_SIZE,
         selected: true,
-        type: ResourceKind.Process
-    }, {
-        name: resourceLabel(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));

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list