});
});
- it.only('shows search context menu', function() {
+ it('shows search context menu', function() {
const colName = `Collection ${Math.floor(Math.random() * Math.floor(999999))}`;
cy.createCollection(adminUser.token, {
}
};
-export const getNavUrl = (uuid: string, config: FederationConfig) => {
+/**
+ * @returns A relative or federated url for the given uuid, with a token for federated WB1 urls
+ */
+export const getNavUrl = (uuid: string, config: FederationConfig, includeToken: boolean = true): string => {
const path = getResourceUrl(uuid) || "";
const cls = uuid.substring(0, 5);
if (cls === config.localCluster || extractUuidKind(uuid) === ResourceKind.USER || COLLECTION_PDH_REGEX.exec(uuid)) {
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;
+ if (includeToken) {
+ u.search = "api_token=" + config.sessions.filter((s) => s.clusterId === cls)[0].token;
+ }
}
u.pathname = path;
return u.toString();
// SPDX-License-Identifier: AGPL-3.0
import copy from 'copy-to-clipboard';
-import { getResourceUrl } from 'routes/routes';
-import { getClipboardUrl } from 'views-components/context-menu/actions/helpers';
+import { Dispatch } from 'redux';
+import { getNavUrl } from 'routes/routes';
+import { RootState } from 'store/store';
-export const openInNewTabAction = (resource: any) => () => {
- const url = getResourceUrl(resource.uuid);
+export const openInNewTabAction = (resource: any) => (dispatch: Dispatch, getState: () => RootState) => {
+ const url = getNavUrl(resource.uuid, getState().auth);
- if (url) {
+ if (url[0] === '/') {
window.open(`${window.location.origin}${url}`, '_blank');
+ } else if (url.length) {
+ window.open(url, '_blank');
}
};
-export const copyToClipboardAction = (resource: any) => () => {
- const url = getResourceUrl(resource.uuid);
+export const copyToClipboardAction = (resource: any) => (dispatch: Dispatch, getState: () => RootState) => {
+ // Copy to clipboard omits token to avoid accidental sharing
+ const url = getNavUrl(resource.uuid, getState().auth, false);
if (url) {
- copy(getClipboardUrl(url, false));
+ copy(url);
}
};
import copy from 'copy-to-clipboard';
import { ListItemIcon, ListItemText, ListItem } from "@material-ui/core";
import { Link } from "components/icon/icon";
-import { getClipboardUrl } from "./helpers";
+import { getCollectionItemClipboardUrl } from "./helpers";
export const CopyToClipboardAction = (props: { href?: any, download?: any, onClick?: () => void, kind?: string, currentCollectionUuid?: string; }) => {
const copyToClipboard = () => {
if (props.href) {
- const clipboardUrl = getClipboardUrl(props.href, true, true);
+ const clipboardUrl = getCollectionItemClipboardUrl(props.href, true, true);
copy(clipboardUrl);
}
//
// SPDX-License-Identifier: AGPL-3.0
-import { sanitizeToken, getClipboardUrl, getInlineFileUrl } from "./helpers";
+import { sanitizeToken, getCollectionItemClipboardUrl, getInlineFileUrl } from "./helpers";
describe('helpers', () => {
// given
describe('getClipboardUrl', () => {
it('should add redirectTo query param', () => {
// when
- const result = getClipboardUrl(url);
+ const result = getCollectionItemClipboardUrl(url);
// then
expect(result).toBe('http://localhost?redirectToDownload=https://example.com/c=zzzzz-4zz18-0123456789abcde/LIMS/1.html');
return `${[prefix, ...rest].join('/')}${tokenAsQueryParam ? `${sep}api_token=${token}` : ''}`;
};
-export const getClipboardUrl = (href: string, shouldSanitizeToken = true, inline = false): string => {
+/**
+ * @returns A shareable token-free WB2 url that redirects to keep-web after login
+ */
+export const getCollectionItemClipboardUrl = (href: string, shouldSanitizeToken = true, inline = false): string => {
const { origin } = window.location;
const url = shouldSanitizeToken ? sanitizeToken(href, false) : href;
const redirectKey = inline ? REDIRECT_TO_PREVIEW_KEY : REDIRECT_TO_DOWNLOAD_KEY;