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: '/virtual-machines',
23 WORKFLOWS: '/workflows',
24 SEARCH_RESULTS: '/search-results',
25 SSH_KEYS: `/ssh-keys`,
26 MY_ACCOUNT: '/my-account',
27 KEEP_SERVICES: `/keep-services`,
28 COMPUTE_NODES: `/nodes`,
30 API_CLIENT_AUTHORIZATIONS: `/api_client_authorizations`
33 export const getResourceUrl = (uuid: string) => {
34 const kind = extractUuidKind(uuid);
36 case ResourceKind.PROJECT:
37 return getProjectUrl(uuid);
38 case ResourceKind.COLLECTION:
39 return getCollectionUrl(uuid);
40 case ResourceKind.PROCESS:
41 return getProcessUrl(uuid);
47 export const getProcessUrl = (uuid: string) => `/processes/${uuid}`;
49 export const getProcessLogUrl = (uuid: string) => `/process-logs/${uuid}`;
51 export interface ResourceRouteParams {
55 export const matchRootRoute = (route: string) =>
56 matchPath(route, { path: Routes.ROOT, exact: true });
58 export const matchFavoritesRoute = (route: string) =>
59 matchPath(route, { path: Routes.FAVORITES });
61 export const matchTrashRoute = (route: string) =>
62 matchPath(route, { path: Routes.TRASH });
64 export const matchProjectRoute = (route: string) =>
65 matchPath<ResourceRouteParams>(route, { path: Routes.PROJECTS });
67 export const matchCollectionRoute = (route: string) =>
68 matchPath<ResourceRouteParams>(route, { path: Routes.COLLECTIONS });
70 export const matchProcessRoute = (route: string) =>
71 matchPath<ResourceRouteParams>(route, { path: Routes.PROCESSES });
73 export const matchProcessLogRoute = (route: string) =>
74 matchPath<ResourceRouteParams>(route, { path: Routes.PROCESS_LOGS });
76 export const matchSharedWithMeRoute = (route: string) =>
77 matchPath(route, { path: Routes.SHARED_WITH_ME });
79 export const matchRunProcessRoute = (route: string) =>
80 matchPath(route, { path: Routes.RUN_PROCESS });
82 export const matchWorkflowRoute = (route: string) =>
83 matchPath<ResourceRouteParams>(route, { path: Routes.WORKFLOWS });
85 export const matchSearchResultsRoute = (route: string) =>
86 matchPath<ResourceRouteParams>(route, { path: Routes.SEARCH_RESULTS });
88 export const matchVirtualMachineRoute = (route: string) =>
89 matchPath<ResourceRouteParams>(route, { path: Routes.VIRTUAL_MACHINES });
91 export const matchRepositoriesRoute = (route: string) =>
92 matchPath<ResourceRouteParams>(route, { path: Routes.REPOSITORIES });
94 export const matchSshKeysRoute = (route: string) =>
95 matchPath(route, { path: Routes.SSH_KEYS });
97 export const matchMyAccountRoute = (route: string) =>
98 matchPath(route, { path: Routes.MY_ACCOUNT });
100 export const matchKeepServicesRoute = (route: string) =>
101 matchPath(route, { path: Routes.KEEP_SERVICES });
103 export const matchUsersRoute = (route: string) =>
104 matchPath(route, { path: Routes.USERS });
106 export const matchComputeNodesRoute = (route: string) =>
107 matchPath(route, { path: Routes.COMPUTE_NODES });
109 export const matchApiClientAuthorizationsRoute = (route: string) =>
110 matchPath(route, { path: Routes.API_CLIENT_AUTHORIZATIONS });