[ARVADOS-WORKBENCH2] updated: 1.1.4-245-g312f0cb

Git user git at public.curoverse.com
Mon Jul 9 10:47:48 EDT 2018


Summary of changes:
 src/store/project/project-action.ts       | 15 +++++++++++-
 src/store/project/project-reducer.test.ts | 15 ++++++++----
 src/store/project/project-reducer.ts      | 40 ++++++++++++++++++-------------
 3 files changed, 47 insertions(+), 23 deletions(-)

       via  312f0cb3a36f9bce0b16b53765701578191daab8 (commit)
      from  e8d0331277033fea37a9fd73ffc781ffca8759f0 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit 312f0cb3a36f9bce0b16b53765701578191daab8
Author: Michal Klobukowski <michal.klobukowski at contractors.roche.com>
Date:   Mon Jul 9 16:47:34 2018 +0200

    Create actions and store field for project creator
    
    Feature #13694
    
    Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski <michal.klobukowski at contractors.roche.com>

diff --git a/src/store/project/project-action.ts b/src/store/project/project-action.ts
index 5169349..a02c9e7 100644
--- a/src/store/project/project-action.ts
+++ b/src/store/project/project-action.ts
@@ -8,9 +8,13 @@ import { projectService } from "../../services/services";
 import { Dispatch } from "redux";
 import { getResourceKind } from "../../models/resource";
 import FilterBuilder from "../../common/api/filter-builder";
+import { ThunkAction } from "../../../node_modules/redux-thunk";
 
 const actions = unionize({
-    CREATE_PROJECT: ofType<Project>(),
+    OPEN_PROJECT_CREATOR: ofType<{}>(),
+    CREATE_PROJECT: ofType<Partial<ProjectResource>>(),
+    CREATE_PROJECT_SUCCESS: ofType<ProjectResource>(),
+    CREATE_PROJECT_ERROR: ofType<string>(),
     REMOVE_PROJECT: ofType<string>(),
     PROJECTS_REQUEST: ofType<string>(),
     PROJECTS_SUCCESS: ofType<{ projects: Project[], parentItemId?: string }>(),
@@ -38,5 +42,14 @@ export const getProjectList = (parentUuid: string = '') => (dispatch: Dispatch)
     });
 };
 
+export const createProject = (project: Partial<ProjectResource>) =>
+    (dispatch: Dispatch) => {
+        dispatch(actions.CREATE_PROJECT(project));
+        return projectService
+            .create(project)
+            .then(project => dispatch(actions.CREATE_PROJECT_SUCCESS(project)))
+            .catch(() => dispatch(actions.CREATE_PROJECT_ERROR("Could not create a project")));
+    };
+
 export type ProjectAction = UnionOf<typeof actions>;
 export default actions;
diff --git a/src/store/project/project-reducer.test.ts b/src/store/project/project-reducer.test.ts
index c80f18c..724623e 100644
--- a/src/store/project/project-reducer.test.ts
+++ b/src/store/project/project-reducer.test.ts
@@ -76,7 +76,8 @@ describe('project-reducer', () => {
                 active: true,
                 status: 1
             }],
-            currentItemId: "1"
+            currentItemId: "1",
+            creator: { opened: false, pending: false },
         };
         const project = {
             items: [{
@@ -118,7 +119,8 @@ describe('project-reducer', () => {
                 active: false,
                 status: 1
             }],
-            currentItemId: "1"
+            currentItemId: "1",
+            creator: { opened: false, pending: false }
         };
         const project = {
             items: [{
@@ -137,7 +139,8 @@ describe('project-reducer', () => {
                 status: 1,
                 toggled: true
             }],
-            currentItemId: "1"
+            currentItemId: "1",
+            creator: { opened: false, pending: false },
         };
 
         const state = projectsReducer(initialState, actions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(initialState.items[0].id));
@@ -163,7 +166,8 @@ describe('project-reducer', () => {
                 status: 1,
                 toggled: false,
             }],
-            currentItemId: "1"
+            currentItemId: "1",
+            creator: { opened: false, pending: false }
         };
         const project = {
             items: [{
@@ -182,7 +186,8 @@ describe('project-reducer', () => {
                 status: 1,
                 toggled: true
             }],
-            currentItemId: "1"
+            currentItemId: "1",
+            creator: { opened: false, pending: false },
         };
 
         const state = projectsReducer(initialState, actions.TOGGLE_PROJECT_TREE_ITEM_OPEN(initialState.items[0].id));
diff --git a/src/store/project/project-reducer.ts b/src/store/project/project-reducer.ts
index efef809..bb7d3d0 100644
--- a/src/store/project/project-reducer.ts
+++ b/src/store/project/project-reducer.ts
@@ -10,7 +10,11 @@ import { TreeItem, TreeItemStatus } from "../../components/tree/tree";
 
 export type ProjectState = {
     items: Array<TreeItem<Project>>,
-    currentItemId: string
+    currentItemId: string,
+    creator: {
+        opened: boolean,
+        pending: boolean
+    }
 };
 
 export function findTreeItem<T>(tree: Array<TreeItem<T>>, itemId: string): TreeItem<T> | undefined {
@@ -40,12 +44,12 @@ export function getActiveTreeItem<T>(tree: Array<TreeItem<T>>): TreeItem<T> | un
 }
 
 export function getTreePath<T>(tree: Array<TreeItem<T>>, itemId: string): Array<TreeItem<T>> {
-    for (const item of tree){
-        if(item.id === itemId){
+    for (const item of tree) {
+        if (item.id === itemId) {
             return [item];
         } else {
             const branch = getTreePath(item.items || [], itemId);
-            if(branch.length > 0){
+            if (branch.length > 0) {
                 return [item, ...branch];
             }
         }
@@ -85,20 +89,22 @@ function updateProjectTree(tree: Array<TreeItem<Project>>, projects: Project[],
     return items;
 }
 
-const projectsReducer = (state: ProjectState = { items: [], currentItemId: "" }, action: ProjectAction) => {
+const initialState: ProjectState = {
+    items: [],
+    currentItemId: "",
+    creator: {
+        opened: false,
+        pending: false
+    }
+};
+
+
+const projectsReducer = (state: ProjectState = initialState, action: ProjectAction) => {
     return actions.match(action, {
-        CREATE_PROJECT: project => ({
-            ...state,
-            items: state.items.concat({
-                id: project.uuid,
-                open: false,
-                active: false,
-                status: TreeItemStatus.Loaded,
-                toggled: false,
-                items: [],
-                data: project
-            })
-        }),
+        OPEN_PROJECT_CREATOR: () => ({ ...state, creator: { opened: true, pending: false } }),
+        CREATE_PROJECT: () => ({ ...state, creator: { opened: false, pending: true } }),
+        CREATE_PROJECT_SUCCESS: () => ({ ...state, creator: { opened: false, pending: false } }),
+        CREATE_PROJECT_ERROR: () => ({ ...state, creator: { opened: false, pending: false } }),
         REMOVE_PROJECT: () => state,
         PROJECTS_REQUEST: itemId => {
             const items = _.cloneDeep(state.items);

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


hooks/post-receive
-- 




More information about the arvados-commits mailing list