refs #master Fix auth reducer test
[arvados.git] / src / routes / routes.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
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';
9
10 export const Routes = {
11     ROOT: '/',
12     TOKEN: '/token',
13     PROJECTS: `/projects/:id(${RESOURCE_UUID_PATTERN})`,
14     COLLECTIONS: `/collections/:id(${RESOURCE_UUID_PATTERN})`,
15     PROCESSES: `/processes/:id(${RESOURCE_UUID_PATTERN})`,
16     FAVORITES: '/favorites',
17     TRASH: '/trash',
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     WORKFLOWS: '/workflows',
23     SEARCH_RESULTS: '/search-results',
24     SSH_KEYS: `/ssh-keys`
25 };
26
27 export const getResourceUrl = (uuid: string) => {
28     const kind = extractUuidKind(uuid);
29     switch (kind) {
30         case ResourceKind.PROJECT:
31             return getProjectUrl(uuid);
32         case ResourceKind.COLLECTION:
33             return getCollectionUrl(uuid);
34         case ResourceKind.PROCESS:
35             return getProcessUrl(uuid);
36         default:
37             return undefined;
38     }
39 };
40
41 export const getProcessUrl = (uuid: string) => `/processes/${uuid}`;
42
43 export const getProcessLogUrl = (uuid: string) => `/process-logs/${uuid}`;
44
45 export interface ResourceRouteParams {
46     id: string;
47 }
48
49 export const matchRootRoute = (route: string) =>
50     matchPath(route, { path: Routes.ROOT, exact: true });
51
52 export const matchFavoritesRoute = (route: string) =>
53     matchPath(route, { path: Routes.FAVORITES });
54
55 export const matchTrashRoute = (route: string) =>
56     matchPath(route, { path: Routes.TRASH });
57
58 export const matchProjectRoute = (route: string) =>
59     matchPath<ResourceRouteParams>(route, { path: Routes.PROJECTS });
60
61 export const matchCollectionRoute = (route: string) =>
62     matchPath<ResourceRouteParams>(route, { path: Routes.COLLECTIONS });
63
64 export const matchProcessRoute = (route: string) =>
65     matchPath<ResourceRouteParams>(route, { path: Routes.PROCESSES });
66
67 export const matchProcessLogRoute = (route: string) =>
68     matchPath<ResourceRouteParams>(route, { path: Routes.PROCESS_LOGS });
69
70 export const matchSharedWithMeRoute = (route: string) =>
71     matchPath(route, { path: Routes.SHARED_WITH_ME });
72
73 export const matchRunProcessRoute = (route: string) =>
74     matchPath(route, { path: Routes.RUN_PROCESS });
75
76 export const matchWorkflowRoute = (route: string) =>
77     matchPath<ResourceRouteParams>(route, { path: Routes.WORKFLOWS });
78
79 export const matchSearchResultsRoute = (route: string) =>
80     matchPath<ResourceRouteParams>(route, { path: Routes.SEARCH_RESULTS });
81
82 export const matchRepositoriesRoute = (route: string) =>
83     matchPath<ResourceRouteParams>(route, { path: Routes.REPOSITORIES });
84     
85 export const matchSshKeysRoute = (route: string) =>
86     matchPath(route, { path: Routes.SSH_KEYS });