16005: Open collection and project in new tab feature added
[arvados-workbench2.git] / src / views-components / context-menu / actions / helpers.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { REDIRECT_TO_APPLY_TO_PATH } from "~/common/redirect-to";
6
7 export const sanitizeToken = (href: string, tokenAsQueryParam = true): string => {
8     const [prefix, suffix] = href.split('/t=');
9     const [token1, token2, token3, ...rest] = suffix.split('/');
10     const token = `${token1}/${token2}/${token3}`;
11     const sep = href.indexOf("?") > -1 ? "&" : "?";
12
13     return `${[prefix, ...rest].join('/')}${tokenAsQueryParam ? `${sep}api_token=${token}` : ''}`;
14 };
15
16 export const getClipboardUrl = (href: string, shouldSanitizeToken = true): string => {
17     const { origin } = window.location;
18     const url = shouldSanitizeToken ? sanitizeToken(href, false) : href;
19
20     return `${origin}${!shouldSanitizeToken ? `?${REDIRECT_TO_APPLY_TO_PATH}=true&` : `?`}redirectTo=${url}`;
21 };