15768: made new dialog for multi-copy Arvados-DCO-1.1-Signed-off-by: Lisa Knox <lisa...
[arvados.git] / src / views-components / context-menu / action-sets / collection-action-set.ts
index 5b170f6707b7b697fe0e21df6a793ac04b7c4e36..c63144e8b96316c6ade88855fcf7d2d36b80c354 100644 (file)
@@ -2,9 +2,9 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import { ContextMenuAction, ContextMenuActionSet } from '../context-menu-action-set';
-import { ToggleFavoriteAction } from '../actions/favorite-action';
-import { toggleFavorite } from 'store/favorites/favorites-actions';
+import { ContextMenuAction, ContextMenuActionSet } from "../context-menu-action-set";
+import { ToggleFavoriteAction } from "../actions/favorite-action";
+import { toggleFavorite } from "store/favorites/favorites-actions";
 import {
     RenameIcon,
     ShareIcon,
@@ -16,30 +16,33 @@ import {
     Link,
     RestoreVersionIcon,
     FolderSharedIcon,
-} from 'components/icon/icon';
-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 { openWebDavS3InfoDialog } from 'store/collections/collection-info-actions';
-import { ToggleTrashAction } from 'views-components/context-menu/actions/trash-action';
-import { toggleCollectionTrashed } from 'store/trash/trash-actions';
-import { openSharingDialog } from 'store/sharing-dialog/sharing-dialog-actions';
-import { openAdvancedTabDialog } from 'store/advanced-tab/advanced-tab';
-import { toggleDetailsPanel } from 'store/details-panel/details-panel-action';
-import { copyToClipboardAction, openInNewTabAction } from 'store/open-in-new-tab/open-in-new-tab.actions';
-import { openRestoreCollectionVersionDialog } from 'store/collections/collection-version-actions';
-import { TogglePublicFavoriteAction } from '../actions/public-favorite-action';
-import { togglePublicFavorite } from 'store/public-favorites/public-favorites-actions';
-import { publicFavoritePanelActions } from 'store/public-favorites-panel/public-favorites-action';
+} from "components/icon/icon";
+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, 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";
+import { openSharingDialog } from "store/sharing-dialog/sharing-dialog-actions";
+import { openAdvancedTabDialog } from "store/advanced-tab/advanced-tab";
+import { toggleDetailsPanel } from "store/details-panel/details-panel-action";
+import { copyToClipboardAction, openInNewTabAction } from "store/open-in-new-tab/open-in-new-tab.actions";
+import { openRestoreCollectionVersionDialog } from "store/collections/collection-version-actions";
+import { TogglePublicFavoriteAction } from "../actions/public-favorite-action";
+import { togglePublicFavorite } from "store/public-favorites/public-favorites-actions";
+import { publicFavoritePanelActions } from "store/public-favorites-panel/public-favorites-action";
+import { ContextMenuResource } from "store/context-menu/context-menu-actions";
 
 const toggleFavoriteAction: ContextMenuAction = {
     component: ToggleFavoriteAction,
-    name: 'ToggleFavoriteAction',
-    execute: (dispatch, resource) => {
-        dispatch<any>(toggleFavorite(resource)).then(() => {
-            dispatch<any>(favoritePanelActions.REQUEST_ITEMS());
-        });
+    name: "ToggleFavoriteAction",
+    execute: (dispatch, resources) => {
+        resources.forEach(resource =>
+            dispatch<any>(toggleFavorite(resource)).then(() => {
+                dispatch<any>(favoritePanelActions.REQUEST_ITEMS());
+            })
+        );
     },
 };
 
@@ -47,37 +50,38 @@ const commonActionSet: ContextMenuActionSet = [
     [
         {
             icon: OpenIcon,
-            name: 'Open in new tab',
-            execute: (dispatch, resource) => {
-                dispatch<any>(openInNewTabAction(resource));
+            name: "Open in new tab",
+            execute: (dispatch, resources) => {
+                dispatch<any>(openInNewTabAction(resources[0]));
             },
         },
         {
             icon: Link,
-            name: 'Copy to clipboard',
-            execute: (dispatch, resource) => {
-                dispatch<any>(copyToClipboardAction(resource));
+            name: "Copy to clipboard",
+            execute: (dispatch, resources) => {
+                dispatch<any>(copyToClipboardAction(resources));
             },
         },
         {
             icon: CopyIcon,
-            name: 'Make a copy',
-            execute: (dispatch, resource) => {
-                dispatch<any>(openCollectionCopyDialog(resource));
+            name: "Make a copy",
+            execute: (dispatch, resources) => {
+                if (resources[0].isSingle) dispatch<any>(openCollectionCopyDialog(resources[0]));
+                else dispatch<any>(openMultiCollectionCopyDialog(resources[0]));
             },
         },
         {
             icon: DetailsIcon,
-            name: 'View details',
-            execute: (dispatch) => {
+            name: "View details",
+            execute: dispatch => {
                 dispatch<any>(toggleDetailsPanel());
             },
         },
         {
             icon: AdvancedIcon,
-            name: 'API Details',
-            execute: (dispatch, resource) => {
-                dispatch<any>(openAdvancedTabDialog(resource.uuid));
+            name: "API Details",
+            execute: (dispatch, resources) => {
+                resources.forEach(resource => dispatch<any>(openAdvancedTabDialog(resource.uuid)));
             },
         },
     ],
@@ -89,9 +93,9 @@ export const readOnlyCollectionActionSet: ContextMenuActionSet = [
         toggleFavoriteAction,
         {
             icon: FolderSharedIcon,
-            name: 'Open with 3rd party client',
-            execute: (dispatch, resource) => {
-                dispatch<any>(openWebDavS3InfoDialog(resource.uuid));
+            name: "Open with 3rd party client",
+            execute: (dispatch, resources) => {
+                resources.forEach(resource => dispatch<any>(openWebDavS3InfoDialog(resource.uuid)));
             },
         },
     ],
@@ -102,28 +106,28 @@ export const collectionActionSet: ContextMenuActionSet = [
         ...readOnlyCollectionActionSet.reduce((prev, next) => prev.concat(next), []),
         {
             icon: RenameIcon,
-            name: 'Edit collection',
-            execute: (dispatch, resource) => {
-                dispatch<any>(openCollectionUpdateDialog(resource));
+            name: "Edit collection",
+            execute: (dispatch, resources) => {
+                resources.forEach(resource => dispatch<any>(openCollectionUpdateDialog(resource)));
             },
         },
         {
             icon: ShareIcon,
-            name: 'Share',
-            execute: (dispatch, { uuid }) => {
-                dispatch<any>(openSharingDialog(uuid));
+            name: "Share",
+            execute: (dispatch, resources) => {
+                resources.forEach(({ uuid }) => dispatch<any>(openSharingDialog(uuid)));
             },
         },
         {
             icon: MoveToIcon,
-            name: 'Move to',
-            execute: (dispatch, resource) => dispatch<any>(openMoveCollectionDialog(resource)),
+            name: "Move to",
+            execute: (dispatch, resources) => dispatch<any>(openMoveCollectionDialog(resources[0])),
         },
         {
             component: ToggleTrashAction,
-            name: 'ToggleTrashAction',
-            execute: (dispatch, resource) => {
-                dispatch<any>(toggleCollectionTrashed(resource.uuid, resource.isTrashed!!));
+            name: "ToggleTrashAction",
+            execute: (dispatch, resources: ContextMenuResource[]) => {
+                resources.forEach(resource => dispatch<any>(toggleCollectionTrashed(resource.uuid, resource.isTrashed!!)));
             },
         },
     ],
@@ -134,11 +138,13 @@ export const collectionAdminActionSet: ContextMenuActionSet = [
         ...collectionActionSet.reduce((prev, next) => prev.concat(next), []),
         {
             component: TogglePublicFavoriteAction,
-            name: 'TogglePublicFavoriteAction',
-            execute: (dispatch, resource) => {
-                dispatch<any>(togglePublicFavorite(resource)).then(() => {
-                    dispatch<any>(publicFavoritePanelActions.REQUEST_ITEMS());
-                });
+            name: "TogglePublicFavoriteAction",
+            execute: (dispatch, resources) => {
+                resources.forEach(resource =>
+                    dispatch<any>(togglePublicFavorite(resource)).then(() => {
+                        dispatch<any>(publicFavoritePanelActions.REQUEST_ITEMS());
+                    })
+                );
             },
         },
     ],
@@ -149,9 +155,9 @@ export const oldCollectionVersionActionSet: ContextMenuActionSet = [
         ...commonActionSet.reduce((prev, next) => prev.concat(next), []),
         {
             icon: RestoreVersionIcon,
-            name: 'Restore version',
-            execute: (dispatch, { uuid }) => {
-                dispatch<any>(openRestoreCollectionVersionDialog(uuid));
+            name: "Restore version",
+            execute: (dispatch, resources) => {
+                resources.forEach(({ uuid }) => dispatch<any>(openRestoreCollectionVersionDialog(uuid)));
             },
         },
     ],