X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/eb9611ea28acee0a8fdef772ef8d1b31ac689e4c..badcb86fb7d0e2ab87c7dcef230072db2e2ae95e:/src/routes/routes.ts diff --git a/src/routes/routes.ts b/src/routes/routes.ts index 7e6897a899..08e0a03d05 100644 --- a/src/routes/routes.ts +++ b/src/routes/routes.ts @@ -2,10 +2,18 @@ // // SPDX-License-Identifier: AGPL-3.0 -import { matchPath, Router } from 'react-router'; -import { ResourceKind, RESOURCE_UUID_PATTERN, extractUuidKind } from '~/models/resource'; +import { matchPath } from 'react-router'; +import { ResourceKind, RESOURCE_UUID_PATTERN, extractUuidKind, COLLECTION_PDH_REGEX } from '~/models/resource'; import { getProjectUrl } from '~/models/project'; import { getCollectionUrl } from '~/models/collection'; +import { Config } from '~/common/config'; +import { Session } from "~/models/session"; + +export interface FederationConfig { + localCluster: string; + remoteHostsConfig: { [key: string]: Config }; + sessions: Session[]; +} export const Routes = { ROOT: '/', @@ -45,6 +53,8 @@ export const getResourceUrl = (uuid: string) => { switch (kind) { case ResourceKind.PROJECT: return getProjectUrl(uuid); + case ResourceKind.USER: + return getProjectUrl(uuid); case ResourceKind.COLLECTION: return getCollectionUrl(uuid); case ResourceKind.PROCESS: @@ -54,6 +64,27 @@ export const getResourceUrl = (uuid: string) => { } }; +export const getNavUrl = (uuid: string, config: FederationConfig) => { + const path = getResourceUrl(uuid) || ""; + const cls = uuid.substr(0, 5); + if (cls === config.localCluster || extractUuidKind(uuid) === ResourceKind.USER || COLLECTION_PDH_REGEX.exec(uuid)) { + return path; + } else if (config.remoteHostsConfig[cls]) { + let u: URL; + if (config.remoteHostsConfig[cls].workbench2Url) { + u = new URL(config.remoteHostsConfig[cls].workbench2Url || ""); + } else { + u = new URL(config.remoteHostsConfig[cls].workbenchUrl); + u.search = "api_token=" + config.sessions.filter((s) => s.clusterId === cls)[0].token; + } + u.pathname = path; + return u.toString(); + } else { + return ""; + } +}; + + export const getProcessUrl = (uuid: string) => `/processes/${uuid}`; export const getProcessLogUrl = (uuid: string) => `/process-logs/${uuid}`;