Extract major components from workbench
[arvados-workbench2.git] / src / store / context-menu / context-menu-actions.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { unionize, ofType, UnionOf } from '~/common/unionize';
6 import { ContextMenuPosition, ContextMenuResource } from "./context-menu-reducer";
7 import { ContextMenuKind } from '~/views-components/context-menu/context-menu';
8 import { Dispatch } from 'redux';
9
10 export const contextMenuActions = unionize({
11     OPEN_CONTEXT_MENU: ofType<{ position: ContextMenuPosition, resource: ContextMenuResource }>(),
12     CLOSE_CONTEXT_MENU: ofType<{}>()
13 });
14
15 export type ContextMenuAction = UnionOf<typeof contextMenuActions>;
16
17 export const openContextMenu = (event: React.MouseEvent<HTMLElement>, resource: { name: string; uuid: string; description?: string; kind: ContextMenuKind; }) =>
18     (dispatch: Dispatch) => {
19         event.preventDefault();
20         dispatch(
21             contextMenuActions.OPEN_CONTEXT_MENU({
22                 position: { x: event.clientX, y: event.clientY },
23                 resource
24             })
25         );
26     };