[arvados-workbench2] created: 2.5.0-9-g070a998f

git repository hosting git at public.arvados.org
Thu Jan 26 17:19:05 UTC 2023


        at  070a998f625b59e09b1bedc8ee107527ad857c26 (commit)


commit 070a998f625b59e09b1bedc8ee107527ad857c26
Author: Daniel Kutyła <daniel.kutyla at contractors.roche.com>
Date:   Thu Jan 26 18:18:32 2023 +0100

    19836: inital tooltip idea
    
    Arvados-DCO-1.1-Signed-off-by: Daniel Kutyła <daniel.kutyla at contractors.roche.com>

diff --git a/src/store/store.ts b/src/store/store.ts
index 2057939e..4213143a 100644
--- a/src/store/store.ts
+++ b/src/store/store.ts
@@ -75,6 +75,7 @@ import { Config } from 'common/config';
 import { pluginConfig } from 'plugins';
 import { MiddlewareListReducer } from 'common/plugintypes';
 import { sidePanelReducer } from './side-panel/side-panel-reducer'
+import { tooltipsMiddleware } from './tooltips/tooltips-middleware';
 
 declare global {
     interface Window {
@@ -159,6 +160,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
index 00000000..982348b4
--- /dev/null
+++ b/src/store/tooltips/tooltips-middleware.ts
@@ -0,0 +1,79 @@
+// 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;
+const TOOLTIP_LOCAL_STORAGE_KEY = "TOOLTIP_LOCAL_STORAGE_KEY";
+
+export const tooltipsMiddleware = (services: ServiceRepository): Middleware => (store: Store) => next => action => {
+    const state: RootState = store.getState();
+    const result = localStorage.getItem(TOOLTIP_LOCAL_STORAGE_KEY);
+    const { BannerURL } = (state.auth.config.clusterConfig.Workbench as any);
+
+    let bannerUUID = !!BannerURL ? BannerURL : 'tordo-4zz18-1buneu6sb8zxiti';
+
+    if (bannerUUID && !tooltipsContents && !result && !tooltipsFetchFailed && !running) {
+        running = true;
+        fetchTooltips(services, bannerUUID);
+    } else if (tooltipsContents && !result && !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);
+
+        createSingleton(tippyInstances, {delay: 10});
+};
\ No newline at end of file

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list