X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/9cd0c2757db479fb75e150d52d4871d9a88af364..3f7e1a8afad27920adf8f03ce82eeb1ae58aa84f:/src/store/open-in-new-tab/open-in-new-tab.actions.ts diff --git a/src/store/open-in-new-tab/open-in-new-tab.actions.ts b/src/store/open-in-new-tab/open-in-new-tab.actions.ts index 94aec140..c465aae8 100644 --- a/src/store/open-in-new-tab/open-in-new-tab.actions.ts +++ b/src/store/open-in-new-tab/open-in-new-tab.actions.ts @@ -3,35 +3,25 @@ // SPDX-License-Identifier: AGPL-3.0 import copy from 'copy-to-clipboard'; -import { ResourceKind } from 'models/resource'; -import { getClipboardUrl } from 'views-components/context-menu/actions/helpers'; +import { Dispatch } from 'redux'; +import { getNavUrl } from 'routes/routes'; +import { RootState } from 'store/store'; -const getUrl = (resource: any) => { - let url: string | null = null; - const { uuid, kind } = resource; +export const openInNewTabAction = (resource: any) => (dispatch: Dispatch, getState: () => RootState) => { + const url = getNavUrl(resource.uuid, getState().auth); - if (kind === ResourceKind.COLLECTION) { - url = `/collections/${uuid}`; - } - if (kind === ResourceKind.PROJECT) { - url = `/projects/${uuid}`; - } - - return url; -}; - -export const openInNewTabAction = (resource: any) => () => { - const url = getUrl(resource); - - 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 = getUrl(resource); +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); } -}; \ No newline at end of file +};