Browse Source

HUE-8570 [editor] Enable click to insert from sample popover to SQL variables

Johan Ahlen 7 years ago
parent
commit
deb270af9a

+ 14 - 1
desktop/core/src/desktop/templates/ko_components/ko_catalog_entries_table.mako

@@ -190,7 +190,7 @@ from desktop.views import _ko
       <!-- /ko -->
 
       <!-- ko if: !loading() && catalogEntry.isField() && !catalogEntry.isComplex() -->
-      <!-- ko component: { name: 'field-samples', params: { catalogEntry: catalogEntry } } --><!-- /ko -->
+      <!-- ko component: { name: 'field-samples', params: { catalogEntry: catalogEntry, onSampleClick: onSampleClick } } --><!-- /ko -->
       <!-- /ko -->
     </div>
   </script>
@@ -268,6 +268,7 @@ from desktop.views import _ko
         self.entries = ko.observableArray();
         self.editableDescriptions = !!params.editableDescriptions;
         self.contextPopoverEnabled = !!params.contextPopoverEnabled;
+        self.onSampleClick = params.onSampleClick;
         self.querySpec = ko.observable();
         self.cancellablePromises = [];
         self.loading = ko.observable(false);
@@ -543,7 +544,12 @@ from desktop.views import _ko
       <!-- ko ifnot: loadingSamples -->
       <tbody data-bind="foreach: filteredColumnSamples">
       <tr>
+        <!-- ko if: typeof $parent.onSampleClick === 'function' -->
+        <td class="sample-column pointer" data-bind="html: $data, attr: { 'title': hueUtils.html2text($data) }, click: $parent.sampleClick"></td>
+        <!-- /ko -->
+        <!-- ko ifnot: typeof $parent.onSampleClick === 'function' -->
         <td class="sample-column" data-bind="html: $data, attr: { 'title': hueUtils.html2text($data) }"></td>
+        <!-- /ko -->
       </tr>
       </tbody>
       <!-- ko if: filteredColumnSamples().length === 0 -->
@@ -567,6 +573,8 @@ from desktop.views import _ko
       function FieldSamples (params) {
         var self = this;
         self.catalogEntry = params.catalogEntry;
+        self.onSampleClick = params.onSampleClick;
+
         self.cancellablePromises = [];
         self.querySpec = ko.observable();
 
@@ -575,6 +583,11 @@ from desktop.views import _ko
 
         self.showOperations = self.catalogEntry.getSourceType() === 'impala' || self.catalogEntry.getSourceType() === 'hive';
 
+        self.sampleClick = function (html) {
+          self.onSampleClick(hueUtils.html2text(html));
+          huePubSub.publish('context.popover.hide');
+        };
+
         self.operations = [
           {
             label: '${ _("default") }',

+ 4 - 1
desktop/core/src/desktop/templates/ko_components/ko_context_popover.mako

@@ -367,7 +367,7 @@ from metadata.conf import has_navigator
             <div class="context-popover-sql" data-bind="highlight: { value: $parent.viewSql, formatted: true, dialect: getSourceType() }"></div>
             <!-- /ko -->
             <!-- ko ifnot: $parent.viewSqlVisible -->
-            <!-- ko component: { name: 'catalog-entries-list', params: { catalogEntry: $data, onClick: $parent.catalogEntry } } --><!-- /ko -->
+            <!-- ko component: { name: 'catalog-entries-list', params: { catalogEntry: $data, onClick: $parent.catalogEntry, onSampleClick: $parent.onSampleClick } } --><!-- /ko -->
             <!-- /ko -->
           <!-- /ko -->
         </div>
@@ -536,6 +536,8 @@ from metadata.conf import has_navigator
         self.activePromises = [];
         self.errorText = ko.observable();
 
+        self.onSampleClick = options.popover.onSampleClick;
+
         self.analysis = ko.observable();
         self.comment = ko.observable();
         self.commentExpanded = ko.observable(false);
@@ -1255,6 +1257,7 @@ from metadata.conf import has_navigator
         self.compute = params.compute;
         self.defaultDatabase = params.defaultDatabase;
         self.close = hidePopover;
+        self.onSampleClick = params.onSampleClick;
         var orientation = params.orientation || 'bottom';
         self.contents = null;
         self.resizeHelper = new ResizeHelper(orientation, self.leftAdjust, self.topAdjust);

+ 1 - 0
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -3466,6 +3466,7 @@ var EditorViewModel = (function() {
           type: 'catalogEntry',
           catalogEntry: field.catalogEntry
         },
+        onSampleClick: field.value,
         showInAssistEnabled: true,
         sourceType: self.editorType(),
         orientation: 'bottom',