X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/1a90c384645ab8880d68abb5dbee1d1193f80538..cc72c29b709759a4498ad232e3f0374e857c7a62:/src/store/context-menu/context-menu-actions.ts?ds=sidebyside diff --git a/src/store/context-menu/context-menu-actions.ts b/src/store/context-menu/context-menu-actions.ts index 40623999..d56a3fb5 100644 --- a/src/store/context-menu/context-menu-actions.ts +++ b/src/store/context-menu/context-menu-actions.ts @@ -3,15 +3,20 @@ // SPDX-License-Identifier: AGPL-3.0 import { unionize, ofType, UnionOf } from '~/common/unionize'; -import { ContextMenuPosition, ContextMenuResource } from "./context-menu-reducer"; +import { ContextMenuPosition } from "./context-menu-reducer"; import { ContextMenuKind } from '~/views-components/context-menu/context-menu'; import { Dispatch } from 'redux'; import { RootState } from '~/store/store'; import { getResource } from '../resources/resources'; import { ProjectResource } from '~/models/project'; -import { UserResource } from '../../models/user'; +import { UserResource } from '~/models/user'; import { isSidePanelTreeCategory } from '~/store/side-panel-tree/side-panel-tree-actions'; import { extractUuidKind, ResourceKind } from '~/models/resource'; +import { Process } from '~/store/processes/process'; +import { RepositoryResource } from '~/models/repositories'; +import { SshKeyResource } from '~/models/ssh-key'; +import { VirtualMachinesResource } from '~/models/virtual-machines'; +import { KeepServiceResource } from '~/models/keep-services'; export const contextMenuActions = unionize({ OPEN_CONTEXT_MENU: ofType<{ position: ContextMenuPosition, resource: ContextMenuResource }>(), @@ -20,37 +25,116 @@ export const contextMenuActions = unionize({ export type ContextMenuAction = UnionOf; -export const openContextMenu = (event: React.MouseEvent, resource: { name: string; uuid: string; description?: string; kind: ContextMenuKind; }) => +export type ContextMenuResource = { + name: string; + uuid: string; + ownerUuid: string; + description?: string; + kind: ResourceKind, + menuKind: ContextMenuKind; + isTrashed?: boolean; + index?: number +}; + +export const isKeyboardClick = (event: React.MouseEvent) => event.nativeEvent.detail === 0; + +export const openContextMenu = (event: React.MouseEvent, resource: ContextMenuResource) => (dispatch: Dispatch) => { event.preventDefault(); + const { left, top } = event.currentTarget.getBoundingClientRect(); dispatch( contextMenuActions.OPEN_CONTEXT_MENU({ - position: { x: event.clientX, y: event.clientY }, + position: { + x: event.clientX || left, + y: event.clientY || top, + }, resource }) ); }; +export const openCollectionFilesContextMenu = (event: React.MouseEvent) => + (dispatch: Dispatch, getState: () => RootState) => { + const isCollectionFileSelected = JSON.stringify(getState().collectionPanelFiles).includes('"selected":true'); + dispatch(openContextMenu(event, { + name: '', + uuid: '', + ownerUuid: '', + kind: ResourceKind.COLLECTION, + menuKind: isCollectionFileSelected ? ContextMenuKind.COLLECTION_FILES : ContextMenuKind.COLLECTION_FILES_NOT_SELECTED + })); + }; + +export const openRepositoryContextMenu = (event: React.MouseEvent, repository: RepositoryResource) => + (dispatch: Dispatch, getState: () => RootState) => { + dispatch(openContextMenu(event, { + name: '', + uuid: repository.uuid, + ownerUuid: repository.ownerUuid, + kind: ResourceKind.REPOSITORY, + menuKind: ContextMenuKind.REPOSITORY + })); + }; + +export const openVirtualMachinesContextMenu = (event: React.MouseEvent, repository: VirtualMachinesResource) => + (dispatch: Dispatch, getState: () => RootState) => { + dispatch(openContextMenu(event, { + name: '', + uuid: repository.uuid, + ownerUuid: repository.ownerUuid, + kind: ResourceKind.VIRTUAL_MACHINE, + menuKind: ContextMenuKind.VIRTUAL_MACHINE + })); + }; + +export const openSshKeyContextMenu = (event: React.MouseEvent, sshKey: SshKeyResource) => + (dispatch: Dispatch) => { + dispatch(openContextMenu(event, { + name: '', + uuid: sshKey.uuid, + ownerUuid: sshKey.ownerUuid, + kind: ResourceKind.SSH_KEY, + menuKind: ContextMenuKind.SSH_KEY + })); + }; + +export const openKeepServiceContextMenu = (event: React.MouseEvent, keepService: KeepServiceResource) => + (dispatch: Dispatch) => { + dispatch(openContextMenu(event, { + name: '', + uuid: keepService.uuid, + ownerUuid: keepService.ownerUuid, + kind: ResourceKind.KEEP_SERVICE, + menuKind: ContextMenuKind.KEEP_SERVICE + })); + }; + export const openRootProjectContextMenu = (event: React.MouseEvent, projectUuid: string) => (dispatch: Dispatch, getState: () => RootState) => { - const userResource = getResource(projectUuid)(getState().resources); - if (userResource) { + const res = getResource(projectUuid)(getState().resources); + if (res) { dispatch(openContextMenu(event, { name: '', - uuid: userResource.uuid, - kind: ContextMenuKind.ROOT_PROJECT + uuid: res.uuid, + ownerUuid: res.uuid, + kind: res.kind, + menuKind: ContextMenuKind.ROOT_PROJECT, + isTrashed: false })); } }; export const openProjectContextMenu = (event: React.MouseEvent, projectUuid: string) => (dispatch: Dispatch, getState: () => RootState) => { - const projectResource = getResource(projectUuid)(getState().resources); - if (projectResource) { + const res = getResource(projectUuid)(getState().resources); + if (res) { dispatch(openContextMenu(event, { - name: projectResource.name, - uuid: projectResource.uuid, - kind: ContextMenuKind.PROJECT + name: res.name, + uuid: res.uuid, + kind: res.kind, + menuKind: ContextMenuKind.PROJECT, + ownerUuid: res.ownerUuid, + isTrashed: res.isTrashed })); } }; @@ -67,6 +151,19 @@ export const openSidePanelContextMenu = (event: React.MouseEvent, i } }; +export const openProcessContextMenu = (event: React.MouseEvent, process: Process) => + (dispatch: Dispatch, getState: () => RootState) => { + const resource = { + uuid: process.containerRequest.uuid, + ownerUuid: process.containerRequest.ownerUuid, + kind: ResourceKind.PROCESS, + name: process.containerRequest.name, + description: process.containerRequest.description, + menuKind: ContextMenuKind.PROCESS + }; + dispatch(openContextMenu(event, resource)); + }; + export const resourceKindToContextMenuKind = (uuid: string) => { const kind = extractUuidKind(uuid); switch (kind) { @@ -74,6 +171,8 @@ export const resourceKindToContextMenuKind = (uuid: string) => { return ContextMenuKind.PROJECT; case ResourceKind.COLLECTION: return ContextMenuKind.COLLECTION_RESOURCE; + case ResourceKind.PROCESS: + return ContextMenuKind.PROCESS_RESOURCE; case ResourceKind.USER: return ContextMenuKind.ROOT_PROJECT; default: