Merge branch 'master' into 14225-prepare-structure-and-init-stepper
[arvados-workbench2.git] / src / routes / routes.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { matchPath } from 'react-router';
6 import { ResourceKind, RESOURCE_UUID_PATTERN, extractUuidKind } from '~/models/resource';
7 import { getProjectUrl } from '~/models/project';
8 import { getCollectionUrl } from '~/models/collection';
9
10 export const Routes = {
11     ROOT: '/',
12     TOKEN: '/token',
13     PROJECTS: `/projects/:id(${RESOURCE_UUID_PATTERN})`,
14     COLLECTIONS: `/collections/:id(${RESOURCE_UUID_PATTERN})`,
15     PROCESSES: `/processes/:id(${RESOURCE_UUID_PATTERN})`,
16     FAVORITES: '/favorites',
17     TRASH: '/trash',
18     PROCESS_LOGS: `/process-logs/:id(${RESOURCE_UUID_PATTERN})`,
19     SHARED_WITH_ME: '/shared-with-me',
20     RUN_PROCESS: '/run-process',
21     WORKFLOWS: '/workflows'
22 };
23
24 export const getResourceUrl = (uuid: string) => {
25     const kind = extractUuidKind(uuid);
26     switch (kind) {
27         case ResourceKind.PROJECT:
28             return getProjectUrl(uuid);
29         case ResourceKind.COLLECTION:
30             return getCollectionUrl(uuid);
31         case ResourceKind.PROCESS:
32             return getProcessUrl(uuid);
33         default:
34             return undefined;
35     }
36 };
37
38 export const getProcessUrl = (uuid: string) => `/processes/${uuid}`;
39
40 export const getProcessLogUrl = (uuid: string) => `/process-logs/${uuid}`;
41
42 export interface ResourceRouteParams {
43     id: string;
44 }
45
46 export const matchRootRoute = (route: string) =>
47     matchPath(route, { path: Routes.ROOT, exact: true });
48
49 export const matchFavoritesRoute = (route: string) =>
50     matchPath(route, { path: Routes.FAVORITES });
51
52 export const matchTrashRoute = (route: string) =>
53     matchPath(route, { path: Routes.TRASH });
54
55 export const matchProjectRoute = (route: string) =>
56     matchPath<ResourceRouteParams>(route, { path: Routes.PROJECTS });
57
58 export const matchCollectionRoute = (route: string) =>
59     matchPath<ResourceRouteParams>(route, { path: Routes.COLLECTIONS });
60
61 export const matchProcessRoute = (route: string) =>
62     matchPath<ResourceRouteParams>(route, { path: Routes.PROCESSES });
63
64 export const matchProcessLogRoute = (route: string) =>
65     matchPath<ResourceRouteParams>(route, { path: Routes.PROCESS_LOGS });
66
67 export const matchSharedWithMeRoute = (route: string) =>
68     matchPath(route, { path: Routes.SHARED_WITH_ME });
69
70 export const matchRunProcessRoute = (route: string) =>
71     matchPath(route, { path: Routes.RUN_PROCESS });
72     
73 export const matchWorkflowRoute = (route: string) =>
74     matchPath<ResourceRouteParams>(route, { path: Routes.WORKFLOWS });