Merge branch '20029-collection-batch-file-operations' into main. Closes #20029 and...
authorStephen Smith <stephen@curii.com>
Fri, 17 Mar 2023 14:31:09 +0000 (10:31 -0400)
committerStephen Smith <stephen@curii.com>
Fri, 17 Mar 2023 14:31:09 +0000 (10:31 -0400)
Arvados-DCO-1.1-Signed-off-by: Stephen Smith <stephen@curii.com>

.licenseignore
cypress/fixtures/files/banner.html [new file with mode: 0644]
cypress/fixtures/files/tooltips.txt [new file with mode: 0644]
cypress/integration/banner-tooltip.spec.js [new file with mode: 0644]
cypress/support/commands.js
package.json
src/common/config.ts
src/store/store.ts
src/store/tooltips/tooltips-middleware.ts [new file with mode: 0644]
src/views-components/main-app-bar/notifications-menu.tsx
yarn.lock

index 2440cc334e144c8aecc3fa8a8952069c16634b68..2d7deb739d1d54b1a9168b05c35c7cbee81f3254 100644 (file)
@@ -16,6 +16,8 @@ src/lib/cwl-svg/*
 tools/arvados_config.yml
 cypress/fixtures/files/5mb.bin
 cypress/fixtures/files/cat.png
+cypress/fixtures/files/banner.html
+cypress/fixtures/files/tooltips.txt
 cypress/fixtures/webdav-propfind-outputs.xml
 .yarn/releases/*
 package.json
diff --git a/cypress/fixtures/files/banner.html b/cypress/fixtures/files/banner.html
new file mode 100644 (file)
index 0000000..34966bd
--- /dev/null
@@ -0,0 +1,5 @@
+<div>
+    <h1>Hi there</h1>
+    <h3>This is my amazing</h3>
+    <h5 style="color: red">Banner</h5>
+</div>
\ No newline at end of file
diff --git a/cypress/fixtures/files/tooltips.txt b/cypress/fixtures/files/tooltips.txt
new file mode 100644 (file)
index 0000000..c3c2162
--- /dev/null
@@ -0,0 +1,3 @@
+{
+    "[data-cy=side-panel-tree]": "This allows you to navigate through the app"
+}
\ No newline at end of file
diff --git a/cypress/integration/banner-tooltip.spec.js b/cypress/integration/banner-tooltip.spec.js
new file mode 100644 (file)
index 0000000..6156909
--- /dev/null
@@ -0,0 +1,116 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+describe('Collection panel tests', function () {
+    let activeUser;
+    let adminUser;
+    let collectionUUID;
+
+    before(function () {
+        // Only set up common users once. These aren't set up as aliases because
+        // aliases are cleaned up after every test. Also it doesn't make sense
+        // to set the same users on beforeEach() over and over again, so we
+        // separate a little from Cypress' 'Best Practices' here.
+        cy.getUser('admin', 'Admin', 'User', true, true)
+            .as('adminUser').then(function () {
+                adminUser = this.adminUser;
+            }
+            );
+        cy.getUser('collectionuser1', 'Collection', 'User', false, true)
+            .as('activeUser').then(function () {
+                activeUser = this.activeUser;
+            });
+            cy.on('uncaught:exception', (err, runnable) => {console.error(err)});
+    });
+
+    beforeEach(function () {
+        cy.clearCookies();
+        cy.clearLocalStorage();
+    });
+
+    it('should re-show the banner', () => {
+        setupTheEnvironment();
+
+        cy.loginAs(adminUser);
+
+        cy.wait(2000);
+
+        cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
+
+        cy.get('[title=Notifications]').click();
+        cy.get('li').contains('Restore Banner').click();
+
+        cy.wait(2000);
+
+        cy.get('[data-cy=confirmation-dialog-ok-btn]').should('be.visible');
+    });
+
+
+    it('should show tooltips and remove tooltips as localStorage key is present', () => {
+        setupTheEnvironment();
+
+        cy.loginAs(adminUser);
+
+        cy.wait(2000);
+
+        cy.get('[data-cy=side-panel-tree]').then(($el) => {
+            const el = $el.get(0) //native DOM element
+            expect(el._tippy).to.exist;
+        });
+
+        cy.wait(2000);
+
+        cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
+
+        cy.get('[title=Notifications]').click();
+        cy.get('li').contains('Disable tooltips').click();
+
+        cy.get('[data-cy=side-panel-tree]').then(($el) => {
+            const el = $el.get(0) //native DOM element
+            expect(el._tippy).to.be.undefined;
+        });
+    });
+
+    const setupTheEnvironment = () => {
+            cy.createCollection(adminUser.token, {
+                name: `BannerTooltipTest${Math.floor(Math.random() * 999999)}`,
+                owner_uuid: adminUser.user.uuid,
+            }).as('bannerCollection');
+
+            cy.getAll('@bannerCollection')
+                .then(function ([bannerCollection]) {
+
+                    collectionUUID=bannerCollection.uuid;
+
+                    cy.loginAs(adminUser);
+
+                    cy.goToPath(`/collections/${bannerCollection.uuid}`);
+
+                    cy.get('[data-cy=upload-button]').click();
+
+                    cy.fixture('files/banner.html').as('banner');
+                    cy.fixture('files/tooltips.txt').as('tooltips');
+
+                    cy.getAll('@banner', '@tooltips')
+                        .then(([banner, tooltips]) => {
+                            console.log(tooltips)
+                            cy.get('[data-cy=drag-and-drop]').upload(banner, 'banner.html', false);
+                            cy.get('[data-cy=drag-and-drop]').upload(tooltips, 'tooltips.json', false);
+                        });
+
+                    cy.get('[data-cy=form-submit-btn]').click();
+                    cy.get('[data-cy=form-submit-btn]').should('not.exist');
+                    cy.get('[data-cy=collection-files-right-panel]')
+                        .contains('banner.html').should('exist');
+                    cy.get('[data-cy=collection-files-right-panel]')
+                        .contains('tooltips.json').should('exist');
+
+                        cy.intercept({ method: 'GET', url: '**/arvados/v1/config?nocache=*' }, (req) => {
+                            req.reply((res) => {
+                                res.body.Workbench.BannerUUID = collectionUUID;
+                            });
+                        });
+                });
+    }
+});
index e98000fc71403462a2f67ffbb0008c804da5c4b0..f09d959b8fe9ac6ec35b36f35bde9e7aa36799c2 100644 (file)
@@ -387,9 +387,11 @@ Cypress.Commands.add(
     {
         prevSubject: 'element',
     },
-    (subject, file, fileName) => {
+    (subject, file, fileName, binaryMode = true) => {
         cy.window().then(window => {
-            const blob = b64toBlob(file, '', 512);
+            const blob = binaryMode
+                ? b64toBlob(file, '', 512)
+                : new Blob([file], {type: 'text/plain'});
             const testFile = new window.File([blob], fileName);
 
             cy.wrap(subject).trigger('drop', {
index 347ca0f40a652aa499c8c04c5b5fd9b8d1a5afb3..c17fc9174500db0ad7cbe43788d9c18d4c1574e4 100644 (file)
@@ -74,6 +74,7 @@
     "set-value": "2.0.1",
     "shell-escape": "^0.2.0",
     "sinon": "7.3",
+    "tippy.js": "^6.3.7",
     "tslint": "5.20.0",
     "tslint-etc": "1.6.0",
     "unionize": "2.1.2",
index a6eabdadf9b8ae409f3fa234be59a9d1ce719f82..9b0542820db85e16315f009d59c587c90f5a1f28 100644 (file)
@@ -281,16 +281,16 @@ export const mockClusterConfigJSON = (
     WebDAVDownload: { ExternalURL: '' },
     WebShell: { ExternalURL: '' },
     Workbench: {
-        DisableSharingURLsUI: false,
-        ArvadosDocsite: "",
-        FileViewersConfigURL: "",
-        WelcomePageHTML: "",
-        InactivePageHTML: "",
-        SSHHelpPageHTML: "",
-        SSHHelpHostSuffix: "",
-        SiteName: "",
-        IdleTimeout: "0s"
-    }
+      DisableSharingURLsUI: false,
+      ArvadosDocsite: "",
+      FileViewersConfigURL: "",
+      WelcomePageHTML: "",
+      InactivePageHTML: "",
+      SSHHelpPageHTML: "",
+      SSHHelpHostSuffix: "",
+      SiteName: "",
+      IdleTimeout: "0s"
+    },
   },
   Workbench: {
     DisableSharingURLsUI: false,
index 4ef5e3d0e5c45d4bb29bcc8f701f701dd65d7af7..1501fd4fb5be80db4e03d9f832e59116ec95b6f9 100644 (file)
@@ -74,6 +74,7 @@ import { ALL_PROCESSES_PANEL_ID } from './all-processes-panel/all-processes-pane
 import { Config } from 'common/config';
 import { pluginConfig } from 'plugins';
 import { MiddlewareListReducer } from 'common/plugintypes';
+import { tooltipsMiddleware } from './tooltips/tooltips-middleware';
 import { sidePanelReducer } from './side-panel/side-panel-reducer'
 import { bannerReducer } from './banner/banner-reducer';
 
@@ -160,6 +161,7 @@ export function configureStore(history: History, services: ServiceRepository, co
         routerMiddleware(history),
         thunkMiddleware.withExtraArgument(services),
         authMiddleware(services),
+        tooltipsMiddleware(services),
         projectPanelMiddleware,
         favoritePanelMiddleware,
         allProcessessPanelMiddleware,
diff --git a/src/store/tooltips/tooltips-middleware.ts b/src/store/tooltips/tooltips-middleware.ts
new file mode 100644 (file)
index 0000000..d4ea41e
--- /dev/null
@@ -0,0 +1,84 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import { CollectionDirectory, CollectionFile } from "models/collection-file";
+import { Middleware, Store } from "redux";
+import { ServiceRepository } from "services/services";
+import { RootState } from "store/store";
+import tippy, { createSingleton } from 'tippy.js';
+import 'tippy.js/dist/tippy.css';
+
+let running = false;
+let tooltipsContents = null;
+let tooltipsFetchFailed = false;
+export const TOOLTIP_LOCAL_STORAGE_KEY = "TOOLTIP_LOCAL_STORAGE_KEY";
+
+const tippySingleton = createSingleton([], {delay: 10});
+
+export const tooltipsMiddleware = (services: ServiceRepository): Middleware => (store: Store) => next => action => {
+    const state: RootState = store.getState();
+
+    if (state && state.auth && state.auth.config && state.auth.config.clusterConfig && state.auth.config.clusterConfig.Workbench) {
+        const hideTooltip = localStorage.getItem(TOOLTIP_LOCAL_STORAGE_KEY);
+        const { BannerUUID: bannerUUID } = state.auth.config.clusterConfig.Workbench;
+    
+        if (bannerUUID && !tooltipsContents && !hideTooltip && !tooltipsFetchFailed && !running) {
+            running = true;
+            fetchTooltips(services, bannerUUID);
+        } else if (tooltipsContents && !hideTooltip && !tooltipsFetchFailed) {
+            applyTooltips();
+        }
+    }
+
+    return next(action);
+};
+
+const fetchTooltips = (services, bannerUUID) => {
+    services.collectionService.files(bannerUUID)
+        .then(results => {
+            const tooltipsFile: CollectionDirectory | CollectionFile | undefined = results.find(({ name }) => name === 'tooltips.json');
+
+            if (tooltipsFile) {
+                running = true;
+                services.collectionService.getFileContents(tooltipsFile as CollectionFile)
+                    .then(data => {
+                        tooltipsContents = JSON.parse(data);
+                        applyTooltips();
+                    })
+                    .catch(() => {})
+                    .finally(() => {
+                        running = false;
+                    });
+            }  else {
+                tooltipsFetchFailed = true;
+            }
+        })
+        .catch(() => {})
+        .finally(() => {
+            running = false;
+        });
+};
+
+const applyTooltips = () => {
+    const tippyInstances: any[] = Object.keys(tooltipsContents as any)
+        .map((key) => {
+            const content = (tooltipsContents as any)[key]
+            const element = document.querySelector(key);
+
+            if (element) {
+                const hasTippyAttatched = !!(element as any)._tippy;
+
+                if (!hasTippyAttatched && tooltipsContents) {
+                    return tippy(element as any, { content });
+                }
+            }
+
+            return null;
+        })
+        .filter(data => !!data);
+
+    if (tippyInstances.length > 0) {
+        tippySingleton.setInstances(tippyInstances);
+    }
+};
\ No newline at end of file
index 30a5756f2a00998466a1ecb975409cd9a0850497..ca97a612bb11875460c17eeed6487266b9c46cf3 100644 (file)
@@ -11,6 +11,8 @@ import { NotificationIcon } from "components/icon/icon";
 import bannerActions from "store/banner/banner-action";
 import { BANNER_LOCAL_STORAGE_KEY } from "views-components/baner/banner";
 import { RootState } from "store/store";
+import { TOOLTIP_LOCAL_STORAGE_KEY } from "store/tooltips/tooltips-middleware";
+import { useCallback } from "react";
 
 const mapStateToProps = (state: RootState): NotificationsMenuProps => ({
     isOpen: state.banner.isOpen,
@@ -32,13 +34,29 @@ type NotificationsMenuComponentProps = NotificationsMenuProps & {
 
 export const NotificationsMenuComponent = (props: NotificationsMenuComponentProps) => {
     const { isOpen, openBanner } = props;
-    const result = localStorage.getItem(BANNER_LOCAL_STORAGE_KEY);
+    const bannerResult = localStorage.getItem(BANNER_LOCAL_STORAGE_KEY);
+    const tooltipResult = localStorage.getItem(TOOLTIP_LOCAL_STORAGE_KEY);
     const menuItems: any[] = [];
 
-    if (!isOpen && result) {
+    if (!isOpen && bannerResult) {
         menuItems.push(<MenuItem><span onClick={openBanner}>Restore Banner</span></MenuItem>);
     }
 
+    const toggleTooltips = useCallback(() => {
+        if (tooltipResult) {
+            localStorage.removeItem(TOOLTIP_LOCAL_STORAGE_KEY);
+        } else {
+            localStorage.setItem(TOOLTIP_LOCAL_STORAGE_KEY, 'true');
+        }
+        window.location.reload();
+    }, [tooltipResult]);
+
+    if (tooltipResult) {
+        menuItems.push(<MenuItem><span onClick={toggleTooltips}>Enable tooltips</span></MenuItem>);
+    } else {
+        menuItems.push(<MenuItem><span onClick={toggleTooltips}>Disable tooltips</span></MenuItem>);
+    }
+
     if (menuItems.length === 0) {
         menuItems.push(<MenuItem>You are up to date</MenuItem>);
     }
@@ -53,7 +71,7 @@ export const NotificationsMenuComponent = (props: NotificationsMenuComponentProp
         id="account-menu"
         title="Notifications">
         {
-            menuItems.map(item => item)
+            menuItems.map((item, i) => <div key={i}>{item}</div>)
         }
     </DropdownMenu>);
 }
index 924540208807fca8d7f7a489e8889919bddf28de..580aa8ed9243da6ecf6049fcdb91fb64d35b502a 100644 (file)
--- a/yarn.lock
+++ b/yarn.lock
@@ -2203,6 +2203,13 @@ __metadata:
   languageName: node
   linkType: hard
 
+"@popperjs/core@npm:^2.9.0":
+  version: 2.11.6
+  resolution: "@popperjs/core@npm:2.11.6"
+  checksum: 47fb328cec1924559d759b48235c78574f2d71a8a6c4c03edb6de5d7074078371633b91e39bbf3f901b32aa8af9b9d8f82834856d2f5737a23475036b16817f0
+  languageName: node
+  linkType: hard
+
 "@samverschueren/stream-to-observable@npm:^0.3.0":
   version: 0.3.1
   resolution: "@samverschueren/stream-to-observable@npm:0.3.1"
@@ -3811,6 +3818,7 @@ __metadata:
     set-value: 2.0.1
     shell-escape: ^0.2.0
     sinon: 7.3
+    tippy.js: ^6.3.7
     ts-mock-imports: 1.3.7
     tslint: 5.20.0
     tslint-etc: 1.6.0
@@ -17565,6 +17573,15 @@ __metadata:
   languageName: node
   linkType: hard
 
+"tippy.js@npm:^6.3.7":
+  version: 6.3.7
+  resolution: "tippy.js@npm:6.3.7"
+  dependencies:
+    "@popperjs/core": ^2.9.0
+  checksum: cac955318a65288e8d2dca05059878b003c6e66f92c94f7810f5bc5448eb6646abdf7dacc9bd00020e2611592598d0aae3a28ec9a45349a159603c3fdddce5fb
+  languageName: node
+  linkType: hard
+
 "tmp@npm:^0.0.33":
   version: 0.0.33
   resolution: "tmp@npm:0.0.33"