merge-conflicts
authorPawel Kowalczyk <pawel.kowalczyk@contractors.roche.com>
Mon, 25 Jun 2018 10:05:09 +0000 (12:05 +0200)
committerPawel Kowalczyk <pawel.kowalczyk@contractors.roche.com>
Mon, 25 Jun 2018 10:05:09 +0000 (12:05 +0200)
Feature ##13598

Arvados-DCO-1.1-Signed-off-by: Pawel Kowalczyk <pawel.kowalczyk@contractors.roche.com>

14 files changed:
src/components/side-panel/side-panel.tsx [new file with mode: 0644]
src/components/tree/tree.tsx
src/index.tsx
src/store/project/project-action.ts
src/store/project/project-reducer.test.ts
src/store/project/project-reducer.ts
src/store/side-panel/side-panel-action.ts [new file with mode: 0644]
src/store/side-panel/side-panel-reducer.test.ts [new file with mode: 0644]
src/store/side-panel/side-panel-reducer.ts [new file with mode: 0644]
src/store/store.ts
src/views-components/project-tree/project-tree.test.tsx
src/views-components/project-tree/project-tree.tsx
src/views/workbench/workbench.test.tsx
src/views/workbench/workbench.tsx

diff --git a/src/components/side-panel/side-panel.tsx b/src/components/side-panel/side-panel.tsx
new file mode 100644 (file)
index 0000000..36e4c74
--- /dev/null
@@ -0,0 +1,111 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import * as React from 'react';
+import { ReactElement } from 'react';
+import { StyleRulesCallback, Theme, WithStyles, withStyles } from '@material-ui/core/styles';
+import List from "@material-ui/core/List/List";
+import ListItem from "@material-ui/core/ListItem/ListItem";
+import ListItemText from "@material-ui/core/ListItemText/ListItemText";
+import ListItemIcon from '@material-ui/core/ListItemIcon';
+import Collapse from "@material-ui/core/Collapse/Collapse";
+
+import { Typography } from '@material-ui/core';
+
+export interface SidePanelItem {
+    id: string;
+    name: string;
+    icon: string;
+    active?: boolean;
+    open?: boolean;
+}
+
+interface SidePanelProps {
+    toggleOpen: (id: string) => void;
+    toggleActive: (id: string) => void;
+    sidePanelItems: SidePanelItem[];
+}
+
+class SidePanel extends React.Component<SidePanelProps & WithStyles<CssRules>> {
+    render(): ReactElement<any> {
+        const { classes, toggleOpen, toggleActive, sidePanelItems } = this.props;
+        const { listItemText, leftSidePanelContainer, row, list, icon, projectIcon, active, activeArrow, inactiveArrow, arrowTransition, arrowRotate } = classes;
+        return (
+            <div className={leftSidePanelContainer}>
+                <List>
+                    {sidePanelItems.map(it => (
+                        <span key={it.name}>
+                            <ListItem button className={list} onClick={() => toggleActive(it.id)}>
+                                <span className={row}>
+                                    {it.name === "Projects" ? <i onClick={() => toggleOpen(it.id)} className={`${it.active ? activeArrow : inactiveArrow} 
+                                        ${it.open ? `fas fa-caret-down ${arrowTransition}` : `fas fa-caret-down ${arrowRotate}`}`} /> : null}
+                                    <ListItemIcon className={it.active ? active : ''}>
+                                        <i className={`${it.icon} ${icon} ${it.name === "Projects" ? projectIcon : ''}`} />
+                                    </ListItemIcon>
+                                    <ListItemText className={listItemText} primary={<Typography className={it.active ? active : ''}>{it.name}</Typography>} />
+                                </span>
+                            </ListItem>
+                            {it.name === "Projects" ? (
+                                <Collapse in={it.open} timeout="auto" unmountOnExit>
+                                    {this.props.children}
+                                </Collapse>) : null}
+                        </span>
+                    ))}
+                </List>
+            </div>
+        );
+    }
+}
+
+type CssRules = 'active' | 'listItemText' | 'row' | 'leftSidePanelContainer' | 'list' | 'icon' | 'projectIcon' |
+    'activeArrow' | 'inactiveArrow' | 'arrowRotate' | 'arrowTransition';
+
+const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
+    active: {
+        color: '#4285F6',
+    },
+    listItemText: {
+        padding: '0px',
+    },
+    row: {
+        display: 'flex',
+        alignItems: 'center',
+    },
+    activeArrow: {
+        color: '#4285F6',
+        position: 'absolute',
+    },
+    inactiveArrow: {
+        position: 'absolute',
+    },
+    arrowTransition: {
+        transition: 'all 0.1s ease',
+    },
+    arrowRotate: {
+        transition: 'all 0.1s ease',
+        transform: 'rotate(-90deg)',
+    },
+    leftSidePanelContainer: {
+        overflowY: 'auto',
+        minWidth: '240px',
+        whiteSpace: 'nowrap',
+        marginTop: '38px',
+        display: 'flex',
+        flexGrow: 1,
+    },
+    list: {
+        paddingBottom: '5px',
+        paddingTop: '5px',
+        paddingLeft: '14px',
+        minWidth: '240px',
+    },
+    icon: {
+        minWidth: '20px',
+    },
+    projectIcon: {
+        marginLeft: '17px',
+    }
+});
+
+export default withStyles(styles)(SidePanel);
\ No newline at end of file
index 6731950c1adb8a78543cffa36000f2441e8144a4..2c19a831ecd1154bfe7de3746787a6b3d6641eb3 100644 (file)
@@ -9,38 +9,6 @@ import { StyleRulesCallback, Theme, withStyles, WithStyles } from '@material-ui/
 import { ReactElement } from "react";
 import Collapse from "@material-ui/core/Collapse/Collapse";
 import CircularProgress from '@material-ui/core/CircularProgress';
-import { inherits } from 'util';
-
-type CssRules = 'list' | 'activeArrow' | 'inactiveArrow' | 'arrowRotate' | 'arrowTransition' | 'loader' | 'arrowVisibility';
-
-const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
-    list: {
-        paddingBottom: '3px',
-        paddingTop: '3px',
-    },
-    activeArrow: {
-        color: '#4285F6',
-        position: 'absolute',
-    },
-    inactiveArrow: {
-        position: 'absolute',
-    },
-    arrowTransition: {
-        transition: 'all 0.1s ease',
-    },
-    arrowRotate: {
-        transition: 'all 0.1s ease',
-        transform: 'rotate(-90deg)',
-    },
-    arrowVisibility: {
-        opacity: 0,
-    },
-    loader: {
-        position: 'absolute',
-        transform: 'translate(0px)',
-        top: '3px'
-    }
-});
 
 export enum TreeItemStatus {
     Initial,
@@ -61,27 +29,28 @@ export interface TreeItem<T> {
 interface TreeProps<T> {
     items?: Array<TreeItem<T>>;
     render: (item: TreeItem<T>, level?: number) => ReactElement<{}>;
-    toggleItem: (id: string, status: TreeItemStatus) => any;
+    toggleItemOpen: (id: string, status: TreeItemStatus) => void;
+    toggleItemActive: (id: string, status: TreeItemStatus) => void;
     level?: number;
 }
 
 class Tree<T> extends React.Component<TreeProps<T> & WithStyles<CssRules>, {}> {
     renderArrow(status: TreeItemStatus, arrowClass: string, open: boolean, id: string) {
-        return <i
-            onClick={() => this.props.toggleItem(id, status)}
+        const { arrowTransition, arrowVisibility, arrowRotate } = this.props.classes;
+        return <i onClick={() => this.props.toggleItemOpen(id, status)}
             className={`
-                ${arrowClass} 
-                ${status === TreeItemStatus.Pending ? this.props.classes.arrowVisibility : ''} 
-                ${open ? `fas fa-caret-down ${this.props.classes.arrowTransition}` : `fas fa-caret-down ${this.props.classes.arrowRotate}`}`} />;
+                    ${arrowClass} 
+                    ${status === TreeItemStatus.Pending ? arrowVisibility : ''} 
+                    ${open ? `fas fa-caret-down ${arrowTransition}` : `fas fa-caret-down ${arrowRotate}`}`} />;
     }
     render(): ReactElement<any> {
         const level = this.props.level ? this.props.level : 0;
-        const { classes, render, toggleItem, items } = this.props;
+        const { classes, render, toggleItemOpen, items, toggleItemActive } = this.props;
         const { list, inactiveArrow, activeArrow, loader } = classes;
         return <List component="div" className={list}>
             {items && items.map((it: TreeItem<T>, idx: number) =>
                 <div key={`item/${level}/${idx}`}>
-                    <ListItem button className={list} style={{ paddingLeft: (level + 1) * 20 }}>
+                    <ListItem button className={list} style={{ paddingLeft: (level + 1) * 20 }} onClick={() => toggleItemActive(it.id, it.status)}>
                         {it.status === TreeItemStatus.Pending ? <CircularProgress size={10} className={loader} /> : null}
                         {it.toggled && it.items && it.items.length === 0 ? null : this.renderArrow(it.status, it.active ? activeArrow : inactiveArrow, it.open, it.id)}
                         {render(it, level)}
@@ -91,7 +60,8 @@ class Tree<T> extends React.Component<TreeProps<T> & WithStyles<CssRules>, {}> {
                             <StyledTree
                                 items={it.items}
                                 render={render}
-                                toggleItem={toggleItem}
+                                toggleItemOpen={toggleItemOpen}
+                                toggleItemActive={toggleItemActive}
                                 level={level + 1} />
                         </Collapse>}
                 </div>)}
@@ -99,5 +69,36 @@ class Tree<T> extends React.Component<TreeProps<T> & WithStyles<CssRules>, {}> {
     }
 }
 
+type CssRules = 'list' | 'activeArrow' | 'inactiveArrow' | 'arrowRotate' | 'arrowTransition' | 'loader' | 'arrowVisibility';
+
+const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
+    list: {
+        paddingBottom: '3px',
+        paddingTop: '3px',
+    },
+    activeArrow: {
+        color: '#4285F6',
+        position: 'absolute',
+    },
+    inactiveArrow: {
+        position: 'absolute',
+    },
+    arrowTransition: {
+        transition: 'all 0.1s ease',
+    },
+    arrowRotate: {
+        transition: 'all 0.1s ease',
+        transform: 'rotate(-90deg)',
+    },
+    arrowVisibility: {
+        opacity: 0,
+    },
+    loader: {
+        position: 'absolute',
+        transform: 'translate(0px)',
+        top: '3px'
+    }
+});
+
 const StyledTree = withStyles(styles)(Tree);
 export default StyledTree;
index cf1610f83226cd12a279b4a28db1f3494ee740a7..ba395e8b785ab49dd6255427ff90382b43ff6191 100644 (file)
@@ -26,7 +26,8 @@ const store = configureStore({
     },
     auth: {
         user: undefined
-    }
+    },
+    sidePanel: []
 }, history);
 
 store.dispatch(authActions.INIT());
index 728b1cc95e587112104d032f6cbc56698fe45426..3c264d3ef9fcbba5089a9294a65b3aec0d863c5b 100644 (file)
@@ -1,29 +1,33 @@
 // Copyright (C) The Arvados Authors. All rights reserved.
 //
 // SPDX-License-Identifier: AGPL-3.0
+import { default as unionize, ofType, UnionOf } from "unionize";
 
 import { Project } from "../../models/project";
-import { default as unionize, ofType, UnionOf } from "unionize";
 import { projectService } from "../../services/services";
 import { Dispatch } from "redux";
 
 const actions = unionize({
     CREATE_PROJECT: ofType<Project>(),
     REMOVE_PROJECT: ofType<string>(),
-    PROJECTS_REQUEST: ofType<any>(),
+    PROJECTS_REQUEST: ofType<string>(),
     PROJECTS_SUCCESS: ofType<{ projects: Project[], parentItemId?: string }>(),
-    TOGGLE_PROJECT_TREE_ITEM: ofType<string>()
+    TOGGLE_PROJECT_TREE_ITEM_OPEN: ofType<string>(),
+    TOGGLE_PROJECT_TREE_ITEM_ACTIVE: ofType<string>(),
+    RESET_PROJECT_TREE_ACTIVITY: ofType<string>(),
 }, {
-    tag: 'type',
-    value: 'payload'
-});
+        tag: 'type',
+        value: 'payload'
+    });
 
 export const getProjectList = (parentUuid?: string) => (dispatch: Dispatch): Promise<Project[]> => {
-    dispatch(actions.PROJECTS_REQUEST());
-    return projectService.getProjectList(parentUuid).then(projects => {
-        dispatch(actions.PROJECTS_SUCCESS({projects, parentItemId: parentUuid}));
-        return projects;
-    });
+    if (parentUuid) {
+        dispatch(actions.PROJECTS_REQUEST(parentUuid));
+        return projectService.getProjectList(parentUuid).then(projects => {
+            dispatch(actions.PROJECTS_SUCCESS({ projects, parentItemId: parentUuid }));
+            return projects;
+        });
+    } return Promise.resolve([]);
 };
 
 export type ProjectAction = UnionOf<typeof actions>;
index f964e0ea311f333af3486a69ed6188a1cddb9e0c..e8d6afc6154dd004af9729042bbd9d48f7265bff 100644 (file)
@@ -38,21 +38,144 @@ describe('project-reducer', () => {
         const projects = [project, project];
         const state = projectsReducer(initialState, actions.PROJECTS_SUCCESS({ projects, parentItemId: undefined }));
         expect(state).toEqual([{
+            active: false,
+            open: false,
+            id: "test123",
+            items: [],
+            data: project,
+            status: 0
+        }, {
+            active: false,
+            open: false,
+            id: "test123",
+            items: [],
+            data: project,
+            status: 0
+        }
+        ]);
+    });
+
+    it('should remove activity on projects list', () => {
+        const initialState = [
+            {
+                data: {
+                    name: 'test',
+                    href: 'href',
+                    createdAt: '2018-01-01',
+                    modifiedAt: '2018-01-01',
+                    ownerUuid: 'owner-test123',
+                    uuid: 'test123',
+                    kind: 'example'
+                },
+                id: "1",
+                open: true,
+                active: true,
+                status: 1
+            }
+        ];
+        const project = [
+            {
+                data: {
+                    name: 'test',
+                    href: 'href',
+                    createdAt: '2018-01-01',
+                    modifiedAt: '2018-01-01',
+                    ownerUuid: 'owner-test123',
+                    uuid: 'test123',
+                    kind: 'example'
+                },
+                id: "1",
+                open: true,
                 active: false,
-                open: false,
-                id: "test123",
-                items: [],
-                data: project,
-                status: 0
-            }, {
+                status: 1
+            }
+        ];
+
+        const state = projectsReducer(initialState, actions.RESET_PROJECT_TREE_ACTIVITY(initialState[0].id));
+        expect(state).toEqual(project);
+    });
+
+    it('should toggle project tree item activity', () => {
+        const initialState = [
+            {
+                data: {
+                    name: 'test',
+                    href: 'href',
+                    createdAt: '2018-01-01',
+                    modifiedAt: '2018-01-01',
+                    ownerUuid: 'owner-test123',
+                    uuid: 'test123',
+                    kind: 'example'
+                },
+                id: "1",
+                open: true,
+                active: false,
+                status: 1
+            }
+        ];
+        const project = [
+            {
+                data: {
+                    name: 'test',
+                    href: 'href',
+                    createdAt: '2018-01-01',
+                    modifiedAt: '2018-01-01',
+                    ownerUuid: 'owner-test123',
+                    uuid: 'test123',
+                    kind: 'example'
+                },
+                id: "1",
+                open: true,
+                active: true,
+                status: 1
+            }
+        ];
+
+        const state = projectsReducer(initialState, actions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(initialState[0].id));
+        expect(state).toEqual(project);
+    });
+
+
+    it('should close project tree item ', () => {
+        const initialState = [
+            {
+                data: {
+                    name: 'test',
+                    href: 'href',
+                    createdAt: '2018-01-01',
+                    modifiedAt: '2018-01-01',
+                    ownerUuid: 'owner-test123',
+                    uuid: 'test123',
+                    kind: 'example'
+                },
+                id: "1",
+                open: true,
                 active: false,
+                status: 1,
+                toggled: false,
+            }
+        ];
+        const project = [
+            {
+                data: {
+                    name: 'test',
+                    href: 'href',
+                    createdAt: '2018-01-01',
+                    modifiedAt: '2018-01-01',
+                    ownerUuid: 'owner-test123',
+                    uuid: 'test123',
+                    kind: 'example'
+                },
+                id: "1",
                 open: false,
-                id: "test123",
-                items: [],
-                data: project,
-                status: 0
+                active: false,
+                status: 1,
+                toggled: true
             }
-        ]);
+        ];
+
+        const state = projectsReducer(initialState, actions.TOGGLE_PROJECT_TREE_ITEM_OPEN(initialState[0].id));
+        expect(state).toEqual(project);
     });
 });
 
index 4f7545fc979ea93b9fbe4fd6ee2f4e74559e6a87..48db05df77eb6051fcc5c84509fe317777ad7f26 100644 (file)
@@ -2,10 +2,11 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
+import * as _ from "lodash";
+
 import { Project } from "../../models/project";
 import actions, { ProjectAction } from "./project-action";
 import { TreeItem, TreeItemStatus } from "../../components/tree/tree";
-import * as _ from "lodash";
 
 export type ProjectState = Array<TreeItem<Project>>;
 
@@ -83,17 +84,29 @@ const projectsReducer = (state: ProjectState = [], action: ProjectAction) => {
         PROJECTS_SUCCESS: ({ projects, parentItemId }) => {
             return updateProjectTree(state, projects, parentItemId);
         },
-        TOGGLE_PROJECT_TREE_ITEM: itemId => {
+        TOGGLE_PROJECT_TREE_ITEM_OPEN: itemId => {
             const tree = _.cloneDeep(state);
-            resetTreeActivity(tree);
             const item = findTreeItem(tree, itemId);
             if (item) {
+                item.toggled = true;
                 item.open = !item.open;
+            }
+            return tree;
+        },
+        TOGGLE_PROJECT_TREE_ITEM_ACTIVE: itemId => {
+            const tree = _.cloneDeep(state);
+            resetTreeActivity(tree);
+            const item = findTreeItem(tree, itemId);
+            if (item) {
                 item.active = true;
-                item.toggled = true;
             }
             return tree;
         },
+        RESET_PROJECT_TREE_ACTIVITY: () => {
+            const tree = _.cloneDeep(state);
+            resetTreeActivity(tree);
+            return tree;
+        },
         default: () => state
     });
 };
diff --git a/src/store/side-panel/side-panel-action.ts b/src/store/side-panel/side-panel-action.ts
new file mode 100644 (file)
index 0000000..32fa653
--- /dev/null
@@ -0,0 +1,17 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import { default as unionize, ofType, UnionOf } from "unionize";
+
+const actions = unionize({
+    TOGGLE_SIDE_PANEL_ITEM_OPEN: ofType<string>(),
+    TOGGLE_SIDE_PANEL_ITEM_ACTIVE: ofType<string>(),
+    RESET_SIDE_PANEL_ACTIVITY: ofType<string>(),
+}, {
+    tag: 'type',
+    value: 'payload'
+});
+
+export type SidePanelAction = UnionOf<typeof actions>;
+export default actions;
\ No newline at end of file
diff --git a/src/store/side-panel/side-panel-reducer.test.ts b/src/store/side-panel/side-panel-reducer.test.ts
new file mode 100644 (file)
index 0000000..942c16e
--- /dev/null
@@ -0,0 +1,81 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import sidePanelReducer from "./side-panel-reducer";
+import actions from "./side-panel-action";
+
+describe('side-panel-reducer', () => {
+
+    it('should toggle activity on side-panel', () => {
+        const initialState = [
+            {
+                id: "1",
+                name: "Projects",
+                icon: "fas fa-th fa-fw",
+                open: false,
+                active: false,
+            }
+        ];
+        const project = [
+            {
+                id: "1",
+                name: "Projects",
+                icon: "fas fa-th fa-fw",
+                open: false,
+                active: true,
+            }
+        ];
+
+        const state = sidePanelReducer(initialState, actions.TOGGLE_SIDE_PANEL_ITEM_ACTIVE(initialState[0].id));
+        expect(state).toEqual(project);
+    });
+
+    it('should open side-panel item', () => {
+        const initialState = [
+            {
+                id: "1",
+                name: "Projects",
+                icon: "fas fa-th fa-fw",
+                open: false,
+                active: false,
+            }
+        ];
+        const project = [
+            {
+                id: "1",
+                name: "Projects",
+                icon: "fas fa-th fa-fw",
+                open: true,
+                active: false,
+            }
+        ];
+
+        const state = sidePanelReducer(initialState, actions.TOGGLE_SIDE_PANEL_ITEM_OPEN(initialState[0].id));
+        expect(state).toEqual(project);
+    });
+
+    it('should remove activity on side-panel item', () => {
+        const initialState = [
+            {
+                id: "1",
+                name: "Projects",
+                icon: "fas fa-th fa-fw",
+                open: false,
+                active: true,
+            }
+        ];
+        const project = [
+            {
+                id: "1",
+                name: "Projects",
+                icon: "fas fa-th fa-fw",
+                open: false,
+                active: false,
+            }
+        ];
+
+        const state = sidePanelReducer(initialState, actions.RESET_SIDE_PANEL_ACTIVITY(initialState[0].id));
+        expect(state).toEqual(project);
+    });
+});
\ No newline at end of file
diff --git a/src/store/side-panel/side-panel-reducer.ts b/src/store/side-panel/side-panel-reducer.ts
new file mode 100644 (file)
index 0000000..8051017
--- /dev/null
@@ -0,0 +1,84 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import * as _ from "lodash";
+
+import actions, { SidePanelAction } from './side-panel-action';
+import { SidePanelItem } from '../../components/side-panel/side-panel';
+
+export type SidePanelState = SidePanelItem[];
+
+const sidePanelReducer = (state: SidePanelState = sidePanelData, action: SidePanelAction) => {
+    if (state.length === 0) {
+        return sidePanelData;
+    } else {
+        return actions.match(action, {
+            TOGGLE_SIDE_PANEL_ITEM_OPEN: itemId => state.map(it => itemId === it.id && it.open === false ? {...it, open: true} : {...it, open: false}),
+            TOGGLE_SIDE_PANEL_ITEM_ACTIVE: itemId => {
+                const sidePanel = _.cloneDeep(state);
+                resetSidePanelActivity(sidePanel);
+                sidePanel.map(it => {
+                    if (it.id === itemId) {
+                        it.active = true;
+                    }
+                });
+                return sidePanel;
+            },
+            RESET_SIDE_PANEL_ACTIVITY: () => {
+                const sidePanel = _.cloneDeep(state);
+                resetSidePanelActivity(sidePanel);
+                return sidePanel;
+            },
+            default: () => state
+        });
+    }
+};
+
+export const sidePanelData = [
+    {
+        id: "1",
+        name: "Projects",
+        icon: "fas fa-th fa-fw",
+        open: false,
+        active: false,
+    },
+    {
+        id: "2",
+        name: "Shared with me",
+        icon: "fas fa-users fa-fw",
+        active: false,
+    },
+    {
+        id: "3",
+        name: "Workflows",
+        icon: "fas fa-cogs fa-fw",
+        active: false,
+    },
+    {
+        id: "4",
+        name: "Recent open",
+        icon: "icon-time fa-fw",
+        active: false,
+    },
+    {
+        id: "5",
+        name: "Favorites",
+        icon: "fas fa-star fa-fw",
+        active: false,
+    },
+    {
+        id: "6",
+        name: "Trash",
+        icon: "fas fa-trash-alt fa-fw",
+        active: false,
+    }
+];
+
+function resetSidePanelActivity(sidePanel: SidePanelItem[]) {
+    for (const t of sidePanel) {
+        t.active = false;
+    }
+}
+
+export default sidePanelReducer;
index 6b9c31ff4ee3bfca4426d3364b8440625c4d6e19..6089caf35cdf409d77ceb5ede5ced2ebc4083967 100644 (file)
@@ -6,26 +6,30 @@ import { createStore, applyMiddleware, compose, Middleware, combineReducers } fr
 import { routerMiddleware, routerReducer, RouterState } from "react-router-redux";
 import thunkMiddleware from 'redux-thunk';
 import { History } from "history";
+
 import projectsReducer, { ProjectState } from "./project/project-reducer";
+import sidePanelReducer, { SidePanelState } from './side-panel/side-panel-reducer';
 import authReducer, { AuthState } from "./auth/auth-reducer";
 import collectionsReducer from "./collection/collection-reducer";
 
 const composeEnhancers =
     (process.env.NODE_ENV === 'development' &&
-    window && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__) ||
+        window && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__) ||
     compose;
 
 export interface RootState {
     auth: AuthState;
     projects: ProjectState;
     router: RouterState;
+    sidePanel: SidePanelState;
 }
 
 const rootReducer = combineReducers({
     auth: authReducer,
     projects: projectsReducer,
     collections: collectionsReducer,
-    router: routerReducer
+    router: routerReducer,
+    sidePanel: sidePanelReducer
 });
 
 
index d53121304c817a83b113406b5451f8c433ca37b7..1ba3abb8bb39ddb2c40de1098b769b35bd7ad105 100644 (file)
@@ -26,13 +26,14 @@ describe("ProjectTree component", () => {
                 uuid: "uuid",
                 ownerUuid: "ownerUuid",
                 href: "href",
+                kind: 'example'
             },
             id: "3",
             open: true,
             active: true,
             status: 1
         };
-        const wrapper = mount(<ProjectTree projects={[project]} toggleProjectTreeItem={() => { }} />);
+        const wrapper = mount(<ProjectTree projects={[project]} toggleOpen={jest.fn()} toggleActive={jest.fn()} />);
 
         expect(wrapper.find(ListItemIcon)).toHaveLength(1);
     });
@@ -47,6 +48,7 @@ describe("ProjectTree component", () => {
                     uuid: "uuid",
                     ownerUuid: "ownerUuid",
                     href: "href",
+                    kind: 'example'
                 },
                 id: "3",
                 open: false,
@@ -61,6 +63,7 @@ describe("ProjectTree component", () => {
                     uuid: "uuid",
                     ownerUuid: "ownerUuid",
                     href: "href",
+                    kind: 'example'
                 },
                 id: "3",
                 open: false,
@@ -68,7 +71,7 @@ describe("ProjectTree component", () => {
                 status: 1
             }
         ];
-        const wrapper = mount(<ProjectTree projects={project} toggleProjectTreeItem={() => { }} />);
+        const wrapper = mount(<ProjectTree projects={project} toggleOpen={jest.fn()} toggleActive={jest.fn()} />);
 
         expect(wrapper.find(ListItemIcon)).toHaveLength(2);
     });
@@ -83,6 +86,7 @@ describe("ProjectTree component", () => {
                     uuid: "uuid",
                     ownerUuid: "ownerUuid",
                     href: "href",
+                    kind: 'example'
                 },
                 id: "3",
                 open: true,
@@ -97,6 +101,7 @@ describe("ProjectTree component", () => {
                             uuid: "uuid",
                             ownerUuid: "ownerUuid",
                             href: "href",
+                            kind: 'example'
                         },
                         id: "3",
                         open: true,
@@ -106,7 +111,7 @@ describe("ProjectTree component", () => {
                 ]
             }
         ];
-        const wrapper = mount(<ProjectTree projects={project} toggleProjectTreeItem={() => { }} />);
+        const wrapper = mount(<ProjectTree projects={project} toggleOpen={jest.fn()} toggleActive={jest.fn()}/>);
 
         expect(wrapper.find(Collapse)).toHaveLength(1);
     });
@@ -120,13 +125,14 @@ describe("ProjectTree component", () => {
                 uuid: "uuid",
                 ownerUuid: "ownerUuid",
                 href: "href",
+                kind: 'example'
             },
             id: "3",
             open: false,
             active: true,
             status: 1
         };
-        const wrapper = mount(<ProjectTree projects={[project]} toggleProjectTreeItem={() => { }} />);
+        const wrapper = mount(<ProjectTree projects={[project]} toggleOpen={jest.fn()} toggleActive={jest.fn()} />);
 
         expect(wrapper.find(CircularProgress)).toHaveLength(1);
     });
index fd32ff040d82dc5dce7f8bbc94583c88357695dd..f51b65e054df7f8ab2d69a263e658f9a1fe2a7d8 100644 (file)
@@ -12,6 +12,36 @@ import Typography from '@material-ui/core/Typography';
 import Tree, { TreeItem, TreeItemStatus } from '../../components/tree/tree';
 import { Project } from '../../models/project';
 
+export interface ProjectTreeProps {
+    projects: Array<TreeItem<Project>>;
+    toggleOpen: (id: string, status: TreeItemStatus) => void;
+    toggleActive: (id: string, status: TreeItemStatus) => void;
+}
+
+class ProjectTree<T> extends React.Component<ProjectTreeProps & WithStyles<CssRules>> {
+    render(): ReactElement<any> {
+        const { classes, projects, toggleOpen, toggleActive } = this.props;
+        const { active, listItemText, row, treeContainer } = classes;
+        return (
+            <div className={treeContainer}>
+                <Tree items={projects}
+                    toggleItemOpen={toggleOpen}
+                    toggleItemActive={toggleActive}
+                    render={(project: TreeItem<Project>) =>
+                        <span className={row}>
+                            <ListItemIcon className={project.active ? active : ''}>
+                                <i className="fas fa-folder" />
+                            </ListItemIcon>
+                            <ListItemText className={listItemText} primary={
+                                <Typography className={project.active ? active : ''}>{project.data.name}</Typography>
+                            } />
+                        </span>
+                    } />
+            </div>
+        );
+    }
+}
+
 type CssRules = 'active' | 'listItemText' | 'row' | 'treeContainer';
 
 const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
@@ -27,42 +57,10 @@ const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
         marginLeft: '20px',
     },
     treeContainer: {
-        marginTop: '37px',
-        overflowX: 'visible',
-        overflowY: 'auto',
         minWidth: '240px',
         whiteSpace: 'nowrap',
+        marginLeft: '13px',
     }
 });
 
-export interface ProjectTreeProps {
-    projects: Array<TreeItem<Project>>;
-    toggleProjectTreeItem: (id: string, status: TreeItemStatus) => void;
-}
-
-class ProjectTree<T> extends React.Component<ProjectTreeProps & WithStyles<CssRules>> {
-    render(): ReactElement<any> {
-        const {classes, projects} = this.props;
-        const {active, listItemText, row, treeContainer} = classes;
-        return (
-            <div className={treeContainer}>
-                <Tree items={projects}
-                    toggleItem={this.props.toggleProjectTreeItem}
-                    render={(project: TreeItem<Project>, level: number) =>
-                        <span className={row}>
-                            <ListItemIcon className={project.active ? active : ''}>
-                                {level === 0 ? <i className="fas fa-th"/> : <i className="fas fa-folder"/>}
-                            </ListItemIcon>
-                            <ListItemText className={listItemText} primary={
-                                <Typography className={project.active ? active : ''}>
-                                    {project.data.name}
-                                </Typography>
-                            }/>
-                        </span>
-                    }/>
-            </div>
-        );
-    }
-}
-
 export default withStyles(styles)(ProjectTree);
index 7b9b74d095c65a8a1ad760a2c4c87f360cb13836..6925792293b65c475539ddd9e0a9bf279cb02f9e 100644 (file)
@@ -14,7 +14,7 @@ const history = createBrowserHistory();
 
 it('renders without crashing', () => {
     const div = document.createElement('div');
-    const store = configureStore({ projects: [], router: { location: null }, auth: {} }, createBrowserHistory());
+    const store = configureStore({ projects: [], router: { location: null }, auth: {}, sidePanel: [] }, createBrowserHistory());
     ReactDOM.render(
         <Provider store={store}>
             <ConnectedRouter history={history}>
index bac0b473f10e780016df801e5f7323d05a5fc6ac..4f9843cb0a3e952786ef3489de8ac29b477796ee 100644 (file)
@@ -3,7 +3,6 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import * as React from 'react';
-
 import { StyleRulesCallback, Theme, WithStyles, withStyles } from '@material-ui/core/styles';
 import Drawer from '@material-ui/core/Drawer';
 import { connect, DispatchProp } from "react-redux";
@@ -20,6 +19,9 @@ import { TreeItem, TreeItemStatus } from "../../components/tree/tree";
 import { Project } from "../../models/project";
 import { getTreePath } from '../../store/project/project-reducer';
 import ProjectPanel from '../project-panel/project-panel';
+import sidePanelActions from '../../store/side-panel/side-panel-action';
+import { projectService } from '../../services/services';
+import SidePanel, { SidePanelItem } from '../../components/side-panel/side-panel';
 
 const drawerWidth = 240;
 const appBarHeight = 102;
@@ -45,6 +47,8 @@ const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
     drawerPaper: {
         position: 'relative',
         width: drawerWidth,
+        display: 'flex',
+        flexDirection: 'column',
     },
     contentWrapper: {
         backgroundColor: theme.palette.background.default,
@@ -64,6 +68,7 @@ const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
 interface WorkbenchDataProps {
     projects: Array<TreeItem<Project>>;
     user?: User;
+    sidePanelItems: SidePanelItem[];
 }
 
 interface WorkbenchActionProps {
@@ -125,7 +130,7 @@ class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
 
     mainAppBarActions: MainAppBarActionProps = {
         onBreadcrumbClick: ({ itemId, status }: NavBreadcrumb) => {
-            this.toggleProjectTreeItem(itemId, status);
+            this.toggleProjectTreeItemOpen(itemId, status);
         },
         onSearch: searchText => {
             this.setState({ searchText });
@@ -134,15 +139,45 @@ class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
         onMenuItemClick: (menuItem: NavMenuItem) => menuItem.action()
     };
 
-    toggleProjectTreeItem = (itemId: string, status: TreeItemStatus) => {
+    toggleProjectTreeItemOpen = (itemId: string, status: TreeItemStatus) => {
         if (status === TreeItemStatus.Loaded) {
             this.openProjectItem(itemId);
+            this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_OPEN(itemId));
+            this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(itemId));
         } else {
             this.props.dispatch<any>(getProjectList(itemId))
-                .then(() => this.openProjectItem(itemId));
+                .then(() => {
+                    this.openProjectItem(itemId);
+                    this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_OPEN(itemId));
+                    this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(itemId));
+                });
         }
     }
 
+    toggleProjectTreeItemActive = (itemId: string, status: TreeItemStatus) => {
+        if (status === TreeItemStatus.Loaded) {
+            this.openProjectItem(itemId);
+            this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(itemId));
+            this.props.dispatch(sidePanelActions.RESET_SIDE_PANEL_ACTIVITY(itemId));
+        } else {
+            this.props.dispatch<any>(getProjectList(itemId))
+                .then(() => {
+                    this.openProjectItem(itemId);
+                    this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(itemId));
+                    this.props.dispatch(sidePanelActions.RESET_SIDE_PANEL_ACTIVITY(itemId));
+                });
+        }
+    }
+
+    toggleSidePanelOpen = (itemId: string) => {
+        this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_OPEN(itemId));
+    }
+
+    toggleSidePanelActive = (itemId: string) => {
+        this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_ACTIVE(itemId));
+        this.props.dispatch(projectActions.RESET_PROJECT_TREE_ACTIVITY(itemId));
+    }
+
     openProjectItem = (itemId: string) => {
         const branch = getTreePath(this.props.projects, itemId);
         this.setState({
@@ -152,12 +187,12 @@ class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
                 status: item.status
             }))
         });
-        this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM(itemId));
+        this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(itemId));
         this.props.dispatch(push(`/project/${itemId}`));
     }
 
     render() {
-        const { classes, user } = this.props;
+        const { classes, user, projects, sidePanelItems } = this.props;
         return (
             <div className={classes.root}>
                 <div className={classes.appBar}>
@@ -176,9 +211,15 @@ class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
                             paper: classes.drawerPaper,
                         }}>
                         <div className={classes.toolbar} />
-                        <ProjectTree
-                            projects={this.props.projects}
-                            toggleProjectTreeItem={this.toggleProjectTreeItem} />
+                        <SidePanel
+                            toggleOpen={this.toggleSidePanelOpen}
+                            toggleActive={this.toggleSidePanelActive}
+                            sidePanelItems={sidePanelItems}>
+                            <ProjectTree
+                                projects={projects}
+                                toggleOpen={this.toggleProjectTreeItemOpen}
+                                toggleActive={this.toggleProjectTreeItemActive} />
+                        </SidePanel>
                     </Drawer>}
                 <main className={classes.contentWrapper}>
                     <div className={classes.content}>
@@ -195,7 +236,8 @@ class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
 export default connect<WorkbenchDataProps>(
     (state: RootState) => ({
         projects: state.projects,
-        user: state.auth.user
+        user: state.auth.user,
+        sidePanelItems: state.sidePanel,
     })
 )(
     withStyles(styles)(Workbench)