19079: Add search results context menu with clipboard and new tab options
[arvados-workbench2.git] / src / store / open-in-new-tab / open-in-new-tab.actions.ts
index 42bdc4ccfe5c25de8a33e277b0d34a4c81f24b98..a363bc03c5c6b7b79527dcc87dcf9f86813cba53 100644 (file)
@@ -2,27 +2,22 @@
 //
 // 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 { getResourceUrl } from 'routes/routes';
+import { getClipboardUrl } from 'views-components/context-menu/actions/helpers';
 
-export const openInNewTabActions = unionize({
-    COPY_STORE: ofType<{}>(),
-    OPEN_COLLECTION_IN_NEW_TAB: ofType<string>(),
-    OPEN_PROJECT_IN_NEW_TAB: ofType<string>()
-});
+export const openInNewTabAction = (resource: any) => () => {
+    const url = getResourceUrl(resource.uuid);
 
-export const openInNewTabAction = (resource: any) => (dispatch: Dispatch) => {
-    const { uuid, kind } = resource;
+    if (url) {
+        window.open(`${window.location.origin}${url}`, '_blank');
+    }
+};
 
-    dispatch(openInNewTabActions.COPY_STORE());
+export const copyToClipboardAction = (resource: any) => () => {
+    const url = getResourceUrl(resource.uuid);
 
-    if (kind === ResourceKind.COLLECTION) {
-        dispatch(openInNewTabActions.OPEN_COLLECTION_IN_NEW_TAB(uuid));
-    }
-    if (kind === ResourceKind.PROJECT) {
-        dispatch(openInNewTabActions.OPEN_PROJECT_IN_NEW_TAB(uuid));
+    if (url) {
+        copy(getClipboardUrl(url, false));
     }
-
-    console.log(uuid);
-};
\ No newline at end of file
+};