[ARVADOS-WORKBENCH2] created: 1.1.4-268-g8365bee

Git user git at public.curoverse.com
Wed Jul 11 06:36:28 EDT 2018


        at  8365beee952d63f7ae1d6e94063f36ddc8a98be0 (commit)


commit 8365beee952d63f7ae1d6e94063f36ddc8a98be0
Author: Janicki Artur <artur.janicki at contractors.roche.com>
Date:   Wed Jul 11 12:36:13 2018 +0200

    add factory patter for render item details
    
    Feature #13705
    
    Arvados-DCO-1.1-Signed-off-by: Janicki Artur <artur.janicki at contractors.roche.com>

diff --git a/src/components/details-panel-factory/details-panel-factory.tsx b/src/components/details-panel-factory/details-panel-factory.tsx
new file mode 100644
index 0000000..aa9d777
--- /dev/null
+++ b/src/components/details-panel-factory/details-panel-factory.tsx
@@ -0,0 +1,29 @@
+
+
+import * as React from 'react';
+import { ProjectResource } from "../../models/project";
+import { CollectionResource } from "../../models/collection";
+import { ProcessResource } from "../../models/process";
+import { ResourceKind } from '../../models/kinds';
+import ProjectItem from './items/project-item';
+import CollectionItem from './items/collection-item';
+import ProcessItem from './items/process-item';
+import { AbstractItem } from './items/abstract-item';
+
+// TODO: move to models
+export type DetailsPanelResource = ProjectResource | CollectionResource | ProcessResource;
+
+export default class DetailsPanelFactory {
+    static createItem(res: DetailsPanelResource): AbstractItem {
+        switch (res.kind) {
+            case ResourceKind.Project:
+                return new ProjectItem(res);
+            case ResourceKind.Collection:
+                return new CollectionItem(res);
+            case ResourceKind.Collection:
+                return new ProcessItem(res);
+            default:
+                return new ProjectItem(res);
+        }
+    }
+}
\ No newline at end of file
diff --git a/src/components/details-panel-factory/items/abstract-item.tsx b/src/components/details-panel-factory/items/abstract-item.tsx
new file mode 100644
index 0000000..5e7d159
--- /dev/null
+++ b/src/components/details-panel-factory/items/abstract-item.tsx
@@ -0,0 +1,26 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import * as React from 'react';
+import { DetailsPanelResource } from "./../details-panel-factory";
+import { IconTypes } from '../../icon/icon';
+
+export abstract class AbstractItem {
+    protected item: DetailsPanelResource;
+
+    constructor(item: DetailsPanelResource) {
+        this.item = item;
+    }
+
+    getTitle(): string {
+        return this.item.name;
+    }
+
+    abstract getIcon(): IconTypes;
+    abstract buildDetails(): React.ReactElement<any>;
+    
+    buildActivity(): React.ReactElement<any> {
+        return <div/>;
+    }
+}
\ No newline at end of file
diff --git a/src/components/details-panel-factory/items/collection-item.tsx b/src/components/details-panel-factory/items/collection-item.tsx
new file mode 100644
index 0000000..d9504e4
--- /dev/null
+++ b/src/components/details-panel-factory/items/collection-item.tsx
@@ -0,0 +1,40 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import * as React from 'react';
+import { DetailsPanelResource } from "./../details-panel-factory";
+import IconBase, { IconTypes } from '../../icon/icon';
+import Attribute from '../../attribute/attribute';
+import { AbstractItem } from './abstract-item';
+
+export default class CollectionItem extends AbstractItem {
+    
+    constructor(item: DetailsPanelResource) {
+        super(item);
+    }
+
+    getIcon(): IconTypes {
+        return IconTypes.COLLECTION;
+    }
+
+    buildDetails(): React.ReactElement<any> {
+        return <div>
+           <Attribute label='Type' value='Data Collection' />
+            <Attribute label='Size' value='---' />
+            <Attribute label="Location">
+                <IconBase icon={IconTypes.FOLDER} />
+                Collection
+            </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>;
+    }
+}
\ No newline at end of file
diff --git a/src/components/details-panel-factory/items/process-item.tsx b/src/components/details-panel-factory/items/process-item.tsx
new file mode 100644
index 0000000..ebbebb9
--- /dev/null
+++ b/src/components/details-panel-factory/items/process-item.tsx
@@ -0,0 +1,40 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import * as React from 'react';
+import { DetailsPanelResource } from "./../details-panel-factory";
+import IconBase, { IconTypes } from '../../icon/icon';
+import Attribute from '../../attribute/attribute';
+import { AbstractItem } from './abstract-item';
+
+export default class ProcessItem extends AbstractItem {
+    
+    constructor(item: DetailsPanelResource) {
+        super(item);
+    }
+
+    getIcon(): IconTypes {
+        return IconTypes.PROCESS;
+    }
+
+    buildDetails(): React.ReactElement<any> {
+        return <div>
+            <Attribute label='Type' value='Data Collection' />
+            <Attribute label='Size' value='---' />
+            <Attribute label="Location">
+                <IconBase icon={IconTypes.FOLDER} />
+                Process
+            </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>;
+    }
+}
\ No newline at end of file
diff --git a/src/components/details-panel-factory/items/project-item.tsx b/src/components/details-panel-factory/items/project-item.tsx
new file mode 100644
index 0000000..9b96f84
--- /dev/null
+++ b/src/components/details-panel-factory/items/project-item.tsx
@@ -0,0 +1,35 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import * as React from 'react';
+import { DetailsPanelResource } from "./../details-panel-factory";
+import IconBase, { IconTypes } from '../../icon/icon';
+import Attribute from '../../attribute/attribute';
+import { AbstractItem } from './abstract-item';
+
+export default class ProjectItem extends AbstractItem {
+
+    constructor(item: DetailsPanelResource) {
+        super(item);
+    }
+
+    getIcon(): IconTypes {
+        return IconTypes.PROJECT;
+    }
+
+    buildDetails(): React.ReactElement<any> {
+        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>;
+    }
+}
\ No newline at end of file
diff --git a/src/views-components/details-panel/details-panel.tsx b/src/views-components/details-panel/details-panel.tsx
index 138c91a..60994b0 100644
--- a/src/views-components/details-panel/details-panel.tsx
+++ b/src/views-components/details-panel/details-panel.tsx
@@ -23,6 +23,7 @@ import { ProjectResource } from '../../models/project';
 import { CollectionResource } from '../../models/collection';
 import IconBase, { IconTypes } from '../../components/icon/icon';
 import { ProcessResource } from '../../models/process';
+import DetailsPanelFactory from '../../components/details-panel-factory/details-panel-factory';
 
 export interface DetailsPanelDataProps {
     onCloseDrawer: () => void;
@@ -67,7 +68,7 @@ class DetailsPanel extends React.Component<DetailsPanelProps, {}> {
                     </Typography>
                     <Tabs value={tabsValue} onChange={this.handleChange}>
                         <Tab disableRipple label="Details" />
-                        <Tab disableRipple label="Activity" />
+                        <Tab disableRipple label="Activity" disabled />
                     </Tabs>
                     {tabsValue === 0 && this.renderTabContainer(
                         <Grid container direction="column">
@@ -114,90 +115,37 @@ const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
     }
 });
 
+// TODO: move to models
 type DetailsPanelResource = ProjectResource | CollectionResource | ProcessResource;
 
-const getIcon = (res: DetailsPanelResource) => {
-    switch (res.kind) {
-        case ResourceKind.Project:
-            return IconTypes.FOLDER;
-        case ResourceKind.Collection:
-            return IconTypes.COLLECTION;
-        case ResourceKind.Process:
-            return IconTypes.PROCESS;
-        default:
-            return IconTypes.FOLDER;
-    }
+const getEmptyState = () => {
+    return <EmptyState icon={ IconTypes.ANNOUNCEMENT } 
+        message='Select a file or folder to view its details.' />;
 };
 
-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 getItem = (res: DetailsPanelResource) => {
+    const item = DetailsPanelFactory.createItem(res);
+    return {
+        title: item.getTitle(),
+        icon: item.getIcon(),
+        details: item.buildDetails() 
+    };    
 };
 
-const getEmptyState = () => {
-    return <EmptyState icon={ IconTypes.ANNOUNCEMENT } 
-        message='Select a file or folder to view its details.' />;
+const getDefaultItem = () => {
+    return {
+        title: 'Projects',
+        icon: IconTypes.FOLDER,
+        details: getEmptyState()
+    };
 };
 
 const mapStateToProps = ({ detailsPanel }: RootState) => {
     const { isOpened, item } = detailsPanel;
+    const newItem = item ? getItem(item as DetailsPanelResource) : getDefaultItem();
     return {
         isOpened,
-        title: item ? (item as DetailsPanelResource).name : 'Projects',
-        icon: item ? getIcon(item as DetailsPanelResource) : IconTypes.FOLDER,
-        details: item ? getDetails(item as DetailsPanelResource) : getEmptyState()
+        ...newItem
     };
 };
 

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


hooks/post-receive
-- 




More information about the arvados-commits mailing list