refs #master Merge branch 'origin/master' into 13901-services-repo
[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 }
23
24 const initialState = {
25     open: false,
26     position: { x: 0, y: 0 }
27 };
28
29 export const contextMenuReducer = (state: ContextMenuState = initialState, action: ContextMenuAction) =>
30     contextMenuActions.match(action, {
31         default: () => state,
32         OPEN_CONTEXT_MENU: ({ resource, position }) => ({ open: true, resource, position }),
33         CLOSE_CONTEXT_MENU: () => ({ ...state, open: false })
34     });
35