Merge branch '19079-search-results-open-newtab' into main. Closes #19079
authorStephen Smith <stephen@curii.com>
Mon, 1 Aug 2022 14:34:43 +0000 (10:34 -0400)
committerStephen Smith <stephen@curii.com>
Mon, 1 Aug 2022 14:34:43 +0000 (10:34 -0400)
Arvados-DCO-1.1-Signed-off-by: Stephen Smith <stephen@curii.com>

cypress/integration/search.spec.js
src/index.tsx
src/routes/routes.ts
src/store/context-menu/context-menu-actions.ts
src/store/open-in-new-tab/open-in-new-tab.actions.ts
src/views-components/context-menu/action-sets/search-results-action-set.ts [new file with mode: 0644]
src/views-components/context-menu/actions/copy-to-clipboard-action.tsx
src/views-components/context-menu/actions/helpers.test.ts
src/views-components/context-menu/actions/helpers.ts
src/views-components/context-menu/context-menu.tsx
src/views/search-results-panel/search-results-panel.tsx

index 5434ca248a5167e5461014491d77f422980ae693..2216c067f8423f7c36fdfd4c7b10ca23402d707c 100644 (file)
@@ -126,4 +126,158 @@ describe('Search tests', function() {
                 });
         });
     });
-});
\ No newline at end of file
+
+    it('shows search context menu', function() {
+        const colName = `Collection ${Math.floor(Math.random() * Math.floor(999999))}`;
+        const federatedColName = `Collection ${Math.floor(Math.random() * Math.floor(999999))}`;
+        const federatedColUuid = "xxxxx-4zz18-000000000000000";
+
+        // Intercept config to insert remote cluster
+        cy.intercept({method: 'GET', hostname: 'localhost', url: '**/arvados/v1/config?nocache=*'}, (req) => {
+            req.reply((res) => {
+                res.body.RemoteClusters = {
+                    "*": res.body.RemoteClusters["*"],
+                    "xxxxx": {
+                        "ActivateUsers": true,
+                        "Host": "xxxxx.fakecluster.tld",
+                        "Insecure": false,
+                        "Proxy": true,
+                        "Scheme": ""
+                    }
+                };
+            });
+        });
+
+        // Fake remote cluster config
+        cy.intercept(
+          {
+            method: "GET",
+            hostname: "xxxxx.fakecluster.tld",
+            url: "**/arvados/v1/config",
+          },
+          {
+            statusCode: 200,
+            body: {
+              API: {},
+              ClusterID: "xxxxx",
+              Collections: {},
+              Containers: {},
+              InstanceTypes: {},
+              Login: {},
+              Mail: { SupportEmailAddress: "arvados@example.com" },
+              RemoteClusters: {
+                "*": {
+                  ActivateUsers: false,
+                  Host: "",
+                  Insecure: false,
+                  Proxy: false,
+                  Scheme: "https",
+                },
+              },
+              Services: {
+                Composer: { ExternalURL: "" },
+                Controller: { ExternalURL: "https://xxxxx.fakecluster.tld:34763/" },
+                DispatchCloud: { ExternalURL: "" },
+                DispatchLSF: { ExternalURL: "" },
+                DispatchSLURM: { ExternalURL: "" },
+                GitHTTP: { ExternalURL: "https://xxxxx.fakecluster.tld:39105/" },
+                GitSSH: { ExternalURL: "" },
+                Health: { ExternalURL: "https://xxxxx.fakecluster.tld:42915/" },
+                Keepbalance: { ExternalURL: "" },
+                Keepproxy: { ExternalURL: "https://xxxxx.fakecluster.tld:46773/" },
+                Keepstore: { ExternalURL: "" },
+                RailsAPI: { ExternalURL: "" },
+                WebDAV: { ExternalURL: "https://xxxxx.fakecluster.tld:36041/" },
+                WebDAVDownload: { ExternalURL: "https://xxxxx.fakecluster.tld:42957/" },
+                WebShell: { ExternalURL: "" },
+                Websocket: { ExternalURL: "wss://xxxxx.fakecluster.tld:37121/websocket" },
+                Workbench1: { ExternalURL: "https://wb1.xxxxx.fakecluster.tld/" },
+                Workbench2: { ExternalURL: "https://wb2.xxxxx.fakecluster.tld/" },
+              },
+              StorageClasses: {
+                default: { Default: true, Priority: 0 },
+              },
+              Users: {},
+              Volumes: {},
+              Workbench: {},
+            },
+          }
+        );
+
+        cy.createCollection(adminUser.token, {
+            name: colName,
+            owner_uuid: activeUser.user.uuid,
+            preserve_version: true,
+            manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
+        }).then(function(testCollection) {
+            cy.loginAs(activeUser);
+
+            // Intercept search results to add federated result
+            cy.intercept({method: 'GET', url: '**/arvados/v1/groups/contents?*'}, (req) => {
+                req.reply((res) => {
+                    res.body.items = [
+                        res.body.items[0],
+                        {
+                            ...res.body.items[0],
+                            uuid: federatedColUuid,
+                            portable_data_hash: "00000000000000000000000000000000+0",
+                            name: federatedColName,
+                            href: res.body.items[0].href.replace(testCollection.uuid, federatedColUuid),
+                        }
+                    ];
+                    res.body.items_available += 1;
+                });
+            });
+
+            cy.doSearch(colName);
+
+            // Stub new window
+            cy.window().then(win => {
+                cy.stub(win, 'open').as('Open')
+            });
+
+            // Check copy to clipboard
+            cy.get('[data-cy=search-results]').contains(colName).rightclick();
+            cy.get('[data-cy=context-menu]').within((ctx) => {
+                // Check that there are 4 items in the menu
+                cy.get(ctx).children().should('have.length', 4);
+                cy.contains('Advanced');
+                cy.contains('Copy to clipboard');
+                cy.contains('Open in new tab');
+                cy.contains('View details');
+
+                cy.contains('Copy to clipboard').click();
+                cy.window().then((win) => (
+                    win.navigator.clipboard.readText().then((text) => {
+                        expect(text).to.match(new RegExp(`/collections/${testCollection.uuid}$`));
+                    })
+                ));
+            });
+
+            // Check open in new tab
+            cy.get('[data-cy=search-results]').contains(colName).rightclick();
+            cy.get('[data-cy=context-menu]').within(() => {
+                cy.contains('Open in new tab').click();
+                cy.get('@Open').should('have.been.calledOnceWith', `${window.location.origin}/collections/${testCollection.uuid}`)
+            });
+
+            // Check federated result copy to clipboard
+            cy.get('[data-cy=search-results]').contains(federatedColName).rightclick();
+            cy.get('[data-cy=context-menu]').within(() => {
+                cy.contains('Copy to clipboard').click();
+                cy.window().then((win) => (
+                    win.navigator.clipboard.readText().then((text) => {
+                        expect(text).to.equal(`https://wb2.xxxxx.fakecluster.tld/collections/${federatedColUuid}`);
+                    })
+                ));
+            });
+            // Check open in new tab
+            cy.get('[data-cy=search-results]').contains(federatedColName).rightclick();
+            cy.get('[data-cy=context-menu]').within(() => {
+                cy.contains('Open in new tab').click();
+                cy.get('@Open').should('have.been.calledWith', `https://wb2.xxxxx.fakecluster.tld/collections/${federatedColUuid}`)
+            });
+
+        });
+    });
+});
index 03840d49ad232fe22d22a14c3762757690523894..5d939d36d5f33eec2caa0741e604ced7e2ffa662 100644 (file)
@@ -66,6 +66,7 @@ import { workflowActionSet } from 'views-components/context-menu/action-sets/wor
 import { snackbarActions, SnackbarKind } from "store/snackbar/snackbar-actions";
 import { openNotFoundDialog } from './store/not-found-panel/not-found-panel-action';
 import { storeRedirects } from './common/redirect-to';
+import { searchResultsActionSet } from 'views-components/context-menu/action-sets/search-results-action-set';
 
 console.log(`Starting arvados [${getBuildInfo()}]`);
 
@@ -104,6 +105,7 @@ addMenuActionSet(ContextMenuKind.PROJECT_ADMIN, projectAdminActionSet);
 addMenuActionSet(ContextMenuKind.FILTER_GROUP_ADMIN, filterGroupAdminActionSet);
 addMenuActionSet(ContextMenuKind.PERMISSION_EDIT, permissionEditActionSet);
 addMenuActionSet(ContextMenuKind.WORKFLOW, workflowActionSet);
+addMenuActionSet(ContextMenuKind.SEARCH_RESULTS, searchResultsActionSet);
 
 storeRedirects();
 
index 50689ec37c46ac1fba6d5ff985badeb233944031..22c8f4c8e52414b8d84c99cc439facc4d4f9ecdf 100644 (file)
@@ -66,7 +66,10 @@ export const getResourceUrl = (uuid: string) => {
     }
 };
 
-export const getNavUrl = (uuid: string, config: FederationConfig) => {
+/**
+ * @returns A relative or federated url for the given uuid, with a token for federated WB1 urls
+ */
+export const getNavUrl = (uuid: string, config: FederationConfig, includeToken: boolean = true): string => {
     const path = getResourceUrl(uuid) || "";
     const cls = uuid.substring(0, 5);
     if (cls === config.localCluster || extractUuidKind(uuid) === ResourceKind.USER || COLLECTION_PDH_REGEX.exec(uuid)) {
@@ -83,7 +86,9 @@ export const getNavUrl = (uuid: string, config: FederationConfig) => {
             u = new URL(config.remoteHostsConfig[cls].workbench2Url);
         } else {
             u = new URL(config.remoteHostsConfig[cls].workbenchUrl);
-            u.search = "api_token=" + config.sessions.filter((s) => s.clusterId === cls)[0].token;
+            if (includeToken) {
+                u.search = "api_token=" + config.sessions.filter((s) => s.clusterId === cls)[0].token;
+            }
         }
         u.pathname = path;
         return u.toString();
index 3e239feeaa8bb9cb27867db910b6222398e48495..e00b65b3699e12285e68501e8e3eaae35b87ac70 100644 (file)
@@ -10,7 +10,7 @@ import { RootState } from 'store/store';
 import { getResource, getResourceWithEditableStatus } from '../resources/resources';
 import { UserResource } from 'models/user';
 import { isSidePanelTreeCategory } from 'store/side-panel-tree/side-panel-tree-actions';
-import { extractUuidKind, ResourceKind, EditableResource } from 'models/resource';
+import { extractUuidKind, ResourceKind, EditableResource, Resource } from 'models/resource';
 import { Process } from 'store/processes/process';
 import { RepositoryResource } from 'models/repositories';
 import { SshKeyResource } from 'models/ssh-key';
@@ -267,3 +267,17 @@ export const resourceUuidToContextMenuKind = (uuid: string, readonly = false) =>
                 return;
         }
     };
+
+export const openSearchResultsContextMenu = (event: React.MouseEvent<HTMLElement>, uuid: string) =>
+    (dispatch: Dispatch, getState: () => RootState) => {
+        const res = getResource<Resource>(uuid)(getState().resources);
+        if (res) {
+            dispatch<any>(openContextMenu(event, {
+                name: '',
+                uuid: res.uuid,
+                ownerUuid: '',
+                kind: res.kind,
+                menuKind: ContextMenuKind.SEARCH_RESULTS,
+            }));
+        }
+    };
index 94aec140d64f2bc0b7a906465244ea29f3c3e6b6..c465aae8695a51291918aa0fd630e57fe8b327c6 100644 (file)
@@ -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
+};
diff --git a/src/views-components/context-menu/action-sets/search-results-action-set.ts b/src/views-components/context-menu/action-sets/search-results-action-set.ts
new file mode 100644 (file)
index 0000000..e916a10
--- /dev/null
@@ -0,0 +1,42 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import { ContextMenuActionSet } from "../context-menu-action-set";
+import { DetailsIcon, AdvancedIcon, OpenIcon, Link } from 'components/icon/icon';
+import { openAdvancedTabDialog } from "store/advanced-tab/advanced-tab";
+import { toggleDetailsPanel } from 'store/details-panel/details-panel-action';
+import { copyToClipboardAction, openInNewTabAction } from "store/open-in-new-tab/open-in-new-tab.actions";
+
+export const searchResultsActionSet: ContextMenuActionSet = [
+    [
+        {
+            icon: OpenIcon,
+            name: "Open in new tab",
+            execute: (dispatch, resource) => {
+                dispatch<any>(openInNewTabAction(resource));
+            }
+        },
+        {
+            icon: Link,
+            name: "Copy to clipboard",
+            execute: (dispatch, resource) => {
+                dispatch<any>(copyToClipboardAction(resource));
+            }
+        },
+        {
+            icon: DetailsIcon,
+            name: "View details",
+            execute: dispatch => {
+                dispatch<any>(toggleDetailsPanel());
+            }
+        },
+        {
+            icon: AdvancedIcon,
+            name: "Advanced",
+            execute: (dispatch, resource) => {
+                dispatch<any>(openAdvancedTabDialog(resource.uuid));
+            }
+        },
+    ]
+];
index c34087400cf5223930b806b358163e470e60741a..50ed20fd7fb01d2dc0f0cacb8850bbc5bfcec71d 100644 (file)
@@ -6,12 +6,12 @@ import React from "react";
 import copy from 'copy-to-clipboard';
 import { ListItemIcon, ListItemText, ListItem } from "@material-ui/core";
 import { Link } from "components/icon/icon";
-import { getClipboardUrl } from "./helpers";
+import { getCollectionItemClipboardUrl } from "./helpers";
 
 export const CopyToClipboardAction = (props: { href?: any, download?: any, onClick?: () => void, kind?: string, currentCollectionUuid?: string; }) => {
     const copyToClipboard = () => {
         if (props.href) {
-            const clipboardUrl = getClipboardUrl(props.href, true, true);
+            const clipboardUrl = getCollectionItemClipboardUrl(props.href, true, true);
             copy(clipboardUrl);
         }
 
index b3b7f7f8dab5208cf05047d3322061e4a44d2fa6..7776d0e5aacdf976fe081ef9cbb964dd44e04b31 100644 (file)
@@ -2,7 +2,7 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import { sanitizeToken, getClipboardUrl, getInlineFileUrl } from "./helpers";
+import { sanitizeToken, getCollectionItemClipboardUrl, getInlineFileUrl } from "./helpers";
 
 describe('helpers', () => {
     // given
@@ -22,7 +22,7 @@ describe('helpers', () => {
     describe('getClipboardUrl', () => {
         it('should add redirectTo query param', () => {
             // when
-            const result = getClipboardUrl(url);
+            const result = getCollectionItemClipboardUrl(url);
 
             // then
             expect(result).toBe('http://localhost?redirectToDownload=https://example.com/c=zzzzz-4zz18-0123456789abcde/LIMS/1.html');
index f196074d7e8770dde905e653be6e356c305ceaa5..9140e457afef89affcb573f0c84303640d4014e0 100644 (file)
@@ -14,7 +14,10 @@ export const sanitizeToken = (href: string, tokenAsQueryParam = true): string =>
     return `${[prefix, ...rest].join('/')}${tokenAsQueryParam ? `${sep}api_token=${token}` : ''}`;
 };
 
-export const getClipboardUrl = (href: string, shouldSanitizeToken = true, inline = false): string => {
+/**
+ * @returns A shareable token-free WB2 url that redirects to keep-web after login
+ */
+export const getCollectionItemClipboardUrl = (href: string, shouldSanitizeToken = true, inline = false): string => {
     const { origin } = window.location;
     const url = shouldSanitizeToken ? sanitizeToken(href, false) : href;
     const redirectKey = inline ? REDIRECT_TO_PREVIEW_KEY : REDIRECT_TO_DOWNLOAD_KEY;
index 4766259a921dfc0728040dbe111dca3f7032a7b9..a8e7fd028aa81cf477eeaa7b99d028da514f42bd 100644 (file)
@@ -111,4 +111,5 @@ export enum ContextMenuKind {
     PERMISSION_EDIT = "PermissionEdit",
     LINK = "Link",
     WORKFLOW = "Workflow",
+    SEARCH_RESULTS = "SearchResults"
 }
index d25682f6e1d8b59a07d4c91c4e8a469bd119504b..0902f15bdcca963a77369b970ff0e2d959cb31f0 100644 (file)
@@ -5,8 +5,7 @@
 import { Dispatch } from "redux";
 import { connect } from "react-redux";
 import { navigateTo } from 'store/navigation/navigation-action';
-// import { openContextMenu, resourceKindToContextMenuKind } from 'store/context-menu/context-menu-actions';
-// import { ResourceKind } from 'models/resource';
+import { openSearchResultsContextMenu } from 'store/context-menu/context-menu-actions';
 import { loadDetailsPanel } from 'store/details-panel/details-panel-action';
 import { SearchResultsPanelView } from 'views/search-results-panel/search-results-panel-view';
 import { RootState } from 'store/store';
@@ -42,7 +41,9 @@ const mapStateToProps = (rootState: RootState) => {
 };
 
 const mapDispatchToProps = (dispatch: Dispatch): SearchResultsPanelActionProps => ({
-    onContextMenu: (event, resourceUuid) => { return; },
+    onContextMenu: (event, resourceUuid) => {
+        dispatch<any>(openSearchResultsContextMenu(event, resourceUuid));
+    },
     onDialogOpen: (ownerUuid: string) => { return; },
     onItemClick: (resourceUuid: string) => {
         dispatch<any>(loadDetailsPanel(resourceUuid));