Add ssh keys panel
[arvados-workbench2.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     SHARED_WITH_ME: '/shared-with-me',
20     RUN_PROCESS: '/run-process',
21     WORKFLOWS: '/workflows',
22     SEARCH_RESULTS: '/search-results',
23     SSH_KEYS: `/ssh-keys`
24 };
25
26 export const getResourceUrl = (uuid: string) => {
27     const kind = extractUuidKind(uuid);
28     switch (kind) {
29         case ResourceKind.PROJECT:
30             return getProjectUrl(uuid);
31         case ResourceKind.COLLECTION:
32             return getCollectionUrl(uuid);
33         case ResourceKind.PROCESS:
34             return getProcessUrl(uuid);
35         default:
36             return undefined;
37     }
38 };
39
40 export const getProcessUrl = (uuid: string) => `/processes/${uuid}`;
41
42 export const getProcessLogUrl = (uuid: string) => `/process-logs/${uuid}`;
43
44 export interface ResourceRouteParams {
45     id: string;
46 }
47
48 export const matchRootRoute = (route: string) =>
49     matchPath(route, { path: Routes.ROOT, exact: true });
50
51 export const matchFavoritesRoute = (route: string) =>
52     matchPath(route, { path: Routes.FAVORITES });
53
54 export const matchTrashRoute = (route: string) =>
55     matchPath(route, { path: Routes.TRASH });
56
57 export const matchProjectRoute = (route: string) =>
58     matchPath<ResourceRouteParams>(route, { path: Routes.PROJECTS });
59
60 export const matchCollectionRoute = (route: string) =>
61     matchPath<ResourceRouteParams>(route, { path: Routes.COLLECTIONS });
62
63 export const matchProcessRoute = (route: string) =>
64     matchPath<ResourceRouteParams>(route, { path: Routes.PROCESSES });
65
66 export const matchProcessLogRoute = (route: string) =>
67     matchPath<ResourceRouteParams>(route, { path: Routes.PROCESS_LOGS });
68
69 export const matchSharedWithMeRoute = (route: string) =>
70     matchPath(route, { path: Routes.SHARED_WITH_ME });
71
72 export const matchRunProcessRoute = (route: string) =>
73     matchPath(route, { path: Routes.RUN_PROCESS });
74     
75 export const matchWorkflowRoute = (route: string) =>
76     matchPath<ResourceRouteParams>(route, { path: Routes.WORKFLOWS });
77
78 export const matchSearchResultsRoute = (route: string) =>
79     matchPath<ResourceRouteParams>(route, { path: Routes.SEARCH_RESULTS });
80
81 export const matchSshKeysRoute = (route: string) =>
82     matchPath(route, { path: Routes.SSH_KEYS });