15230: Refactor copy to clipboard, applies to all DetailsAttribute
[arvados-workbench2.git] / src / routes / routes.ts
index 661a065eb35848bbfaef168d58af2781960f92ad..37c7a816735a7763b8ef25fb13f731f268277883 100644 (file)
@@ -3,13 +3,22 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import { matchPath } from 'react-router';
-import { ResourceKind, RESOURCE_UUID_PATTERN, extractUuidKind } from '~/models/resource';
+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: '/',
     TOKEN: '/token',
+    FED_LOGIN: '/fedtoken',
     PROJECTS: `/projects/:id(${RESOURCE_UUID_PATTERN})`,
     COLLECTIONS: `/collections/:id(${RESOURCE_UUID_PATTERN})`,
     PROCESSES: `/processes/:id(${RESOURCE_UUID_PATTERN})`,
@@ -25,6 +34,7 @@ export const Routes = {
     SEARCH_RESULTS: '/search-results',
     SSH_KEYS_ADMIN: `/ssh-keys-admin`,
     SSH_KEYS_USER: `/ssh-keys-user`,
+    SITE_MANAGER: `/site-manager`,
     MY_ACCOUNT: '/my-account',
     KEEP_SERVICES: `/keep-services`,
     COMPUTE_NODES: `/nodes`,
@@ -32,7 +42,9 @@ export const Routes = {
     API_CLIENT_AUTHORIZATIONS: `/api_client_authorizations`,
     GROUPS: '/groups',
     GROUP_DETAILS: `/group/:id(${RESOURCE_UUID_PATTERN})`,
-    LINKS: '/links'
+    LINKS: '/links',
+    PUBLIC_FAVORITES: '/public-favorites',
+    COLLECTIONS_CONTENT_ADDRESS: '/collections/:id',
 };
 
 export const getResourceUrl = (uuid: string) => {
@@ -40,6 +52,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:
@@ -49,6 +63,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}`;
@@ -107,6 +142,9 @@ export const matchSshKeysUserRoute = (route: string) =>
 export const matchSshKeysAdminRoute = (route: string) =>
     matchPath(route, { path: Routes.SSH_KEYS_ADMIN });
 
+export const matchSiteManagerRoute = (route: string) =>
+    matchPath(route, { path: Routes.SITE_MANAGER });
+
 export const matchMyAccountRoute = (route: string) =>
     matchPath(route, { path: Routes.MY_ACCOUNT });
 
@@ -127,6 +165,12 @@ export const matchGroupsRoute = (route: string) =>
 
 export const matchGroupDetailsRoute = (route: string) =>
     matchPath<ResourceRouteParams>(route, { path: Routes.GROUP_DETAILS });
-    
+
 export const matchLinksRoute = (route: string) =>
     matchPath(route, { path: Routes.LINKS });
+
+export const matchPublicFavoritesRoute = (route: string) =>
+    matchPath(route, { path: Routes.PUBLIC_FAVORITES });
+
+export const matchCollectionsContentAddressRoute = (route: string) =>
+    matchPath(route, { path: Routes.COLLECTIONS_CONTENT_ADDRESS });