Merge branch 'master' of git.curoverse.com:arvados-workbench2 into 14500_admin_api_tokens
[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     REPOSITORIES: '/repositories',
20     SHARED_WITH_ME: '/shared-with-me',
21     RUN_PROCESS: '/run-process',
22     VIRTUAL_MACHINES: '/virtual-machines',
23     WORKFLOWS: '/workflows',
24     SEARCH_RESULTS: '/search-results',
25     SSH_KEYS: `/ssh-keys`,
26     MY_ACCOUNT: '/my-account',
27     KEEP_SERVICES: `/keep-services`,
28     COMPUTE_NODES: `/nodes`,
29     API_CLIENT_AUTHORIZATIONS: `/api_client_authorizations`
30 };
31
32 export const getResourceUrl = (uuid: string) => {
33     const kind = extractUuidKind(uuid);
34     switch (kind) {
35         case ResourceKind.PROJECT:
36             return getProjectUrl(uuid);
37         case ResourceKind.COLLECTION:
38             return getCollectionUrl(uuid);
39         case ResourceKind.PROCESS:
40             return getProcessUrl(uuid);
41         default:
42             return undefined;
43     }
44 };
45
46 export const getProcessUrl = (uuid: string) => `/processes/${uuid}`;
47
48 export const getProcessLogUrl = (uuid: string) => `/process-logs/${uuid}`;
49
50 export interface ResourceRouteParams {
51     id: string;
52 }
53
54 export const matchRootRoute = (route: string) =>
55     matchPath(route, { path: Routes.ROOT, exact: true });
56
57 export const matchFavoritesRoute = (route: string) =>
58     matchPath(route, { path: Routes.FAVORITES });
59
60 export const matchTrashRoute = (route: string) =>
61     matchPath(route, { path: Routes.TRASH });
62
63 export const matchProjectRoute = (route: string) =>
64     matchPath<ResourceRouteParams>(route, { path: Routes.PROJECTS });
65
66 export const matchCollectionRoute = (route: string) =>
67     matchPath<ResourceRouteParams>(route, { path: Routes.COLLECTIONS });
68
69 export const matchProcessRoute = (route: string) =>
70     matchPath<ResourceRouteParams>(route, { path: Routes.PROCESSES });
71
72 export const matchProcessLogRoute = (route: string) =>
73     matchPath<ResourceRouteParams>(route, { path: Routes.PROCESS_LOGS });
74
75 export const matchSharedWithMeRoute = (route: string) =>
76     matchPath(route, { path: Routes.SHARED_WITH_ME });
77
78 export const matchRunProcessRoute = (route: string) =>
79     matchPath(route, { path: Routes.RUN_PROCESS });
80
81 export const matchWorkflowRoute = (route: string) =>
82     matchPath<ResourceRouteParams>(route, { path: Routes.WORKFLOWS });
83
84 export const matchSearchResultsRoute = (route: string) =>
85     matchPath<ResourceRouteParams>(route, { path: Routes.SEARCH_RESULTS });
86
87 export const matchVirtualMachineRoute = (route: string) =>
88     matchPath<ResourceRouteParams>(route, { path: Routes.VIRTUAL_MACHINES });
89     
90 export const matchRepositoriesRoute = (route: string) =>
91     matchPath<ResourceRouteParams>(route, { path: Routes.REPOSITORIES });
92     
93 export const matchSshKeysRoute = (route: string) =>
94     matchPath(route, { path: Routes.SSH_KEYS });
95
96 export const matchMyAccountRoute = (route: string) =>
97     matchPath(route, { path: Routes.MY_ACCOUNT });
98
99 export const matchKeepServicesRoute = (route: string) =>
100     matchPath(route, { path: Routes.KEEP_SERVICES });
101
102 export const matchComputeNodesRoute = (route: string) =>
103     matchPath(route, { path: Routes.COMPUTE_NODES });
104
105 export const matchApiClientAuthorizationsRoute = (route: string) =>
106     matchPath(route, { path: Routes.API_CLIENT_AUTHORIZATIONS });