Merge branch '21128-toolbar-context-menu'
[arvados-workbench2.git] / src / views-components / context-menu / action-sets / collection-action-set.ts
index c93d585990f1c048eab7940acb939c6081c8e74e..95aec9c7c94f476be3de1aa2f595040211b8d6b6 100644 (file)
@@ -20,7 +20,7 @@ import {
 import { openCollectionUpdateDialog } from "store/collections/collection-update-actions";
 import { favoritePanelActions } from "store/favorite-panel/favorite-panel-action";
 import { openMoveCollectionDialog } from "store/collections/collection-move-actions";
-import { openCollectionCopyDialog } from "store/collections/collection-copy-actions";
+import { openCollectionCopyDialog, openMultiCollectionCopyDialog } from "store/collections/collection-copy-actions";
 import { openWebDavS3InfoDialog } from "store/collections/collection-info-actions";
 import { ToggleTrashAction } from "views-components/context-menu/actions/trash-action";
 import { toggleCollectionTrashed } from "store/trash/trash-actions";
@@ -38,21 +38,20 @@ const toggleFavoriteAction: ContextMenuAction = {
     component: ToggleFavoriteAction,
     name: "ToggleFavoriteAction",
     execute: (dispatch, resources) => {
-        resources.forEach(resource =>
+        for (const resource of [...resources]) {
             dispatch<any>(toggleFavorite(resource)).then(() => {
                 dispatch<any>(favoritePanelActions.REQUEST_ITEMS());
-            })
-        );
+            });
+        }
     },
 };
-
 const commonActionSet: ContextMenuActionSet = [
     [
         {
             icon: OpenIcon,
             name: "Open in new tab",
-            execute: (dispatch, resource) => {
-                dispatch<any>(openInNewTabAction(resource));
+            execute: (dispatch, resources) => {
+                dispatch<any>(openInNewTabAction(resources[0]));
             },
         },
         {
@@ -66,7 +65,8 @@ const commonActionSet: ContextMenuActionSet = [
             icon: CopyIcon,
             name: "Make a copy",
             execute: (dispatch, resources) => {
-                resources.forEach(resource => dispatch<any>(openCollectionCopyDialog(resource)));
+                if (resources[0].fromContextMenu || resources.length === 1) dispatch<any>(openCollectionCopyDialog(resources[0]));
+                else dispatch<any>(openMultiCollectionCopyDialog(resources[0]));
             },
         },
         {
@@ -80,7 +80,7 @@ const commonActionSet: ContextMenuActionSet = [
             icon: AdvancedIcon,
             name: "API Details",
             execute: (dispatch, resources) => {
-                resources.forEach(resource => dispatch<any>(openAdvancedTabDialog(resource.uuid)));
+                dispatch<any>(openAdvancedTabDialog(resources[0].uuid));
             },
         },
     ],
@@ -94,7 +94,7 @@ export const readOnlyCollectionActionSet: ContextMenuActionSet = [
             icon: FolderSharedIcon,
             name: "Open with 3rd party client",
             execute: (dispatch, resources) => {
-                resources.forEach(resource => dispatch<any>(openWebDavS3InfoDialog(resource.uuid)));
+                dispatch<any>(openWebDavS3InfoDialog(resources[0].uuid));
             },
         },
     ],
@@ -107,14 +107,14 @@ export const collectionActionSet: ContextMenuActionSet = [
             icon: RenameIcon,
             name: "Edit collection",
             execute: (dispatch, resources) => {
-                resources.forEach(resource => dispatch<any>(openCollectionUpdateDialog(resource)));
+                dispatch<any>(openCollectionUpdateDialog(resources[0]));
             },
         },
         {
             icon: ShareIcon,
             name: "Share",
             execute: (dispatch, resources) => {
-                resources.forEach(({ uuid }) => dispatch<any>(openSharingDialog(uuid)));
+                dispatch<any>(openSharingDialog(resources[0].uuid));
             },
         },
         {
@@ -126,7 +126,9 @@ export const collectionActionSet: ContextMenuActionSet = [
             component: ToggleTrashAction,
             name: "ToggleTrashAction",
             execute: (dispatch, resources: ContextMenuResource[]) => {
-                resources.forEach(resource => dispatch<any>(toggleCollectionTrashed(resource.uuid, resource.isTrashed!!)));
+                for (const resource of [...resources]) {
+                    dispatch<any>(toggleCollectionTrashed(resource.uuid, resource.isTrashed!!));
+                }
             },
         },
     ],
@@ -139,11 +141,11 @@ export const collectionAdminActionSet: ContextMenuActionSet = [
             component: TogglePublicFavoriteAction,
             name: "TogglePublicFavoriteAction",
             execute: (dispatch, resources) => {
-                resources.forEach(resource =>
+                for (const resource of [...resources]) {
                     dispatch<any>(togglePublicFavorite(resource)).then(() => {
                         dispatch<any>(publicFavoritePanelActions.REQUEST_ITEMS());
-                    })
-                );
+                    });
+                }
             },
         },
     ],
@@ -156,7 +158,9 @@ export const oldCollectionVersionActionSet: ContextMenuActionSet = [
             icon: RestoreVersionIcon,
             name: "Restore version",
             execute: (dispatch, resources) => {
-                resources.forEach(({ uuid }) => dispatch<any>(openRestoreCollectionVersionDialog(uuid)));
+                for (const resource of [...resources]) {
+                    dispatch<any>(openRestoreCollectionVersionDialog(resource.uuid));
+                }
             },
         },
     ],