[ARVADOS-WORKBENCH2] updated: 1.1.4-634-gf45dd93

Git user git at public.curoverse.com
Fri Aug 17 10:22:25 EDT 2018


Summary of changes:
 .../collection-service-files-response.ts           | 15 +++++---
 .../creator/collection-creator-action.ts           | 44 ++++------------------
 .../uploader/collection-uploader-actions.ts        | 16 ++++----
 3 files changed, 24 insertions(+), 51 deletions(-)

       via  f45dd93f467fe02c33908c0b4b3ff8ba01827bc9 (commit)
      from  158a4936f754ad78004e1bbcbb5af053a6a4073a (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 f45dd93f467fe02c33908c0b4b3ff8ba01827bc9
Author: Michal Klobukowski <michal.klobukowski at contractors.roche.com>
Date:   Fri Aug 17 16:22:11 2018 +0200

    Refactor new code
    
    Feature #14013
    
    Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski <michal.klobukowski at contractors.roche.com>

diff --git a/src/services/collection-service/collection-service-files-response.ts b/src/services/collection-service/collection-service-files-response.ts
index 4545096..581a6fa 100644
--- a/src/services/collection-service/collection-service-files-response.ts
+++ b/src/services/collection-service/collection-service-files-response.ts
@@ -14,14 +14,17 @@ export const parseFilesResponse = (document: Document) => {
 
 export const sortFilesTree = (tree: Tree<CollectionDirectory | CollectionFile>) => {
     return mapTree(node => {
-        const children = getNodeChildren(node.id)(tree).map(id => getNode(id)(tree)) as TreeNode<CollectionDirectory | CollectionFile>[];
+        const children = getNodeChildren(node.id)(tree)
+            .map(id => getNode(id)(tree))
+            .filter(node => node !== undefined) as TreeNode<CollectionDirectory | CollectionFile>[];
+
         children.sort((a, b) =>
             a.value.type !== b.value.type
                 ? a.value.type === CollectionFileType.DIRECTORY ? -1 : 1
                 : a.value.name.localeCompare(b.value.name)
         );
-        return { ...node, children: children.map(child => child.id) } as TreeNode<CollectionDirectory | CollectionFile>;
-    })(tree);
+        return { ...node, children: children.map(child => child.id) };
+    })(tree) as Tree<CollectionDirectory | CollectionFile>;
 };
 
 export const extractFilesData = (document: Document) => {
@@ -32,14 +35,14 @@ export const extractFilesData = (document: Document) => {
         .map(element => {
             const name = getTagValue(element, 'D:displayname', '');
             const size = parseInt(getTagValue(element, 'D:getcontentlength', '0'), 10);
-            const pathname = getTagValue(element, 'D:href', '');
+            const url = getTagValue(element, 'D:href', '');
             const nameSuffix = `/${name || ''}`;
-            const directory = pathname
+            const directory = url
                 .replace(collectionUrlPrefix, '')
                 .replace(nameSuffix, '');
 
             const data = {
-                url: pathname,
+                url,
                 id: `${directory}/${name}`,
                 name,
                 path: directory,
diff --git a/src/store/collections/creator/collection-creator-action.ts b/src/store/collections/creator/collection-creator-action.ts
index f1044a9..5243a61 100644
--- a/src/store/collections/creator/collection-creator-action.ts
+++ b/src/store/collections/creator/collection-creator-action.ts
@@ -8,7 +8,7 @@ import { Dispatch } from "redux";
 import { RootState } from "../../store";
 import { CollectionResource } from '~/models/collection';
 import { ServiceRepository } from "~/services/services";
-import { collectionUploaderActions } from "../uploader/collection-uploader-actions";
+import { uploadCollectionFiles } from '../uploader/collection-uploader-actions';
 import { reset } from "redux-form";
 
 export const collectionCreateActions = unionize({
@@ -22,45 +22,15 @@ export const collectionCreateActions = unionize({
     });
 
 export const createCollection = (collection: Partial<CollectionResource>, files: File[]) =>
-    (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
+    async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
         const { ownerUuid } = getState().collections.creator;
         const collectiontData = { ownerUuid, ...collection };
         dispatch(collectionCreateActions.CREATE_COLLECTION(collectiontData));
-        return services.collectionService
-            .create(collectiontData)
-            .then(collection => {
-                dispatch(collectionUploaderActions.START_UPLOAD());
-                services.collectionService.uploadFiles(collection.uuid, files,
-                    (fileId, loaded, total, currentTime) => {
-                        dispatch(collectionUploaderActions.SET_UPLOAD_PROGRESS({ fileId, loaded, total, currentTime }));
-                    })
-                    .then(() => {
-                        dispatch(collectionCreateActions.CREATE_COLLECTION_SUCCESS(collection));
-                        dispatch(reset('collectionCreateDialog'));
-                        dispatch(collectionUploaderActions.CLEAR_UPLOAD());
-                    });
-                return collection;
-            });
-    };
-
-export const uploadCollectionFiles = (collectionUuid: string, files: File[]) =>
-    (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
-        dispatch(collectionUploaderActions.START_UPLOAD());
-        return services.collectionService.uploadFiles(collectionUuid, files,
-            (fileId, loaded, total, currentTime) => {
-                dispatch(collectionUploaderActions.SET_UPLOAD_PROGRESS({ fileId, loaded, total, currentTime }));
-            })
-            .then(() => {
-                dispatch(collectionUploaderActions.CLEAR_UPLOAD());
-            });
-    };
-
-export const uploadCurrentCollectionFiles = (files: File[]) =>
-    (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
-        const currentCollection = getState().collectionPanel.item;
-        if (currentCollection) {
-            return dispatch<any>(uploadCollectionFiles(currentCollection.uuid, files));
-        }
+        const newCollection = await services.collectionService.create(collectiontData);
+        await dispatch<any>(uploadCollectionFiles(newCollection.uuid));
+        dispatch(collectionCreateActions.CREATE_COLLECTION_SUCCESS(collection));
+        dispatch(reset('collectionCreateDialog'));
+        return newCollection;
     };
 
 export type CollectionCreateAction = UnionOf<typeof collectionCreateActions>;
diff --git a/src/store/collections/uploader/collection-uploader-actions.ts b/src/store/collections/uploader/collection-uploader-actions.ts
index bc3a0d1..351f3b5 100644
--- a/src/store/collections/uploader/collection-uploader-actions.ts
+++ b/src/store/collections/uploader/collection-uploader-actions.ts
@@ -34,18 +34,14 @@ export const collectionUploaderActions = unionize({
 export type CollectionUploaderAction = UnionOf<typeof collectionUploaderActions>;
 
 export const uploadCollectionFiles = (collectionUuid: string) =>
-    (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
+    async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
         dispatch(collectionUploaderActions.START_UPLOAD());
         const files = getState().collections.uploader.map(file => file.file);
-        return services.collectionService.uploadFiles(collectionUuid, files,
-            (fileId, loaded, total, currentTime) => {
-                dispatch(collectionUploaderActions.SET_UPLOAD_PROGRESS({ fileId, loaded, total, currentTime }));
-            })
-            .then(() => {
-                dispatch(collectionUploaderActions.CLEAR_UPLOAD());
-            });
+        await services.collectionService.uploadFiles(collectionUuid, files, handleUploadProgress(dispatch));
+        dispatch(collectionUploaderActions.CLEAR_UPLOAD());
     };
 
+
 export const uploadCurrentCollectionFiles = () =>
     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
         const currentCollection = getState().collectionPanel.item;
@@ -64,3 +60,7 @@ export const openUploadCollectionFilesDialog = () => (dispatch: Dispatch) => {
 };
 
 export const closeUploadCollectionFilesDialog = () => dialogActions.CLOSE_DIALOG({ id: UPLOAD_COLLECTION_FILES_DIALOG });
+
+const handleUploadProgress = (dispatch: Dispatch) => (fileId: number, loaded: number, total: number, currentTime: number) => {
+    dispatch(collectionUploaderActions.SET_UPLOAD_PROGRESS({ fileId, loaded, total, currentTime }));
+};
\ No newline at end of file

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


hooks/post-receive
-- 




More information about the arvados-commits mailing list