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 PROJECTS: `/projects/:id(${RESOURCE_UUID_PATTERN})`,
14 COLLECTIONS: `/collections/:id(${RESOURCE_UUID_PATTERN})`,
15 PROCESSES: `/processes/:id(${RESOURCE_UUID_PATTERN})`,
16 FAVORITES: '/favorites',
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`,
33 API_CLIENT_AUTHORIZATIONS: `/api_client_authorizations`,
35 GROUP_DETAILS: `/group/:id(${RESOURCE_UUID_PATTERN})`,
39 export const getResourceUrl = (uuid: string) => {
40 const kind = extractUuidKind(uuid);
42 case ResourceKind.PROJECT:
43 return getProjectUrl(uuid);
44 case ResourceKind.COLLECTION:
45 return getCollectionUrl(uuid);
46 case ResourceKind.PROCESS:
47 return getProcessUrl(uuid);
53 export const getProcessUrl = (uuid: string) => `/processes/${uuid}`;
55 export const getProcessLogUrl = (uuid: string) => `/process-logs/${uuid}`;
57 export const getGroupUrl = (uuid: string) => `/group/${uuid}`;
59 export interface ResourceRouteParams {
63 export const matchRootRoute = (route: string) =>
64 matchPath(route, { path: Routes.ROOT, exact: true });
66 export const matchFavoritesRoute = (route: string) =>
67 matchPath(route, { path: Routes.FAVORITES });
69 export const matchTrashRoute = (route: string) =>
70 matchPath(route, { path: Routes.TRASH });
72 export const matchProjectRoute = (route: string) =>
73 matchPath<ResourceRouteParams>(route, { path: Routes.PROJECTS });
75 export const matchCollectionRoute = (route: string) =>
76 matchPath<ResourceRouteParams>(route, { path: Routes.COLLECTIONS });
78 export const matchProcessRoute = (route: string) =>
79 matchPath<ResourceRouteParams>(route, { path: Routes.PROCESSES });
81 export const matchProcessLogRoute = (route: string) =>
82 matchPath<ResourceRouteParams>(route, { path: Routes.PROCESS_LOGS });
84 export const matchSharedWithMeRoute = (route: string) =>
85 matchPath(route, { path: Routes.SHARED_WITH_ME });
87 export const matchRunProcessRoute = (route: string) =>
88 matchPath(route, { path: Routes.RUN_PROCESS });
90 export const matchWorkflowRoute = (route: string) =>
91 matchPath<ResourceRouteParams>(route, { path: Routes.WORKFLOWS });
93 export const matchSearchResultsRoute = (route: string) =>
94 matchPath<ResourceRouteParams>(route, { path: Routes.SEARCH_RESULTS });
96 export const matchUserVirtualMachineRoute = (route: string) =>
97 matchPath<ResourceRouteParams>(route, { path: Routes.VIRTUAL_MACHINES_USER });
99 export const matchAdminVirtualMachineRoute = (route: string) =>
100 matchPath<ResourceRouteParams>(route, { path: Routes.VIRTUAL_MACHINES_ADMIN });
102 export const matchRepositoriesRoute = (route: string) =>
103 matchPath<ResourceRouteParams>(route, { path: Routes.REPOSITORIES });
105 export const matchSshKeysUserRoute = (route: string) =>
106 matchPath(route, { path: Routes.SSH_KEYS_USER });
108 export const matchSshKeysAdminRoute = (route: string) =>
109 matchPath(route, { path: Routes.SSH_KEYS_ADMIN });
111 export const matchSiteManagerRoute = (route: string) =>
112 matchPath(route, { path: Routes.SITE_MANAGER });
114 export const matchMyAccountRoute = (route: string) =>
115 matchPath(route, { path: Routes.MY_ACCOUNT });
117 export const matchKeepServicesRoute = (route: string) =>
118 matchPath(route, { path: Routes.KEEP_SERVICES });
120 export const matchUsersRoute = (route: string) =>
121 matchPath(route, { path: Routes.USERS });
123 export const matchComputeNodesRoute = (route: string) =>
124 matchPath(route, { path: Routes.COMPUTE_NODES });
126 export const matchApiClientAuthorizationsRoute = (route: string) =>
127 matchPath(route, { path: Routes.API_CLIENT_AUTHORIZATIONS });
129 export const matchGroupsRoute = (route: string) =>
130 matchPath(route, { path: Routes.GROUPS });
132 export const matchGroupDetailsRoute = (route: string) =>
133 matchPath<ResourceRouteParams>(route, { path: Routes.GROUP_DETAILS });
135 export const matchLinksRoute = (route: string) =>
136 matchPath(route, { path: Routes.LINKS });