Merge branch 'master' into 14604-ui-improvements
[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_ADMIN: '/virtual-machines-admin',
23     VIRTUAL_MACHINES_USER: '/virtual-machines-user',
24     WORKFLOWS: '/workflows',
25     SEARCH_RESULTS: '/search-results',
26     SSH_KEYS_ADMIN: `/ssh-keys-admin`,
27     SSH_KEYS_USER: `/ssh-keys-user`,
28     SITE_MANAGER: `/site-manager`,
29     MY_ACCOUNT: '/my-account',
30     KEEP_SERVICES: `/keep-services`,
31     COMPUTE_NODES: `/nodes`,
32     USERS: '/users',
33     API_CLIENT_AUTHORIZATIONS: `/api_client_authorizations`,
34     GROUPS: '/groups',
35     GROUP_DETAILS: `/group/:id(${RESOURCE_UUID_PATTERN})`,
36     LINKS: '/links'
37 };
38
39 export const getResourceUrl = (uuid: string) => {
40     const kind = extractUuidKind(uuid);
41     switch (kind) {
42         case ResourceKind.PROJECT:
43             return getProjectUrl(uuid);
44         case ResourceKind.COLLECTION:
45             return getCollectionUrl(uuid);
46         case ResourceKind.PROCESS:
47             return getProcessUrl(uuid);
48         default:
49             return undefined;
50     }
51 };
52
53 export const getProcessUrl = (uuid: string) => `/processes/${uuid}`;
54
55 export const getProcessLogUrl = (uuid: string) => `/process-logs/${uuid}`;
56
57 export const getGroupUrl = (uuid: string) => `/group/${uuid}`;
58
59 export interface ResourceRouteParams {
60     id: string;
61 }
62
63 export const matchRootRoute = (route: string) =>
64     matchPath(route, { path: Routes.ROOT, exact: true });
65
66 export const matchFavoritesRoute = (route: string) =>
67     matchPath(route, { path: Routes.FAVORITES });
68
69 export const matchTrashRoute = (route: string) =>
70     matchPath(route, { path: Routes.TRASH });
71
72 export const matchProjectRoute = (route: string) =>
73     matchPath<ResourceRouteParams>(route, { path: Routes.PROJECTS });
74
75 export const matchCollectionRoute = (route: string) =>
76     matchPath<ResourceRouteParams>(route, { path: Routes.COLLECTIONS });
77
78 export const matchProcessRoute = (route: string) =>
79     matchPath<ResourceRouteParams>(route, { path: Routes.PROCESSES });
80
81 export const matchProcessLogRoute = (route: string) =>
82     matchPath<ResourceRouteParams>(route, { path: Routes.PROCESS_LOGS });
83
84 export const matchSharedWithMeRoute = (route: string) =>
85     matchPath(route, { path: Routes.SHARED_WITH_ME });
86
87 export const matchRunProcessRoute = (route: string) =>
88     matchPath(route, { path: Routes.RUN_PROCESS });
89
90 export const matchWorkflowRoute = (route: string) =>
91     matchPath<ResourceRouteParams>(route, { path: Routes.WORKFLOWS });
92
93 export const matchSearchResultsRoute = (route: string) =>
94     matchPath<ResourceRouteParams>(route, { path: Routes.SEARCH_RESULTS });
95
96 export const matchUserVirtualMachineRoute = (route: string) =>
97     matchPath<ResourceRouteParams>(route, { path: Routes.VIRTUAL_MACHINES_USER });
98
99 export const matchAdminVirtualMachineRoute = (route: string) =>
100     matchPath<ResourceRouteParams>(route, { path: Routes.VIRTUAL_MACHINES_ADMIN });
101
102 export const matchRepositoriesRoute = (route: string) =>
103     matchPath<ResourceRouteParams>(route, { path: Routes.REPOSITORIES });
104
105 export const matchSshKeysUserRoute = (route: string) =>
106     matchPath(route, { path: Routes.SSH_KEYS_USER });
107
108 export const matchSshKeysAdminRoute = (route: string) =>
109     matchPath(route, { path: Routes.SSH_KEYS_ADMIN });
110
111 export const matchSiteManagerRoute = (route: string) =>
112     matchPath(route, { path: Routes.SITE_MANAGER });
113
114 export const matchMyAccountRoute = (route: string) =>
115     matchPath(route, { path: Routes.MY_ACCOUNT });
116
117 export const matchKeepServicesRoute = (route: string) =>
118     matchPath(route, { path: Routes.KEEP_SERVICES });
119
120 export const matchUsersRoute = (route: string) =>
121     matchPath(route, { path: Routes.USERS });
122
123 export const matchComputeNodesRoute = (route: string) =>
124     matchPath(route, { path: Routes.COMPUTE_NODES });
125
126 export const matchApiClientAuthorizationsRoute = (route: string) =>
127     matchPath(route, { path: Routes.API_CLIENT_AUTHORIZATIONS });
128
129 export const matchGroupsRoute = (route: string) =>
130     matchPath(route, { path: Routes.GROUPS });
131
132 export const matchGroupDetailsRoute = (route: string) =>
133     matchPath<ResourceRouteParams>(route, { path: Routes.GROUP_DETAILS });
134     
135 export const matchLinksRoute = (route: string) =>
136     matchPath(route, { path: Routes.LINKS });