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 SHARED_WITH_ME: '/shared-with-me',
20 WORKFLOWS: '/workflows'
23 export const getResourceUrl = (uuid: string) => {
24 const kind = extractUuidKind(uuid);
26 case ResourceKind.PROJECT:
27 return getProjectUrl(uuid);
28 case ResourceKind.COLLECTION:
29 return getCollectionUrl(uuid);
30 case ResourceKind.PROCESS:
31 return getProcessUrl(uuid);
37 export const getProcessUrl = (uuid: string) => `/processes/${uuid}`;
39 export const getProcessLogUrl = (uuid: string) => `/process-logs/${uuid}`;
41 export interface ResourceRouteParams {
45 export const matchRootRoute = (route: string) =>
46 matchPath(route, { path: Routes.ROOT, exact: true });
48 export const matchFavoritesRoute = (route: string) =>
49 matchPath(route, { path: Routes.FAVORITES });
51 export const matchTrashRoute = (route: string) =>
52 matchPath(route, { path: Routes.TRASH });
54 export const matchProjectRoute = (route: string) =>
55 matchPath<ResourceRouteParams>(route, { path: Routes.PROJECTS });
57 export const matchCollectionRoute = (route: string) =>
58 matchPath<ResourceRouteParams>(route, { path: Routes.COLLECTIONS });
60 export const matchProcessRoute = (route: string) =>
61 matchPath<ResourceRouteParams>(route, { path: Routes.PROCESSES });
63 export const matchProcessLogRoute = (route: string) =>
64 matchPath<ResourceRouteParams>(route, { path: Routes.PROCESS_LOGS });
66 export const matchSharedWithMeRoute = (route: string) =>
67 matchPath(route, { path: Routes.SHARED_WITH_ME });
69 export const matchWorkflowRoute = (route: string) =>
70 matchPath<ResourceRouteParams>(route, { path: Routes.WORKFLOWS });