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, COLLECTION_PDH_REGEX } from '~/models/resource';
7 import { getProjectUrl } from '~/models/project';
8 import { getCollectionUrl } from '~/models/collection';
9 import { Config } from '~/common/config';
10 import { Session } from "~/models/session";
12 export interface FederationConfig {
14 remoteHostsConfig: { [key: string]: Config };
18 export const Routes = {
21 FED_LOGIN: '/fedtoken',
22 PROJECTS: `/projects/:id(${RESOURCE_UUID_PATTERN})`,
23 COLLECTIONS: `/collections/:id(${RESOURCE_UUID_PATTERN})`,
24 PROCESSES: `/processes/:id(${RESOURCE_UUID_PATTERN})`,
25 FAVORITES: '/favorites',
27 PROCESS_LOGS: `/process-logs/:id(${RESOURCE_UUID_PATTERN})`,
28 REPOSITORIES: '/repositories',
29 SHARED_WITH_ME: '/shared-with-me',
30 RUN_PROCESS: '/run-process',
31 VIRTUAL_MACHINES_ADMIN: '/virtual-machines-admin',
32 VIRTUAL_MACHINES_USER: '/virtual-machines-user',
33 WORKFLOWS: '/workflows',
34 SEARCH_RESULTS: '/search-results',
35 SSH_KEYS_ADMIN: `/ssh-keys-admin`,
36 SSH_KEYS_USER: `/ssh-keys-user`,
37 SITE_MANAGER: `/site-manager`,
38 MY_ACCOUNT: '/my-account',
39 KEEP_SERVICES: `/keep-services`,
40 COMPUTE_NODES: `/nodes`,
42 API_CLIENT_AUTHORIZATIONS: `/api_client_authorizations`,
44 GROUP_DETAILS: `/group/:id(${RESOURCE_UUID_PATTERN})`,
46 PUBLIC_FAVORITES: '/public-favorites',
47 COLLECTIONS_CONTENT_ADDRESS: '/collections/:id',
50 export const getResourceUrl = (uuid: string) => {
51 const kind = extractUuidKind(uuid);
52 console.log(`for ${uuid} the kind is ${kind}`);
54 case ResourceKind.PROJECT:
55 return getProjectUrl(uuid);
56 case ResourceKind.USER:
57 return getProjectUrl(uuid);
58 case ResourceKind.COLLECTION:
59 return getCollectionUrl(uuid);
60 case ResourceKind.PROCESS:
61 return getProcessUrl(uuid);
67 export const getNavUrl = (uuid: string, config: FederationConfig) => {
68 const path = getResourceUrl(uuid) || "";
69 const cls = uuid.substr(0, 5);
70 if (cls === config.localCluster || extractUuidKind(uuid) === ResourceKind.USER || COLLECTION_PDH_REGEX.exec(uuid)) {
72 } else if (config.remoteHostsConfig[cls]) {
74 if (config.remoteHostsConfig[cls].workbench2Url) {
75 u = new URL(config.remoteHostsConfig[cls].workbench2Url || "");
77 u = new URL(config.remoteHostsConfig[cls].workbenchUrl);
78 u.search = "api_token=" + config.sessions.filter((s) => s.clusterId === cls)[0].token;
88 export const getProcessUrl = (uuid: string) => `/processes/${uuid}`;
90 export const getProcessLogUrl = (uuid: string) => `/process-logs/${uuid}`;
92 export const getGroupUrl = (uuid: string) => `/group/${uuid}`;
94 export interface ResourceRouteParams {
98 export const matchRootRoute = (route: string) =>
99 matchPath(route, { path: Routes.ROOT, exact: true });
101 export const matchFavoritesRoute = (route: string) =>
102 matchPath(route, { path: Routes.FAVORITES });
104 export const matchTrashRoute = (route: string) =>
105 matchPath(route, { path: Routes.TRASH });
107 export const matchProjectRoute = (route: string) =>
108 matchPath<ResourceRouteParams>(route, { path: Routes.PROJECTS });
110 export const matchCollectionRoute = (route: string) =>
111 matchPath<ResourceRouteParams>(route, { path: Routes.COLLECTIONS });
113 export const matchProcessRoute = (route: string) =>
114 matchPath<ResourceRouteParams>(route, { path: Routes.PROCESSES });
116 export const matchProcessLogRoute = (route: string) =>
117 matchPath<ResourceRouteParams>(route, { path: Routes.PROCESS_LOGS });
119 export const matchSharedWithMeRoute = (route: string) =>
120 matchPath(route, { path: Routes.SHARED_WITH_ME });
122 export const matchRunProcessRoute = (route: string) =>
123 matchPath(route, { path: Routes.RUN_PROCESS });
125 export const matchWorkflowRoute = (route: string) =>
126 matchPath<ResourceRouteParams>(route, { path: Routes.WORKFLOWS });
128 export const matchSearchResultsRoute = (route: string) =>
129 matchPath<ResourceRouteParams>(route, { path: Routes.SEARCH_RESULTS });
131 export const matchUserVirtualMachineRoute = (route: string) =>
132 matchPath<ResourceRouteParams>(route, { path: Routes.VIRTUAL_MACHINES_USER });
134 export const matchAdminVirtualMachineRoute = (route: string) =>
135 matchPath<ResourceRouteParams>(route, { path: Routes.VIRTUAL_MACHINES_ADMIN });
137 export const matchRepositoriesRoute = (route: string) =>
138 matchPath<ResourceRouteParams>(route, { path: Routes.REPOSITORIES });
140 export const matchSshKeysUserRoute = (route: string) =>
141 matchPath(route, { path: Routes.SSH_KEYS_USER });
143 export const matchSshKeysAdminRoute = (route: string) =>
144 matchPath(route, { path: Routes.SSH_KEYS_ADMIN });
146 export const matchSiteManagerRoute = (route: string) =>
147 matchPath(route, { path: Routes.SITE_MANAGER });
149 export const matchMyAccountRoute = (route: string) =>
150 matchPath(route, { path: Routes.MY_ACCOUNT });
152 export const matchKeepServicesRoute = (route: string) =>
153 matchPath(route, { path: Routes.KEEP_SERVICES });
155 export const matchUsersRoute = (route: string) =>
156 matchPath(route, { path: Routes.USERS });
158 export const matchComputeNodesRoute = (route: string) =>
159 matchPath(route, { path: Routes.COMPUTE_NODES });
161 export const matchApiClientAuthorizationsRoute = (route: string) =>
162 matchPath(route, { path: Routes.API_CLIENT_AUTHORIZATIONS });
164 export const matchGroupsRoute = (route: string) =>
165 matchPath(route, { path: Routes.GROUPS });
167 export const matchGroupDetailsRoute = (route: string) =>
168 matchPath<ResourceRouteParams>(route, { path: Routes.GROUP_DETAILS });
170 export const matchLinksRoute = (route: string) =>
171 matchPath(route, { path: Routes.LINKS });
173 export const matchPublicFavoritesRoute = (route: string) =>
174 matchPath(route, { path: Routes.PUBLIC_FAVORITES });
176 export const matchCollectionsContentAddressRoute = (route: string) =>
177 matchPath(route, { path: Routes.COLLECTIONS_CONTENT_ADDRESS });