Merge 'main' into 20382-process-action-menu-cancel
[arvados-workbench2.git] / src / store / context-menu / context-menu-actions.ts
index dc35ab68394587aae03289f1db9269d4b77b597f..4cad2962f0f85125260c95ad36dbdf923376f021 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;
@@ -68,6 +71,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 +80,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,
             })
         );
     };
@@ -313,7 +323,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;
         }