Selaa lähdekoodia

HUE-8104 [editor] FIX variables for new sample popup.

jdesjean 7 vuotta sitten
vanhempi
commit
be24b38

+ 12 - 24
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -763,26 +763,15 @@ var EditorViewModel = (function() {
           promise.cancel();
         }
       }
-      var variables = e.data.locations.reduce(function (variables, location) {
-        var re = /\${(\w*)\=?([^{}]*)}/g;
-        if (location.type === 'variable' && location.colRef) {
-          var column = location.colRef.identifierChain;
-          // TODO: This should support multiple tables, i.e. SELECT * FROM web_logs, customers WHERE id = ${id}
-          //       use "location.resolveCatalogEntry({ cancellable: true });"
-          var identifierChain = location.colRef.tables[0].identifierChain.slice().concat(column);
-          var value = re.exec(location.value);
-          variables.push({
-            path: identifierChain.map(function (identifier) {
-              return identifier.name;
-            }),
-            name: value[1]
-          });
-        }
-        return variables;
-      }, []);
       var sourceType = self.type();
-      var oVariables = variables.reduce(function (variables, variable) {
-        variables[variable.name] = variable;
+      var oLocations = e.data.locations
+      .filter(function (location) {
+        return location.type === 'variable' && location.colRef;
+      })
+      .reduce(function (variables, location) {
+        var re = /\${(\w*)\=?([^{}]*)}/g;
+        var name = re.exec(location.value)[1];
+        variables[name] = location;
         return variables;
       }, {});
       var updateVariableType = function (variable, sourceMeta) {
@@ -827,17 +816,16 @@ var EditorViewModel = (function() {
         variable.step(variablesValues.step);
       };
       self.variables().forEach(function (variable) {
-        if (oVariables[variable.name()]) {
-          DataCatalog.getEntry({ sourceType: sourceType, path: oVariables[variable.name()].path }).done(function (entry) {
-            var path = oVariables[variable.name()].path;
-            variable.path(path);
+        if (oLocations[variable.name()]) {
+          activeSourcePromises.push(oLocations[variable.name()].resolveCatalogEntry({ cancellable: true }).done(function (entry) {
+            variable.path(entry.path.join('.'));
             variable.catalogEntry = entry;
 
             activeSourcePromises.push(entry.getSourceMeta({
               silenceErrors: true,
               cancellable: true
             }).then(updateVariableType.bind(self, variable)));
-          });
+          }));
         } else {
           updateVariableType(variable, {
             type: 'text'

+ 5 - 5
desktop/libs/notebook/src/notebook/templates/editor_components.mako

@@ -1240,10 +1240,10 @@ ${ sqlSyntaxDropdown.sqlSyntaxDropdown() }
           <!-- /ko -->
           <!-- ko if: meta.type() == 'text' -->
             <!-- ko if: meta.placeholder() -->
-              <input class="input-medium" type="text" data-bind="value: value, attr: { type: type, placeholder: meta.placeholder() || '${ _ko('Variable value') }' }, valueUpdate: 'afterkeydown', event: { 'keydown': $parent.onKeydownInVariable }">
+              <input class="input-medium" type="text" data-bind="value: value, attr: { type: type, placeholder: meta.placeholder() || '${ _ko('Variable value') }' }, valueUpdate: 'afterkeydown', event: { 'keydown': $parent.onKeydownInVariable }, autogrowInput: { minWidth: 150, maxWidth: 270, comfortZone: 15 }">
             <!-- /ko -->
             <!-- ko ifnot: meta.placeholder() -->
-              <input class="input-medium" type="text" data-bind="value: value, attr: { type: type, step: step }, valueUpdate: 'afterkeydown', event: { 'keydown': $parent.onKeydownInVariable }">
+              <input class="input-medium" type="text" data-bind="value: value, attr: { type: type() || 'text', step: step }, valueUpdate: 'afterkeydown', event: { 'keydown': $parent.onKeydownInVariable }, autogrowInput: { minWidth: 150, maxWidth: 270, comfortZone: 15 }">
             <!-- /ko -->
           <!-- /ko -->
           <!-- ko if: meta.type() == 'select' -->
@@ -3253,7 +3253,7 @@ function togglePresentation(value) {};
             return location.resolvePathPromise;
           }
 
-          if (!location.identifierChain) {
+          if (!location.identifierChain && !location.colRef && !location.colRef.identifierChain) {
             if (!location.resolvePathPromise) {
               location.resolvePathPromise = $.Deferred().reject().promise();
             }
@@ -3264,8 +3264,8 @@ function togglePresentation(value) {};
             sourceType: sourceType,
             cancellable: options.cancellable,
             cachedOnly: options.cachedOnly,
-            identifierChain: location.identifierChain,
-            tables: location.tables
+            identifierChain: location.identifierChain || location.colRef.identifierChain,
+            tables: location.tables || (location.colRef && location.colRef.tables)
           });
 
           if (!options.cachedOnly) {