Merge branch '17426-plug-ins' refs #17426
[arvados-workbench2.git] / src / store / context-menu / context-menu-reducer.ts
index 9a825a5ff7626060b4372c2012f3618d080a4807..03d9cc7843a8df8e5f068a74274d0d6cb7a682e0 100644 (file)
@@ -2,31 +2,28 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-// import actions, { DetailsPanelAction } from "./details-panel-action";
-// import { Resource, ResourceKind } from "../../models/resource";
+import { contextMenuActions, ContextMenuAction, ContextMenuResource } from "./context-menu-actions";
 
-// export interface ContextMenuState {
-//     position: {
-//         x: number;
-//         y: number;
-//     },
-//     resource: {
-//         uuid: string;
-//         kind: ResourceKind.
-//     }
-// }
+export interface ContextMenuState {
+    open: boolean;
+    position: ContextMenuPosition;
+    resource?: ContextMenuResource;
+}
 
-// const initialState = {
-//     item: null,
-//     isOpened: false
-// };
+export interface ContextMenuPosition {
+    x: number;
+    y: number;
+}
 
-// const reducer = (state: DetailsPanelState = initialState, action: DetailsPanelAction) =>
-//     actions.match(action, {
-//         default: () => state,
-//         LOAD_DETAILS: () => state,
-//         LOAD_DETAILS_SUCCESS: ({ item }) => ({ ...state, item }),
-//         TOGGLE_DETAILS_PANEL: () => ({ ...state, isOpened: !state.isOpened })
-//     });
+const initialState = {
+    open: false,
+    position: { x: 0, y: 0 }
+};
+
+export const contextMenuReducer = (state: ContextMenuState = initialState, action: ContextMenuAction) =>
+    contextMenuActions.match(action, {
+        default: () => state,
+        OPEN_CONTEXT_MENU: ({ resource, position }) => ({ open: true, resource, position }),
+        CLOSE_CONTEXT_MENU: () => ({ ...state, open: false })
+    });
 
-// export default reducer;