Merge branch 'master' into 14098-log-view
[arvados.git] / src / store / context-menu / context-menu-actions.ts
index 26e25c3df3a6db4511f39b126667d4321d2b8b6e..3440a3053dad930dd1db230e0b52e9100e690935 100644 (file)
@@ -12,6 +12,7 @@ import { ProjectResource } from '~/models/project';
 import { UserResource } from '../../models/user';
 import { isSidePanelTreeCategory } from '~/store/side-panel-tree/side-panel-tree-actions';
 import { extractUuidKind, ResourceKind } from '~/models/resource';
+import { matchProcessRoute } from '~/routes/routes';
 
 export const contextMenuActions = unionize({
     OPEN_CONTEXT_MENU: ofType<{ position: ContextMenuPosition, resource: ContextMenuResource }>(),
@@ -66,3 +67,35 @@ export const openSidePanelContextMenu = (event: React.MouseEvent<HTMLElement>, i
             }
         }
     };
+
+export const openProcessContextMenu = (event: React.MouseEvent<HTMLElement>) =>
+    (dispatch: Dispatch, getState: () => RootState) => {
+        const { location } = getState().router;
+        const pathname = location ? location.pathname : '';
+        // ToDo: We get error from matchProcessRoute
+        // const match = matchProcessRoute(pathname); 
+        // console.log('match: ', match);
+        // const uuid = match ? match.params.id : '';
+        const uuid = pathname.split('/').slice(-1)[0];
+        const resource = {
+            uuid,
+            name: '',
+            description: '',
+            kind: ContextMenuKind.PROCESS
+        };
+        dispatch<any>(openContextMenu(event, resource));
+    };
+
+export const resourceKindToContextMenuKind = (uuid: string) => {
+    const kind = extractUuidKind(uuid);
+    switch (kind) {
+        case ResourceKind.PROJECT:
+            return ContextMenuKind.PROJECT;
+        case ResourceKind.COLLECTION:
+            return ContextMenuKind.COLLECTION_RESOURCE;
+        case ResourceKind.USER:
+            return ContextMenuKind.ROOT_PROJECT;
+        default:
+            return;
+    }
+};