15768: multimove collections works Arvados-DCO-1.1-Signed-off-by: Lisa Knox <lisa...
authorLisa Knox <lisaknox83@gmail.com>
Mon, 28 Aug 2023 18:24:08 +0000 (14:24 -0400)
committerLisa Knox <lisaknox83@gmail.com>
Mon, 28 Aug 2023 18:24:08 +0000 (14:24 -0400)
src/store/workbench/workbench-actions.ts

index 9b928ce30d03f6859a92189fd00bddeef0221ea0..4d717c483977390d5f7e8bab92e6ffef4aca8e5e 100644 (file)
@@ -289,7 +289,7 @@ export const moveProject = (data: MoveToFormDialogData) => async (dispatch: Disp
         await moveSingleProject(uuid);
     }
 
-    async function moveSingleProject(uuid) {
+    async function moveSingleProject(uuid: string) {
         const originalItem = getResource(uuid)(getState().resources) as Resource & { name: string };
         if (originalItem.kind === ResourceKind.PROJECT) {
             try {
@@ -435,25 +435,39 @@ export const copyCollection = (data: CopyFormDialogData) => async (dispatch: Dis
 };
 
 export const moveCollection = (data: MoveToFormDialogData) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
-    try {
-        const collection = await dispatch<any>(collectionMoveActions.moveCollection(data));
-        dispatch<any>(updateResources([collection]));
-        dispatch<any>(reloadProjectMatchingUuid([collection.ownerUuid]));
-        dispatch(
-            snackbarActions.OPEN_SNACKBAR({
-                message: "Collection has been moved.",
-                hideDuration: 2000,
-                kind: SnackbarKind.SUCCESS,
-            })
-        );
-    } catch (e) {
-        dispatch(
-            snackbarActions.OPEN_SNACKBAR({
-                message: e.message,
-                hideDuration: 2000,
-                kind: SnackbarKind.ERROR,
-            })
-        );
+    const itemsToMove: string[] = selectedToArray(getState().multiselect.checkedList);
+    //if no items in checkedlist, default to normal context menu behavior
+    if (!itemsToMove.length) itemsToMove.push(data.uuid);
+
+    for (const uuid of itemsToMove) {
+        await moveSingleCollection(uuid);
+    }
+
+    async function moveSingleCollection(uuid: string) {
+        const originalItem = getResource(uuid)(getState().resources) as Resource & { name: string };
+        if (originalItem.kind === ResourceKind.COLLECTION) {
+            try {
+                const oldCollection: MoveToFormDialogData = { name: originalItem.name, uuid: originalItem.uuid, ownerUuid: data.ownerUuid };
+                const collection = await dispatch<any>(collectionMoveActions.moveCollection(oldCollection));
+                dispatch<any>(updateResources([collection]));
+                dispatch<any>(reloadProjectMatchingUuid([collection.ownerUuid]));
+                dispatch(
+                    snackbarActions.OPEN_SNACKBAR({
+                        message: "Collection has been moved.",
+                        hideDuration: 2000,
+                        kind: SnackbarKind.SUCCESS,
+                    })
+                );
+            } catch (e) {
+                dispatch(
+                    snackbarActions.OPEN_SNACKBAR({
+                        message: e.message,
+                        hideDuration: 2000,
+                        kind: SnackbarKind.ERROR,
+                    })
+                );
+            }
+        }
     }
 };
 
@@ -536,7 +550,7 @@ export const moveProcess = (data: MoveToFormDialogData) => async (dispatch: Disp
         await moveSingleProcess(uuid);
     }
 
-    async function moveSingleProcess(uuid) {
+    async function moveSingleProcess(uuid: string) {
         const originalItem = getResource(uuid)(getState().resources) as Resource & { name: string };
         if (originalItem.kind === ResourceKind.PROCESS) {
             try {