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 }>(),
isFrozen?: boolean;
storageClassesDesired?: string[];
properties?: { [key: string]: string | string[] };
+ isMulti?: boolean;
+ fromContextMenu?: boolean;
};
export const isKeyboardClick = (event: React.MouseEvent<HTMLElement>) => event.nativeEvent.detail === 0;
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: "",
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,
})
);
};
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) {
case ResourceKind.LINK:
return ContextMenuKind.LINK;
case ResourceKind.WORKFLOW:
- return ContextMenuKind.WORKFLOW;
+ return isEditable ? ContextMenuKind.WORKFLOW : ContextMenuKind.READONLY_WORKFLOW;
default:
return;
}