Преглед изворни кода

HUE-7738 [editor] Switch to the async functions repository in the function context popover

Johan Ahlen пре 5 година
родитељ
комит
2bface0f0b

+ 3 - 0
desktop/core/src/desktop/js/ko/bindings/ace/aceLocationHandler.js

@@ -384,6 +384,7 @@ class AceLocationHandler {
                     catalogEntry: entry
                   },
                   pinEnabled: true,
+                  connector: self.snippet.connector(),
                   source: source
                 });
               })
@@ -401,6 +402,7 @@ class AceLocationHandler {
                     storageEntry: entry,
                     editorLocation: token.parseLocation.location
                   },
+                  connector: self.snippet.connector(),
                   pinEnabled: true,
                   source: source
                 });
@@ -408,6 +410,7 @@ class AceLocationHandler {
             } else {
               huePubSub.publish('context.popover.show', {
                 data: token.parseLocation,
+                connector: self.snippet.connector(),
                 sourceType: self.dialect(),
                 namespace: self.snippet.namespace(),
                 compute: self.snippet.compute(),

+ 18 - 14
desktop/core/src/desktop/js/ko/components/contextPopover/functionContext.js

@@ -17,47 +17,51 @@
 import * as ko from 'knockout';
 
 import I18n from 'utils/i18n';
-import { SqlFunctions } from 'sql/sqlFunctions';
+import { findFunction } from 'sql/reference/sqlReferenceRepository';
 
 const TEMPLATE_NAME = 'context-popover-function-details';
 
 // prettier-ignore
 export const FUNCTION_CONTEXT_TEMPLATE = `
 <script type="text/html" id="context-popover-function-details">
-  <!-- ko if: typeof details === 'undefined' -->
+  <!-- ko ifnot: details -->
   <div class="context-popover-flex-fill">
     <div class="alert">${ I18n('Could not find details for the function') } <span data-bind="text: $parents[2].title"></span>()</div>
   </div>
   <!-- /ko -->
-  <!-- ko if: typeof details !== 'undefined' -->
   <div class="context-popover-flex-fill" data-bind="with: details">
     <div style="padding: 8px">
       <p style="margin: 10px 10px 18px 10px;"><span style="white-space: pre;" class="monospace" data-bind="text: signature"></span></p>
       <p><span data-bind="text: description"></span></p>
     </div>
   </div>
-  <!-- /ko -->
 </script>
 `;
 
 class FunctionContextTabs {
-  constructor(data, sourceType) {
-    const self = this;
-    self.func = ko.observable({
-      details: SqlFunctions.findFunction(sourceType, data.function),
-      loading: ko.observable(false),
-      hasErrors: ko.observable(false)
-    });
+  constructor(data, connector) {
+    this.details = ko.observable();
+    this.loading = ko.observable(true);
+    this.hasErrors = ko.observable(false);
+
+    findFunction(connector, data.function)
+      .then(this.details)
+      .catch(() => {
+        this.hasErrors(true);
+      })
+      .finally(() => {
+        this.loading(false);
+      });
 
-    self.tabs = [
+    this.tabs = [
       {
         id: 'details',
         label: I18n('Details'),
         template: TEMPLATE_NAME,
-        templateData: self.func
+        templateData: this
       }
     ];
-    self.activeTab = ko.observable('details');
+    this.activeTab = ko.observable('details');
   }
 }
 

+ 2 - 1
desktop/core/src/desktop/js/ko/components/contextPopover/ko.contextPopover.js

@@ -581,6 +581,7 @@ class ContextPopoverViewModel {
     self.topAdjust = ko.observable(0);
 
     self.data = params.data;
+    self.connector = params.connector;
     self.sourceType = params.sourceType;
     self.namespace = params.namespace;
     self.compute = params.compute;
@@ -715,7 +716,7 @@ class ContextPopoverViewModel {
       self.titleTemplate = 'context-catalog-entry-title';
       self.contentsTemplate = 'context-catalog-entry-contents';
     } else if (self.isFunction) {
-      self.contents = new FunctionContextTabs(self.data, self.sourceType);
+      self.contents = new FunctionContextTabs(self.data, self.connector);
       self.title = self.data.function;
       self.iconClass = 'fa-superscript';
     } else if (self.isStorageEntry) {