Jelajahi Sumber

HUE-5059 [metadata] Show Navigator search autocomplete on focus

Johan Ahlen 9 tahun lalu
induk
melakukan
c4de3f9

+ 10 - 2
desktop/core/src/desktop/static/desktop/js/ko.hue-bindings.js

@@ -22,7 +22,9 @@
 
       options = $.extend({
         closeOnEnter: true,
-        classPrefix: 'hue-'
+        classPrefix: 'hue-',
+        showOnFocus: false,
+        minLength: 0
       }, options);
 
       if (typeof $().hueAutocomplete === 'undefined') {
@@ -49,13 +51,19 @@
       }
 
       if (options.closeOnEnter) {
-        $element.keyup(function (e) {
+        $element.on('keyup', function (e) {
           if(e.which === 13) {
             $element.hueAutocomplete('close');
           }
         });
       }
 
+      if (options.showOnFocus) {
+        $element.on('focus', function () {
+          $element.hueAutocomplete('search', $element.val());
+        })
+      }
+
       var closeSubscription = huePubSub.subscribe('autocomplete.close', function () {
         $element.hueAutocomplete('close');
       });

+ 3 - 3
desktop/core/src/desktop/templates/assist.mako

@@ -934,7 +934,8 @@ from metadata.conf import has_navigator
         <input id="appendedInput" placeholder="${ _('Search...') }" type="text" data-bind="autocomplete: {
             source: navAutocompleteSource,
             itemTemplate: 'nav-search-autocomp-item',
-            classPrefix: 'nav-'
+            classPrefix: 'nav-',
+            showOnFocus: true
           },
           hasFocus: searchHasFocus,
           clearable: { value: searchInput, onClear: function () { huePubSub.publish('autocomplete.close'); } },
@@ -1566,7 +1567,6 @@ from metadata.conf import has_navigator
           var partial = isFacet && facetMatch[2] ? facetMatch[2] : (partialMatch ? partialMatch[0] : '');
           var beforePartial = request.term.substring(0, request.term.length - partial.length);
 
-
           self.apiHelper.navSearchAutocomplete({
             source: self.visiblePanel().type === 'sql' ?
                 (self.visiblePanel().panelData.selectedSource() ? self.visiblePanel().panelData.selectedSource().sourceType : 'hive') : self.visiblePanel().type,
@@ -1586,7 +1586,7 @@ from metadata.conf import has_navigator
               } else {
                 if (typeof data.facets !== 'undefined') {
                   Object.keys(data.facets).forEach(function (facet) {
-                    if (partial.length > 0 && facet.indexOf(partial) !== -1) {
+                    if (partial.length === 0 || facet.indexOf(partial) !== -1) {
                       values.push({ data: { label: facet + ':', icon: facetIcons[facet], description: Object.keys(data.facets[facet]).join(', ') }, value: beforePartial + facet + ':'});
                     } else if (partial.length > 0) {
                       Object.keys(data.facets[facet]).forEach(function (facetValue) {