Merge branch '21128-toolbar-context-menu'
[arvados-workbench2.git] / src / store / context-menu / context-menu-actions.ts
index dc35ab68394587aae03289f1db9269d4b77b597f..464314877ff645328d838f2ddbbb1e4cd2a99ec7 100644 (file)
@@ -24,6 +24,7 @@ import { LinkResource } from "models/link";
 import { resourceIsFrozen } from "common/frozen-resources";
 import { ProjectResource } from "models/project";
 import { getProcess } from "store/processes/process";
+import { filterCollectionFilesBySelection } from "store/collection-panel/collection-panel-files/collection-panel-files-state";
 
 export const contextMenuActions = unionize({
     OPEN_CONTEXT_MENU: ofType<{ position: ContextMenuPosition; resource: ContextMenuResource }>(),
@@ -47,6 +48,8 @@ export type ContextMenuResource = {
     isFrozen?: boolean;
     storageClassesDesired?: string[];
     properties?: { [key: string]: string | string[] };
+    isMulti?: boolean;
+    fromContextMenu?: boolean;
 };
 
 export const isKeyboardClick = (event: React.MouseEvent<HTMLElement>) => event.nativeEvent.detail === 0;
@@ -67,7 +70,8 @@ export const openContextMenu = (event: React.MouseEvent<HTMLElement>, resource:
 
 export const openCollectionFilesContextMenu =
     (event: React.MouseEvent<HTMLElement>, isWritable: boolean) => (dispatch: Dispatch, getState: () => RootState) => {
-        const isCollectionFileSelected = JSON.stringify(getState().collectionPanelFiles).includes('"selected":true');
+        const selectedCount = filterCollectionFilesBySelection(getState().collectionPanelFiles, true).length;
+        const multiple = selectedCount > 1;
         dispatch<any>(
             openContextMenu(event, {
                 name: "",
@@ -75,11 +79,16 @@ export const openCollectionFilesContextMenu =
                 ownerUuid: "",
                 description: "",
                 kind: ResourceKind.COLLECTION,
-                menuKind: isCollectionFileSelected
-                    ? isWritable
-                        ? ContextMenuKind.COLLECTION_FILES
-                        : ContextMenuKind.READONLY_COLLECTION_FILES
-                    : ContextMenuKind.COLLECTION_FILES_NOT_SELECTED,
+                menuKind:
+                    selectedCount > 0
+                        ? isWritable
+                            ? multiple
+                                ? ContextMenuKind.COLLECTION_FILES_MULTIPLE
+                                : ContextMenuKind.COLLECTION_FILES
+                            : multiple
+                            ? ContextMenuKind.READONLY_COLLECTION_FILES_MULTIPLE
+                            : ContextMenuKind.READONLY_COLLECTION_FILES
+                        : ContextMenuKind.COLLECTION_FILES_NOT_SELECTED,
             })
         );
     };
@@ -206,31 +215,12 @@ export const openProcessContextMenu = (event: React.MouseEvent<HTMLElement>, pro
                 description: res.description,
                 outputUuid: res.outputUuid || "",
                 workflowUuid: res.properties.template_uuid || "",
-                menuKind: ContextMenuKind.PROCESS_RESOURCE,
+                menuKind: isProcessCancelable(process) ? ContextMenuKind.RUNNING_PROCESS_RESOURCE : ContextMenuKind.PROCESS_RESOURCE
             })
         );
     }
 };
 
-export const openRunningProcessContextMenu =
-    (event: React.MouseEvent<HTMLElement>, process: Process) => (dispatch: Dispatch, getState: () => RootState) => {
-        const res = getResource<ProcessResource>(process.containerRequest.uuid)(getState().resources);
-        if (res) {
-            dispatch<any>(
-                openContextMenu(event, {
-                    uuid: res.uuid,
-                    ownerUuid: res.ownerUuid,
-                    kind: ResourceKind.PROCESS,
-                    name: res.name,
-                    description: res.description,
-                    outputUuid: res.outputUuid || "",
-                    workflowUuid: res.properties.template_uuid || "",
-                    menuKind: ContextMenuKind.RUNNING_PROCESS_RESOURCE,
-                })
-            );
-        }
-    };
-
 export const openPermissionEditContextMenu =
     (event: React.MouseEvent<HTMLElement>, link: LinkResource) => (dispatch: Dispatch, getState: () => RootState) => {
         if (link) {
@@ -313,7 +303,7 @@ export const resourceUuidToContextMenuKind =
             case ResourceKind.LINK:
                 return ContextMenuKind.LINK;
             case ResourceKind.WORKFLOW:
-                return ContextMenuKind.WORKFLOW;
+                return isEditable ? ContextMenuKind.WORKFLOW : ContextMenuKind.READONLY_WORKFLOW;
             default:
                 return;
         }