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',
22 export const getResourceUrl = (uuid: string) => {
23 const kind = extractUuidKind(uuid);
25 case ResourceKind.PROJECT:
26 return getProjectUrl(uuid);
27 case ResourceKind.COLLECTION:
28 return getCollectionUrl(uuid);
29 case ResourceKind.PROCESS:
30 return getProcessUrl(uuid);
36 export const getProcessUrl = (uuid: string) => `/processes/${uuid}`;
38 export const getProcessLogUrl = (uuid: string) => `/process-logs/${uuid}`;
40 export interface ResourceRouteParams {
44 export const matchRootRoute = (route: string) =>
45 matchPath(route, { path: Routes.ROOT, exact: true });
47 export const matchFavoritesRoute = (route: string) =>
48 matchPath(route, { path: Routes.FAVORITES });
50 export const matchTrashRoute = (route: string) =>
51 matchPath(route, { path: Routes.TRASH });
53 export const matchProjectRoute = (route: string) =>
54 matchPath<ResourceRouteParams>(route, { path: Routes.PROJECTS });
56 export const matchCollectionRoute = (route: string) =>
57 matchPath<ResourceRouteParams>(route, { path: Routes.COLLECTIONS });
59 export const matchProcessRoute = (route: string) =>
60 matchPath<ResourceRouteParams>(route, { path: Routes.PROCESSES });
62 export const matchProcessLogRoute = (route: string) =>
63 matchPath<ResourceRouteParams>(route, { path: Routes.PROCESS_LOGS });
65 export const matchSharedWithMeRoute = (route: string) =>
66 matchPath(route, { path: Routes.SHARED_WITH_ME });