fixed conflicts
[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     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 };
27
28 export const getResourceUrl = (uuid: string) => {
29     const kind = extractUuidKind(uuid);
30     switch (kind) {
31         case ResourceKind.PROJECT:
32             return getProjectUrl(uuid);
33         case ResourceKind.COLLECTION:
34             return getCollectionUrl(uuid);
35         case ResourceKind.PROCESS:
36             return getProcessUrl(uuid);
37         default:
38             return undefined;
39     }
40 };
41
42 export const getProcessUrl = (uuid: string) => `/processes/${uuid}`;
43
44 export const getProcessLogUrl = (uuid: string) => `/process-logs/${uuid}`;
45
46 export interface ResourceRouteParams {
47     id: string;
48 }
49
50 export const matchRootRoute = (route: string) =>
51     matchPath(route, { path: Routes.ROOT, exact: true });
52
53 export const matchFavoritesRoute = (route: string) =>
54     matchPath(route, { path: Routes.FAVORITES });
55
56 export const matchTrashRoute = (route: string) =>
57     matchPath(route, { path: Routes.TRASH });
58
59 export const matchProjectRoute = (route: string) =>
60     matchPath<ResourceRouteParams>(route, { path: Routes.PROJECTS });
61
62 export const matchCollectionRoute = (route: string) =>
63     matchPath<ResourceRouteParams>(route, { path: Routes.COLLECTIONS });
64
65 export const matchProcessRoute = (route: string) =>
66     matchPath<ResourceRouteParams>(route, { path: Routes.PROCESSES });
67
68 export const matchProcessLogRoute = (route: string) =>
69     matchPath<ResourceRouteParams>(route, { path: Routes.PROCESS_LOGS });
70
71 export const matchSharedWithMeRoute = (route: string) =>
72     matchPath(route, { path: Routes.SHARED_WITH_ME });
73
74 export const matchRunProcessRoute = (route: string) =>
75     matchPath(route, { path: Routes.RUN_PROCESS });
76
77 export const matchWorkflowRoute = (route: string) =>
78     matchPath<ResourceRouteParams>(route, { path: Routes.WORKFLOWS });
79
80 export const matchSearchResultsRoute = (route: string) =>
81     matchPath<ResourceRouteParams>(route, { path: Routes.SEARCH_RESULTS });
82
83 export const matchVirtualMachineRoute = (route: string) =>
84     matchPath<ResourceRouteParams>(route, { path: Routes.VIRTUAL_MACHINES });
85     
86 export const matchRepositoriesRoute = (route: string) =>
87     matchPath<ResourceRouteParams>(route, { path: Routes.REPOSITORIES });
88     
89 export const matchSshKeysRoute = (route: string) =>
90     matchPath(route, { path: Routes.SSH_KEYS });