Merge branch 'master' into 13992-creating-a-collection-within-a-project-does-not...
[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 { contextMenuActions, ContextMenuAction } from "./context-menu-actions";
6
7 export interface ContextMenuState {
8     open: boolean;
9     position: ContextMenuPosition;
10     resource?: ContextMenuResource;
11 }
12
13 export interface ContextMenuPosition {
14     x: number;
15     y: number;
16 }
17
18 export interface ContextMenuResource {
19     uuid: string;
20     kind: string;
21     name: string;
22     description?: 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