Merge branch '21128-toolbar-context-menu'
[arvados-workbench2.git] / src / views-components / context-menu / action-sets / process-resource-action-set.ts
index 9ea1dc62a75f8a4e18a1f9efcbf4f87b22c9e659..2aa7faa1242369be4ea985bad80805b94529b72f 100644 (file)
@@ -2,9 +2,9 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import { ContextMenuActionSet } from '../context-menu-action-set';
-import { ToggleFavoriteAction } from '../actions/favorite-action';
-import { toggleFavorite } from 'store/favorites/favorites-actions';
+import { ContextMenuActionSet } from "../context-menu-action-set";
+import { ToggleFavoriteAction } from "../actions/favorite-action";
+import { toggleFavorite } from "store/favorites/favorites-actions";
 import {
     RenameIcon,
     ShareIcon,
@@ -15,70 +15,68 @@ import {
     OutputIcon,
     AdvancedIcon,
     OpenIcon,
-} from 'components/icon/icon';
-import { favoritePanelActions } from 'store/favorite-panel/favorite-panel-action';
-import { openMoveProcessDialog } from 'store/processes/process-move-actions';
-import { openProcessUpdateDialog } from 'store/processes/process-update-actions';
-import { openCopyProcessDialog } from 'store/processes/process-copy-actions';
-import { openSharingDialog } from 'store/sharing-dialog/sharing-dialog-actions';
-import { openRemoveProcessDialog } from 'store/processes/processes-actions';
-import { toggleDetailsPanel } from 'store/details-panel/details-panel-action';
-import { navigateToOutput } from 'store/process-panel/process-panel-actions';
-import { openAdvancedTabDialog } from 'store/advanced-tab/advanced-tab';
-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 { openInNewTabAction } from 'store/open-in-new-tab/open-in-new-tab.actions';
+    StopIcon,
+} from "components/icon/icon";
+import { favoritePanelActions } from "store/favorite-panel/favorite-panel-action";
+import { openMoveProcessDialog } from "store/processes/process-move-actions";
+import { openProcessUpdateDialog } from "store/processes/process-update-actions";
+import { openCopyProcessDialog } from "store/processes/process-copy-actions";
+import { openSharingDialog } from "store/sharing-dialog/sharing-dialog-actions";
+import { openRemoveProcessDialog } from "store/processes/processes-actions";
+import { toggleDetailsPanel } from "store/details-panel/details-panel-action";
+import { navigateToOutput } from "store/process-panel/process-panel-actions";
+import { openAdvancedTabDialog } from "store/advanced-tab/advanced-tab";
+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 { openInNewTabAction } from "store/open-in-new-tab/open-in-new-tab.actions";
+import { cancelRunningWorkflow } from "store/processes/processes-actions";
 
 export const readOnlyProcessResourceActionSet: ContextMenuActionSet = [
     [
         {
             component: ToggleFavoriteAction,
             execute: (dispatch, resources) => {
-                resources.forEach((resource) =>
-                    dispatch<any>(toggleFavorite(resource)).then(() => {
-                        dispatch<any>(favoritePanelActions.REQUEST_ITEMS());
-                    })
-                );
+                dispatch<any>(toggleFavorite(resources[0])).then(() => {
+                    dispatch<any>(favoritePanelActions.REQUEST_ITEMS());
+                });
             },
         },
         {
             icon: OpenIcon,
-            name: 'Open in new tab',
+            name: "Open in new tab",
             execute: (dispatch, resources) => {
-                resources.forEach((resource) => dispatch<any>(openInNewTabAction(resource)));
+                dispatch<any>(openInNewTabAction(resources[0]));
             },
         },
         {
             icon: ReRunProcessIcon,
-            name: 'Copy and re-run process',
+            name: "Copy and re-run process",
             execute: (dispatch, resources) => {
-                resources.forEach((resource) => dispatch<any>(openCopyProcessDialog(resource)));
+                dispatch<any>(openCopyProcessDialog(resources[0]));
             },
         },
         {
             icon: OutputIcon,
-            name: 'Outputs',
+            name: "Outputs",
             execute: (dispatch, resources) => {
-                resources.forEach((resource) => {
-                    if (resource.outputUuid) {
-                        dispatch<any>(navigateToOutput(resource.outputUuid));
-                    }
-                });
+                if (resources[0]) {
+                    dispatch<any>(navigateToOutput(resources[0]));
+                }
             },
         },
         {
             icon: DetailsIcon,
-            name: 'View details',
-            execute: (dispatch) => {
+            name: "View details",
+            execute: dispatch => {
                 dispatch<any>(toggleDetailsPanel());
             },
         },
         {
             icon: AdvancedIcon,
-            name: 'API Details',
+            name: "API Details",
             execute: (dispatch, resources) => {
-                resources.forEach((resource) => dispatch<any>(openAdvancedTabDialog(resource.uuid)));
+                dispatch<any>(openAdvancedTabDialog(resources[0].uuid));
             },
         },
     ],
@@ -89,48 +87,72 @@ export const processResourceActionSet: ContextMenuActionSet = [
         ...readOnlyProcessResourceActionSet.reduce((prev, next) => prev.concat(next), []),
         {
             icon: RenameIcon,
-            name: 'Edit process',
+            name: "Edit process",
             execute: (dispatch, resources) => {
-                resources.forEach((resource) => dispatch<any>(openProcessUpdateDialog(resource)));
+                dispatch<any>(openProcessUpdateDialog(resources[0]));
             },
         },
         {
             icon: ShareIcon,
-            name: 'Share',
+            name: "Share",
             execute: (dispatch, resources) => {
-                resources.forEach(({ uuid }) => dispatch<any>(openSharingDialog(uuid)));
+                dispatch<any>(openSharingDialog(resources[0].uuid));
             },
         },
         {
             icon: MoveToIcon,
-            name: 'Move to',
+            name: "Move to",
             execute: (dispatch, resources) => {
-                resources.forEach((resource) => dispatch<any>(openMoveProcessDialog(resource)));
+                dispatch<any>(openMoveProcessDialog(resources[0]));
             },
         },
         {
-            name: 'Remove',
+            name: "Remove",
             icon: RemoveIcon,
             execute: (dispatch, resources) => {
-                resources.forEach((resource) => dispatch<any>(openRemoveProcessDialog(resource.uuid)));
+                dispatch<any>(openRemoveProcessDialog(resources[0], resources.length));
             },
         },
     ],
 ];
 
+const runningProcessOnlyActionSet: ContextMenuActionSet = [
+    [
+        {
+            name: "CANCEL",
+            icon: StopIcon,
+            execute: (dispatch, resources) => {
+                dispatch<any>(cancelRunningWorkflow(resources[0].uuid));
+            },
+        },
+    ]
+];
+
 export const processResourceAdminActionSet: ContextMenuActionSet = [
     [
         ...processResourceActionSet.reduce((prev, next) => prev.concat(next), []),
         {
             component: TogglePublicFavoriteAction,
-            name: 'Add to public favorites',
+            name: "Add to public favorites",
             execute: (dispatch, resources) => {
-                resources.forEach((resource) =>
-                    dispatch<any>(togglePublicFavorite(resource)).then(() => {
-                        dispatch<any>(publicFavoritePanelActions.REQUEST_ITEMS());
-                    })
-                );
+                dispatch<any>(togglePublicFavorite(resources[0])).then(() => {
+                    dispatch<any>(publicFavoritePanelActions.REQUEST_ITEMS());
+                });
             },
         },
     ],
 ];
+
+export const runningProcessResourceActionSet = [
+    [
+        ...processResourceActionSet.reduce((prev, next) => prev.concat(next), []),
+        ...runningProcessOnlyActionSet.reduce((prev, next) => prev.concat(next), []),
+    ],
+];
+
+export const runningProcessResourceAdminActionSet: ContextMenuActionSet = [
+    [
+        ...processResourceAdminActionSet.reduce((prev, next) => prev.concat(next), []),
+        ...runningProcessOnlyActionSet.reduce((prev, next) => prev.concat(next), []),
+    ],
+];