Merge 'origin/master' into 13753-favorites-view
[arvados-workbench2.git] / src / store / context-menu / context-menu-reducer.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { ResourceKind } from "../../models/resource";
6 import { contextMenuActions, ContextMenuAction } from "./context-menu-actions";
7
8 export interface ContextMenuState {
9     open: boolean;
10     position: ContextMenuPosition;
11     resource?: ContextMenuResource;
12 }
13
14 export interface ContextMenuPosition {
15     x: number;
16     y: number;
17 }
18
19 export interface ContextMenuResource {
20     uuid: string;
21     kind: string;
22     name: string;
23 }
24
25 const initialState = {
26     open: false,
27     position: { x: 0, y: 0 }
28 };
29
30 export const contextMenuReducer = (state: ContextMenuState = initialState, action: ContextMenuAction) =>
31     contextMenuActions.match(action, {
32         default: () => state,
33         OPEN_CONTEXT_MENU: ({ resource, position }) => ({ open: true, resource, position }),
34         CLOSE_CONTEXT_MENU: () => ({ ...state, open: false })
35     });
36