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})`
21 export const getResourceUrl = (uuid: string) => {
22 const kind = extractUuidKind(uuid);
24 case ResourceKind.PROJECT:
25 return getProjectUrl(uuid);
26 case ResourceKind.COLLECTION:
27 return getCollectionUrl(uuid);
28 case ResourceKind.PROCESS:
29 return getProcessUrl(uuid);
35 export const getProcessUrl = (uuid: string) => `/processes/${uuid}`;
37 export const getProcessLogUrl = (uuid: string) => `/process-logs/${uuid}`;
39 export interface ResourceRouteParams {
43 export const matchRootRoute = (route: string) =>
44 matchPath(route, { path: Routes.ROOT, exact: true });
46 export const matchFavoritesRoute = (route: string) =>
47 matchPath(route, { path: Routes.FAVORITES });
49 export const matchTrashRoute = (route: string) =>
50 matchPath(route, { path: Routes.TRASH });
52 export const matchProjectRoute = (route: string) =>
53 matchPath<ResourceRouteParams>(route, { path: Routes.PROJECTS });
55 export const matchCollectionRoute = (route: string) =>
56 matchPath<ResourceRouteParams>(route, { path: Routes.COLLECTIONS });
58 export const matchProcessRoute = (route: string) =>
59 matchPath<ResourceRouteParams>(route, { path: Routes.PROCESSES });
61 export const matchProcessLogRoute = (route: string) =>
62 matchPath<ResourceRouteParams>(route, { path: Routes.PROCESS_LOGS });