14489-any-menus-persists-after-route-change
[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     MY_ACCOUNT: '/my-account',
29     KEEP_SERVICES: `/keep-services`,
30     COMPUTE_NODES: `/nodes`,
31     USERS: '/users',
32     API_CLIENT_AUTHORIZATIONS: `/api_client_authorizations`,
33     LINKS: '/links'
34 };
35
36 export const getResourceUrl = (uuid: string) => {
37     const kind = extractUuidKind(uuid);
38     switch (kind) {
39         case ResourceKind.PROJECT:
40             return getProjectUrl(uuid);
41         case ResourceKind.COLLECTION:
42             return getCollectionUrl(uuid);
43         case ResourceKind.PROCESS:
44             return getProcessUrl(uuid);
45         default:
46             return undefined;
47     }
48 };
49
50 export const getProcessUrl = (uuid: string) => `/processes/${uuid}`;
51
52 export const getProcessLogUrl = (uuid: string) => `/process-logs/${uuid}`;
53
54 export interface ResourceRouteParams {
55     id: string;
56 }
57
58 export const matchRootRoute = (route: string) =>
59     matchPath(route, { path: Routes.ROOT, exact: true });
60
61 export const matchFavoritesRoute = (route: string) =>
62     matchPath(route, { path: Routes.FAVORITES });
63
64 export const matchTrashRoute = (route: string) =>
65     matchPath(route, { path: Routes.TRASH });
66
67 export const matchProjectRoute = (route: string) =>
68     matchPath<ResourceRouteParams>(route, { path: Routes.PROJECTS });
69
70 export const matchCollectionRoute = (route: string) =>
71     matchPath<ResourceRouteParams>(route, { path: Routes.COLLECTIONS });
72
73 export const matchProcessRoute = (route: string) =>
74     matchPath<ResourceRouteParams>(route, { path: Routes.PROCESSES });
75
76 export const matchProcessLogRoute = (route: string) =>
77     matchPath<ResourceRouteParams>(route, { path: Routes.PROCESS_LOGS });
78
79 export const matchSharedWithMeRoute = (route: string) =>
80     matchPath(route, { path: Routes.SHARED_WITH_ME });
81
82 export const matchRunProcessRoute = (route: string) =>
83     matchPath(route, { path: Routes.RUN_PROCESS });
84
85 export const matchWorkflowRoute = (route: string) =>
86     matchPath<ResourceRouteParams>(route, { path: Routes.WORKFLOWS });
87
88 export const matchSearchResultsRoute = (route: string) =>
89     matchPath<ResourceRouteParams>(route, { path: Routes.SEARCH_RESULTS });
90
91 export const matchUserVirtualMachineRoute = (route: string) =>
92     matchPath<ResourceRouteParams>(route, { path: Routes.VIRTUAL_MACHINES_USER });
93
94 export const matchAdminVirtualMachineRoute = (route: string) =>
95     matchPath<ResourceRouteParams>(route, { path: Routes.VIRTUAL_MACHINES_ADMIN });
96
97 export const matchRepositoriesRoute = (route: string) =>
98     matchPath<ResourceRouteParams>(route, { path: Routes.REPOSITORIES });
99
100 export const matchSshKeysUserRoute = (route: string) =>
101     matchPath(route, { path: Routes.SSH_KEYS_USER });
102
103 export const matchSshKeysAdminRoute = (route: string) =>
104     matchPath(route, { path: Routes.SSH_KEYS_ADMIN });
105
106 export const matchMyAccountRoute = (route: string) =>
107     matchPath(route, { path: Routes.MY_ACCOUNT });
108
109 export const matchKeepServicesRoute = (route: string) =>
110     matchPath(route, { path: Routes.KEEP_SERVICES });
111
112 export const matchUsersRoute = (route: string) =>
113     matchPath(route, { path: Routes.USERS });
114
115 export const matchComputeNodesRoute = (route: string) =>
116     matchPath(route, { path: Routes.COMPUTE_NODES });
117
118 export const matchApiClientAuthorizationsRoute = (route: string) =>
119     matchPath(route, { path: Routes.API_CLIENT_AUTHORIZATIONS });
120
121 export const matchLinksRoute = (route: string) =>
122     matchPath(route, { path: Routes.LINKS });