15768: initial Arvados-DCO-1.1-Signed-off-by: Lisa Knox <lisa.knox@curii.com>
[arvados.git] / src / store / tooltips / tooltips-middleware.ts
index 982348b48d2015e0c8884c29a14d234d8fb755d6..d4ea41ee51f08395f22b23502e18f2ebb48292ed 100644 (file)
@@ -12,20 +12,23 @@ 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 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();
-    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();
+    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);
@@ -75,5 +78,7 @@ const applyTooltips = () => {
         })
         .filter(data => !!data);
 
-        createSingleton(tippyInstances, {delay: 10});
+    if (tippyInstances.length > 0) {
+        tippySingleton.setInstances(tippyInstances);
+    }
 };
\ No newline at end of file