X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/67d77b206ebee7c776bd4d7dbc112ebb0c7ba800..c952afae1af2fb31b68be04f70bd7ae6f9d52aba:/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 42bdc4cc..94aec140 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,27 +2,36 @@ // // SPDX-License-Identifier: AGPL-3.0 -import { Dispatch } from 'redux'; -import { ResourceKind } from '~/models/resource'; -import { unionize, ofType } from '~/common/unionize'; +import copy from 'copy-to-clipboard'; +import { ResourceKind } from 'models/resource'; +import { getClipboardUrl } from 'views-components/context-menu/actions/helpers'; -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) => { +const getUrl = (resource: any) => { + let url: string | null = null; const { uuid, kind } = resource; - dispatch(openInNewTabActions.COPY_STORE()); - if (kind === ResourceKind.COLLECTION) { - dispatch(openInNewTabActions.OPEN_COLLECTION_IN_NEW_TAB(uuid)); + url = `/collections/${uuid}`; } if (kind === ResourceKind.PROJECT) { - dispatch(openInNewTabActions.OPEN_PROJECT_IN_NEW_TAB(uuid)); + url = `/projects/${uuid}`; + } + + return url; +}; + +export const openInNewTabAction = (resource: any) => () => { + const url = getUrl(resource); + + if (url) { + window.open(`${window.location.origin}${url}`, '_blank'); } +}; - console.log(uuid); +export const copyToClipboardAction = (resource: any) => () => { + const url = getUrl(resource); + + if (url) { + copy(getClipboardUrl(url, false)); + } }; \ No newline at end of file