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`,
29 API_CLIENT_AUTHORIZATIONS: `/api_client_authorizations`
32 export const getResourceUrl = (uuid: string) => {
33 const kind = extractUuidKind(uuid);
35 case ResourceKind.PROJECT:
36 return getProjectUrl(uuid);
37 case ResourceKind.COLLECTION:
38 return getCollectionUrl(uuid);
39 case ResourceKind.PROCESS:
40 return getProcessUrl(uuid);
46 export const getProcessUrl = (uuid: string) => `/processes/${uuid}`;
48 export const getProcessLogUrl = (uuid: string) => `/process-logs/${uuid}`;
50 export interface ResourceRouteParams {
54 export const matchRootRoute = (route: string) =>
55 matchPath(route, { path: Routes.ROOT, exact: true });
57 export const matchFavoritesRoute = (route: string) =>
58 matchPath(route, { path: Routes.FAVORITES });
60 export const matchTrashRoute = (route: string) =>
61 matchPath(route, { path: Routes.TRASH });
63 export const matchProjectRoute = (route: string) =>
64 matchPath<ResourceRouteParams>(route, { path: Routes.PROJECTS });
66 export const matchCollectionRoute = (route: string) =>
67 matchPath<ResourceRouteParams>(route, { path: Routes.COLLECTIONS });
69 export const matchProcessRoute = (route: string) =>
70 matchPath<ResourceRouteParams>(route, { path: Routes.PROCESSES });
72 export const matchProcessLogRoute = (route: string) =>
73 matchPath<ResourceRouteParams>(route, { path: Routes.PROCESS_LOGS });
75 export const matchSharedWithMeRoute = (route: string) =>
76 matchPath(route, { path: Routes.SHARED_WITH_ME });
78 export const matchRunProcessRoute = (route: string) =>
79 matchPath(route, { path: Routes.RUN_PROCESS });
81 export const matchWorkflowRoute = (route: string) =>
82 matchPath<ResourceRouteParams>(route, { path: Routes.WORKFLOWS });
84 export const matchSearchResultsRoute = (route: string) =>
85 matchPath<ResourceRouteParams>(route, { path: Routes.SEARCH_RESULTS });
87 export const matchVirtualMachineRoute = (route: string) =>
88 matchPath<ResourceRouteParams>(route, { path: Routes.VIRTUAL_MACHINES });
90 export const matchRepositoriesRoute = (route: string) =>
91 matchPath<ResourceRouteParams>(route, { path: Routes.REPOSITORIES });
93 export const matchSshKeysRoute = (route: string) =>
94 matchPath(route, { path: Routes.SSH_KEYS });
96 export const matchMyAccountRoute = (route: string) =>
97 matchPath(route, { path: Routes.MY_ACCOUNT });
99 export const matchKeepServicesRoute = (route: string) =>
100 matchPath(route, { path: Routes.KEEP_SERVICES });
102 export const matchComputeNodesRoute = (route: string) =>
103 matchPath(route, { path: Routes.COMPUTE_NODES });
105 export const matchApiClientAuthorizationsRoute = (route: string) =>
106 matchPath(route, { path: Routes.API_CLIENT_AUTHORIZATIONS });