Эх сурвалжийг харах

HUE-9187 [ui] Prevent publishing app name to all listeners on the get current app event

Johan Ahlen 5 жил өмнө
parent
commit
33202f33bd

+ 1 - 1
desktop/core/src/desktop/js/ko/bindings/ko.appAwareTemplateContextMenu.js

@@ -21,8 +21,8 @@ import huePubSub from 'utils/huePubSub';
 ko.bindingHandlers.appAwareTemplateContextMenu = {
   init: function(element, valueAccessor, allBindings, viewModel, bindingContext) {
     viewModel.$currentApp = ko.observable('');
+    huePubSub.publish('get.current.app.name', viewModel.$currentApp);
     huePubSub.subscribe('set.current.app.name', viewModel.$currentApp);
-    huePubSub.publish('get.current.app.name');
     ko.bindingHandlers.templateContextMenu.init(
       element,
       valueAccessor,

+ 4 - 3
desktop/core/src/desktop/js/ko/components/assist/ko.rightAssistPanel.js

@@ -169,12 +169,13 @@ class RightAssistPanel {
     });
     this.disposals.push(snippetTypeSub.remove.bind(snippetTypeSub));
 
-    huePubSub.subscribe('set.current.app.name', appName => {
+    const onAppChange = appName => {
       if (appName === 'dashboard') {
         updateContentsForType(appName, false);
       }
-    });
-    huePubSub.publish('get.current.app.name');
+    };
+    huePubSub.publish('get.current.app.name', onAppChange);
+    huePubSub.subscribe('set.current.app.name', onAppChange);
     updateTabs();
   }
 

+ 2 - 2
desktop/core/src/desktop/js/onePageViewModel.js

@@ -76,8 +76,8 @@ class OnePageViewModel {
       });
     });
 
-    huePubSub.subscribe('get.current.app.name', () => {
-      huePubSub.publish('set.current.app.name', self.currentApp());
+    huePubSub.subscribe('get.current.app.name', callback => {
+      callback(self.currentApp());
     });
 
     huePubSub.subscribe('open.editor.query', resp => {

+ 8 - 9
desktop/core/src/desktop/js/sidePanelViewModel.js

@@ -61,20 +61,19 @@ class SidePanelViewModel {
       }
     });
 
-    huePubSub.subscribe('set.current.app.name', appName => {
-      if (appName === 'dashboard') {
-        self.rightAssistAvailable(true);
-      } else if (appName !== 'editor' && appName !== 'notebook') {
-        self.rightAssistAvailable(false);
-      }
-    });
+    const onAppChange = appName => {
+      self.rightAssistAvailable(
+        appName === 'dashboard' || appName === 'editor' || appName === 'notebook'
+      );
+    };
+
+    huePubSub.subscribe('set.current.app.name', onAppChange);
+    huePubSub.publish('get.current.app.name', onAppChange);
 
     huePubSub.subscribe('active.snippet.type.changed', details => {
       self.rightAssistAvailable(details.isSqlDialect || details.type === 'pig');
     });
 
-    huePubSub.publish('get.current.app.name');
-
     self.activeAppViewModel = ko.observable();
     self.currentApp = ko.observable('');
     self.templateApp = ko.pureComputed(() => {