X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/df0520719b15e7e230fb72f3e53ff36a34f4ba87..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 17ba7402..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 @@ -2,24 +2,26 @@ // // SPDX-License-Identifier: AGPL-3.0 +import copy from 'copy-to-clipboard'; import { Dispatch } from 'redux'; -import { ResourceKind } from '~/models/resource'; -import { unionize, ofType } from '~/common/unionize'; +import { getNavUrl } from 'routes/routes'; +import { RootState } from 'store/store'; -export const openInNewTabActions = unionize({ - COPY_STORE: ofType<{}>(), - OPEN_COLLECTION_IN_NEW_TAB: ofType(), - OPEN_PROJECT_IN_NEW_TAB: ofType() -}); +export const openInNewTabAction = (resource: any) => (dispatch: Dispatch, getState: () => RootState) => { + const url = getNavUrl(resource.uuid, getState().auth); -export const openInNewTabAction = (resource: any) => (dispatch: Dispatch) => { - const { uuid, kind } = resource; + if (url[0] === '/') { + window.open(`${window.location.origin}${url}`, '_blank'); + } else if (url.length) { + window.open(url, '_blank'); + } +}; - dispatch(openInNewTabActions.COPY_STORE()); +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 (kind === ResourceKind.COLLECTION) { - dispatch(openInNewTabActions.OPEN_COLLECTION_IN_NEW_TAB(uuid)); - } else if (kind === ResourceKind.PROJECT) { - dispatch(openInNewTabActions.OPEN_PROJECT_IN_NEW_TAB(uuid)); + if (url) { + copy(url); } -}; \ No newline at end of file +};