14096-move-to-process
[arvados-workbench2.git] / src / routes / routes.ts
index 20dd1359b34b626f66ab3b0de959e85a2c28b38f..29941b47e89989cec2417e653c8364fa5b3a21f7 100644 (file)
@@ -2,14 +2,10 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import { History, Location } from 'history';
-import { RootStore } from '~/store/store';
 import { matchPath } from 'react-router';
 import { ResourceKind, RESOURCE_UUID_PATTERN, extractUuidKind } from '~/models/resource';
-import { getProjectUrl } from '../models/project';
+import { getProjectUrl } from '~/models/project';
 import { getCollectionUrl } from '~/models/collection';
-import { loadProject, loadFavorites, loadCollection } from '~/store/workbench/workbench-actions';
-import { loadProcess } from '~/store/processes/processes-actions';
 
 export const Routes = {
     ROOT: '/',
@@ -18,6 +14,8 @@ export const Routes = {
     COLLECTIONS: `/collections/:id(${RESOURCE_UUID_PATTERN})`,
     PROCESSES: `/processes/:id(${RESOURCE_UUID_PATTERN})`,
     FAVORITES: '/favorites',
+    TRASH: '/trash',
+    PROCESS_LOGS: `/process-logs/:id(${RESOURCE_UUID_PATTERN})`
 };
 
 export const getResourceUrl = (uuid: string) => {
@@ -27,6 +25,8 @@ export const getResourceUrl = (uuid: string) => {
             return getProjectUrl(uuid);
         case ResourceKind.COLLECTION:
             return getCollectionUrl(uuid);
+        case ResourceKind.PROCESS:
+            return getProcessUrl(uuid);
         default:
             return undefined;
     }
@@ -34,11 +34,11 @@ export const getResourceUrl = (uuid: string) => {
 
 export const getProcessUrl = (uuid: string) => `/processes/${uuid}`;
 
-export const addRouteChangeHandlers = (history: History, store: RootStore) => {
-    const handler = handleLocationChange(store);
-    handler(history.location);
-    history.listen(handler);
-};
+export const getProcessLogUrl = (uuid: string) => `/process-logs/${uuid}`;
+
+export interface ResourceRouteParams {
+    id: string;
+}
 
 export const matchRootRoute = (route: string) =>
     matchPath(route, { path: Routes.ROOT, exact: true });
@@ -46,9 +46,8 @@ export const matchRootRoute = (route: string) =>
 export const matchFavoritesRoute = (route: string) =>
     matchPath(route, { path: Routes.FAVORITES });
 
-export interface ResourceRouteParams {
-    id: string;
-}
+export const matchTrashRoute = (route: string) =>
+    matchPath(route, { path: Routes.TRASH });
 
 export const matchProjectRoute = (route: string) =>
     matchPath<ResourceRouteParams>(route, { path: Routes.PROJECTS });
@@ -59,19 +58,5 @@ export const matchCollectionRoute = (route: string) =>
 export const matchProcessRoute = (route: string) =>
     matchPath<ResourceRouteParams>(route, { path: Routes.PROCESSES });
 
-
-const handleLocationChange = (store: RootStore) => ({ pathname }: Location) => {
-    const projectMatch = matchProjectRoute(pathname);
-    const collectionMatch = matchCollectionRoute(pathname);
-    const favoriteMatch = matchFavoritesRoute(pathname);
-    const processMatch = matchProcessRoute(pathname);
-    if (projectMatch) {
-        store.dispatch(loadProject(projectMatch.params.id));
-    } else if (collectionMatch) {
-        store.dispatch(loadCollection(collectionMatch.params.id));
-    } else if (favoriteMatch) {
-        store.dispatch(loadFavorites());
-    } else if (processMatch) {
-        store.dispatch(loadProcess(processMatch.params.id));
-    }
-};
+export const matchProcessLogRoute = (route: string) =>
+    matchPath<ResourceRouteParams>(route, { path: Routes.PROCESS_LOGS });