16005: Open collection and project in new tab feature added
[arvados-workbench2.git] / src / views-components / context-menu / actions / helpers.ts
index 8dfcaca0e30853d9f317f8aaa460d58dae25cbc5..578af2053f74d543cf8d00fec26b87d1e4c8c8c6 100644 (file)
@@ -2,7 +2,9 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-export const sanitizeToken = (href: string, tokenAsQueryParam: boolean = true): string => {
+import { REDIRECT_TO_APPLY_TO_PATH } from "~/common/redirect-to";
+
+export const sanitizeToken = (href: string, tokenAsQueryParam = true): string => {
     const [prefix, suffix] = href.split('/t=');
     const [token1, token2, token3, ...rest] = suffix.split('/');
     const token = `${token1}/${token2}/${token3}`;
@@ -11,9 +13,9 @@ export const sanitizeToken = (href: string, tokenAsQueryParam: boolean = true):
     return `${[prefix, ...rest].join('/')}${tokenAsQueryParam ? `${sep}api_token=${token}` : ''}`;
 };
 
-export const getClipboardUrl = (href: string): string => {
+export const getClipboardUrl = (href: string, shouldSanitizeToken = true): string => {
     const { origin } = window.location;
-    const url = sanitizeToken(href, false);
+    const url = shouldSanitizeToken ? sanitizeToken(href, false) : href;
 
-    return `${origin}?redirectTo=${url}`;
+    return `${origin}${!shouldSanitizeToken ? `?${REDIRECT_TO_APPLY_TO_PATH}=true&` : `?`}redirectTo=${url}`;
 };