X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/2f83fcd45b4b23db2bb5bb4afbe1e863ebd77ec6..19d0d9c46a423adf81410f582b3a60a412d3e7f8:/services/workbench2/src/store/open-in-new-tab/open-in-new-tab.actions.ts diff --git a/services/workbench2/src/store/open-in-new-tab/open-in-new-tab.actions.ts b/services/workbench2/src/store/open-in-new-tab/open-in-new-tab.actions.ts index 6b9db6a538..28da3cf95a 100644 --- a/services/workbench2/src/store/open-in-new-tab/open-in-new-tab.actions.ts +++ b/services/workbench2/src/store/open-in-new-tab/open-in-new-tab.actions.ts @@ -2,28 +2,39 @@ // // SPDX-License-Identifier: AGPL-3.0 -import copy from 'copy-to-clipboard'; -import { Dispatch } from 'redux'; -import { getNavUrl } from 'routes/routes'; -import { RootState } from 'store/store'; +import copy from "copy-to-clipboard"; +import { Dispatch } from "redux"; +import { getNavUrl } from "routes/routes"; +import { RootState } from "store/store"; +import { snackbarActions, SnackbarKind } from "store/snackbar/snackbar-actions"; export const openInNewTabAction = (resource: any) => (dispatch: Dispatch, getState: () => RootState) => { const url = getNavUrl(resource.uuid, getState().auth); - if (url[0] === '/') { - window.open(`${window.location.origin}${url}`, '_blank'); + if (url[0] === "/") { + window.open(`${window.location.origin}${url}`, "_blank", "noopener"); } else if (url.length) { - window.open(url, '_blank'); + window.open(url, "_blank", "noopener"); } }; -export const copyToClipboardAction = (resource: any) => (dispatch: Dispatch, getState: () => RootState) => { +export const copyToClipboardAction = (resources: Array) => (dispatch: Dispatch, getState: () => RootState) => { // Copy to clipboard omits token to avoid accidental sharing - const url = getNavUrl(resource.uuid, getState().auth, false); - if (url[0] === '/') { - copy(`${window.location.origin}${url}`); - } else if (url.length) { - copy(url); + let url = getNavUrl(resources[0].uuid, getState().auth, false); + let wasCopied; + + if (url[0] === "/") wasCopied = copy(`${window.location.origin}${url}`); + else if (url.length) { + wasCopied = copy(url); } + + if (wasCopied) + dispatch( + snackbarActions.OPEN_SNACKBAR({ + message: "Copied", + hideDuration: 2000, + kind: SnackbarKind.SUCCESS, + }) + ); };