1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
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';
10 export const Routes = {
13 FED_LOGIN: '/fedtoken',
14 PROJECTS: `/projects/:id(${RESOURCE_UUID_PATTERN})`,
15 COLLECTIONS: `/collections/:id(${RESOURCE_UUID_PATTERN})`,
16 PROCESSES: `/processes/:id(${RESOURCE_UUID_PATTERN})`,
17 FAVORITES: '/favorites',
19 PROCESS_LOGS: `/process-logs/:id(${RESOURCE_UUID_PATTERN})`,
20 REPOSITORIES: '/repositories',
21 SHARED_WITH_ME: '/shared-with-me',
22 RUN_PROCESS: '/run-process',
23 VIRTUAL_MACHINES_ADMIN: '/virtual-machines-admin',
24 VIRTUAL_MACHINES_USER: '/virtual-machines-user',
25 WORKFLOWS: '/workflows',
26 SEARCH_RESULTS: '/search-results',
27 SSH_KEYS_ADMIN: `/ssh-keys-admin`,
28 SSH_KEYS_USER: `/ssh-keys-user`,
29 SITE_MANAGER: `/site-manager`,
30 MY_ACCOUNT: '/my-account',
31 LINK_ACCOUNT: '/link_account',
32 KEEP_SERVICES: `/keep-services`,
33 COMPUTE_NODES: `/nodes`,
35 API_CLIENT_AUTHORIZATIONS: `/api_client_authorizations`,
37 GROUP_DETAILS: `/group/:id(${RESOURCE_UUID_PATTERN})`,
39 PUBLIC_FAVORITES: '/public-favorites',
40 COLLECTIONS_CONTENT_ADDRESS: '/collections/:id',
43 export const getResourceUrl = (uuid: string) => {
44 const kind = extractUuidKind(uuid);
46 case ResourceKind.PROJECT:
47 return getProjectUrl(uuid);
48 case ResourceKind.COLLECTION:
49 return getCollectionUrl(uuid);
50 case ResourceKind.PROCESS:
51 return getProcessUrl(uuid);
57 export const getProcessUrl = (uuid: string) => `/processes/${uuid}`;
59 export const getProcessLogUrl = (uuid: string) => `/process-logs/${uuid}`;
61 export const getGroupUrl = (uuid: string) => `/group/${uuid}`;
63 export interface ResourceRouteParams {
67 export const matchRootRoute = (route: string) =>
68 matchPath(route, { path: Routes.ROOT, exact: true });
70 export const matchFavoritesRoute = (route: string) =>
71 matchPath(route, { path: Routes.FAVORITES });
73 export const matchTrashRoute = (route: string) =>
74 matchPath(route, { path: Routes.TRASH });
76 export const matchProjectRoute = (route: string) =>
77 matchPath<ResourceRouteParams>(route, { path: Routes.PROJECTS });
79 export const matchCollectionRoute = (route: string) =>
80 matchPath<ResourceRouteParams>(route, { path: Routes.COLLECTIONS });
82 export const matchProcessRoute = (route: string) =>
83 matchPath<ResourceRouteParams>(route, { path: Routes.PROCESSES });
85 export const matchProcessLogRoute = (route: string) =>
86 matchPath<ResourceRouteParams>(route, { path: Routes.PROCESS_LOGS });
88 export const matchSharedWithMeRoute = (route: string) =>
89 matchPath(route, { path: Routes.SHARED_WITH_ME });
91 export const matchRunProcessRoute = (route: string) =>
92 matchPath(route, { path: Routes.RUN_PROCESS });
94 export const matchWorkflowRoute = (route: string) =>
95 matchPath<ResourceRouteParams>(route, { path: Routes.WORKFLOWS });
97 export const matchSearchResultsRoute = (route: string) =>
98 matchPath<ResourceRouteParams>(route, { path: Routes.SEARCH_RESULTS });
100 export const matchUserVirtualMachineRoute = (route: string) =>
101 matchPath<ResourceRouteParams>(route, { path: Routes.VIRTUAL_MACHINES_USER });
103 export const matchAdminVirtualMachineRoute = (route: string) =>
104 matchPath<ResourceRouteParams>(route, { path: Routes.VIRTUAL_MACHINES_ADMIN });
106 export const matchRepositoriesRoute = (route: string) =>
107 matchPath<ResourceRouteParams>(route, { path: Routes.REPOSITORIES });
109 export const matchSshKeysUserRoute = (route: string) =>
110 matchPath(route, { path: Routes.SSH_KEYS_USER });
112 export const matchSshKeysAdminRoute = (route: string) =>
113 matchPath(route, { path: Routes.SSH_KEYS_ADMIN });
115 export const matchSiteManagerRoute = (route: string) =>
116 matchPath(route, { path: Routes.SITE_MANAGER });
118 export const matchMyAccountRoute = (route: string) =>
119 matchPath(route, { path: Routes.MY_ACCOUNT });
121 export const matchLinkAccountRoute = (route: string) =>
122 matchPath(route, { path: Routes.LINK_ACCOUNT });
124 export const matchKeepServicesRoute = (route: string) =>
125 matchPath(route, { path: Routes.KEEP_SERVICES });
127 export const matchTokenRoute = (route: string) =>
128 matchPath(route, { path: Routes.TOKEN });
130 export const matchUsersRoute = (route: string) =>
131 matchPath(route, { path: Routes.USERS });
133 export const matchComputeNodesRoute = (route: string) =>
134 matchPath(route, { path: Routes.COMPUTE_NODES });
136 export const matchApiClientAuthorizationsRoute = (route: string) =>
137 matchPath(route, { path: Routes.API_CLIENT_AUTHORIZATIONS });
139 export const matchGroupsRoute = (route: string) =>
140 matchPath(route, { path: Routes.GROUPS });
142 export const matchGroupDetailsRoute = (route: string) =>
143 matchPath<ResourceRouteParams>(route, { path: Routes.GROUP_DETAILS });
145 export const matchLinksRoute = (route: string) =>
146 matchPath(route, { path: Routes.LINKS });
148 export const matchPublicFavoritesRoute = (route: string) =>
149 matchPath(route, { path: Routes.PUBLIC_FAVORITES });
151 export const matchCollectionsContentAddressRoute = (route: string) =>
152 matchPath(route, { path: Routes.COLLECTIONS_CONTENT_ADDRESS });