Explorar o código

HUE-8629 [assist] Add a dedicated streams assist panel

This also takes care of an issue where the database list is visible for solr
Johan Ahlen %!s(int64=7) %!d(string=hai) anos
pai
achega
cc20c76

+ 3 - 3
desktop/core/src/desktop/static/desktop/js/assist/assistDbEntry.js

@@ -159,7 +159,7 @@ var AssistDbEntry = (function () {
     var types = {};
     if (self.parent === null) { // Only find facets on the DB level
       self.entries().forEach(function (tableEntry) {
-        if (self.assistDbNamespace.sourceType !== 'solr') {
+        if (!self.assistDbNamespace.nonSqlType) {
           if (tableEntry.catalogEntry.isTable()) {
             types.table =  types.table ? types.table + 1 : 1;
           } else if (tableEntry.catalogEntry.isView()) {
@@ -343,7 +343,7 @@ var AssistDbEntry = (function () {
           self.hasErrors(true);
         });
 
-        if (self.assistDbNamespace.sourceType !== 'solr') {
+        if (!self.assistDbNamespace.nonSqlType) {
           self.catalogEntry.loadNavigatorMetaForChildren({ silenceErrors: self.navigationSettings.rightAssist });
         }
       } else {
@@ -363,7 +363,7 @@ var AssistDbEntry = (function () {
       loadEntriesDeferred.resolve([]);
     };
 
-    if (!self.navigationSettings.rightAssist && HAS_OPTIMIZER && (self.catalogEntry.isTable() || self.catalogEntry.isDatabase()) && self.assistDbNamespace.sourceType !== 'solr') {
+    if (!self.navigationSettings.rightAssist && HAS_OPTIMIZER && (self.catalogEntry.isTable() || self.catalogEntry.isDatabase()) && !self.assistDbNamespace.nonSqlType) {
       self.catalogEntry.loadNavOptPopularityForChildren({ silenceErrors: true }).done(function () {
         loadEntriesDeferred.done(function () {
           if (!self.hasErrors()) {

+ 19 - 4
desktop/core/src/desktop/static/desktop/js/assist/assistDbSource.js

@@ -22,6 +22,7 @@ var AssistDbSource = (function () {
    * @param {ContextNamespace} [options.initialNamespace] - Optional initial namespace to use
    * @param {ContextCompute} [options.initialCompute] - Optional initial compute to use
    * @param {string} options.name
+   * @param {boolean} options.nonSqlType - Optional, default false
    * @param {Object} options.navigationSettings
    * @constructor
    */
@@ -31,6 +32,7 @@ var AssistDbSource = (function () {
     self.sourceType = options.type;
     self.name = options.name;
     self.i18n = options.i18n;
+    self.nonSqlType = options.nonSqlType;
     self.navigationSettings = options.navigationSettings;
     var apiHelper = ApiHelper.getInstance();
     self.initialNamespace = options.initialNamespace || apiHelper.getFromTotalStorage('contextSelector', 'lastSelectedNamespace');
@@ -67,9 +69,19 @@ var AssistDbSource = (function () {
       return result;
     };
 
+    var ensureDbSet = function () {
+      if (self.nonSqlType) {
+        if (!self.selectedNamespace().selectedDatabase()) {
+          self.selectedNamespace().selectedDatabase(self.selectedNamespace().databases()[0]);
+        }
+      }
+    };
+
     self.selectedNamespace.subscribe(function (namespace) {
       if (namespace && !namespace.loaded() && !namespace.loading()) {
-        namespace.initDatabases();
+        namespace.initDatabases(ensureDbSet);
+      } else {
+        ensureDbSet();
       }
     });
 
@@ -99,6 +111,7 @@ var AssistDbSource = (function () {
               sourceType: self.sourceType,
               namespace: newNamespace,
               i18n: self.i18n,
+              nonSqlType: self.nonSqlType,
               navigationSettings: self.navigationSettings
             }));
           }
@@ -132,6 +145,7 @@ var AssistDbSource = (function () {
           sourceType: self.sourceType,
           namespace: namespace,
           i18n: self.i18n,
+          nonSqlType: self.nonSqlType,
           navigationSettings: self.navigationSettings
         });
 
@@ -217,6 +231,7 @@ var AssistDbNamespace = (function () {
    * @param {Object} options.i18n
    * @param {string} options.sourceType
    * @param {ContextNamespace} options.namespace
+   * @param {boolean} options.nonSqlType - Optional, default false
    * @param {Object} options.navigationSettings
    * @constructor
    */
@@ -226,6 +241,7 @@ var AssistDbNamespace = (function () {
     self.i18n = options.i18n;
     self.navigationSettings = options.navigationSettings;
     self.sourceType = options.sourceType;
+    self.nonSqlType = options.nonSqlType;
 
     self.namespace = options.namespace;
     // TODO: Compute selection in assist?
@@ -235,7 +251,6 @@ var AssistDbNamespace = (function () {
     }
     self.name = options.namespace.name;
 
-    self.catalogEntry;
     self.dbIndex = {};
     self.databases = ko.observableArray();
     self.selectedDatabase = ko.observable();
@@ -284,7 +299,7 @@ var AssistDbNamespace = (function () {
 
     self.selectedDatabase.subscribe(function () {
       var db = self.selectedDatabase();
-      if (HAS_OPTIMIZER && db && !db.popularityIndexSet && self.sourceType !== 'solr') {
+      if (HAS_OPTIMIZER && db && !db.popularityIndexSet && !self.nonSqlType) {
         db.catalogEntry.loadNavOptPopularityForChildren({ silenceErrors: true }).done(function () {
           var applyPopularity = function () {
             db.entries().forEach(function (entry) {
@@ -382,7 +397,7 @@ var AssistDbNamespace = (function () {
             dbs.push(database);
           });
 
-          if (!hasNavMeta && self.sourceType !== 'solr') {
+          if (!hasNavMeta && !self.nonSqlType) {
             self.catalogEntry.loadNavigatorMetaForChildren({ silenceErrors: true });
           }
           self.databases(dbs);

+ 34 - 27
desktop/core/src/desktop/templates/assist.mako

@@ -89,8 +89,6 @@ from desktop.views import _ko
     <!-- ko if: typeof catalogEntry !== 'undefined' -->
       <li><a href="javascript:void(0);" data-bind="click: function (data) { showContextPopover(data, { target: $parentContext.$contextSourceElement }, { left: -15, top: 2 }); }"><i class="fa fa-fw fa-info"></i> ${ _('Show details') }</a></li>
       <!-- ko switch: sourceType -->
-      <!-- ko case: 'kafka' -->
-      <!-- /ko -->
       <!-- ko case: 'solr' -->
         <!-- ko if: catalogEntry.isTableOrView() -->
         <li><a href="javascript:void(0);" data-bind="click: openInIndexer"><i class="fa fa-fw fa-table"></i> ${ _('Open in Browser') }</a></li>
@@ -343,19 +341,6 @@ from desktop.views import _ko
     <!-- /ko -->
   </script>
 
-  <script type="text/html" id="assist-solr-inner-panel">
-    <!-- ko template: { ifnot: selectedSource, name: 'assist-sources-template' } --><!-- /ko -->
-    <!-- ko with: selectedSource -->
-      <!-- ko template: { ifnot: selectedNamespace, name: 'assist-namespaces-template' }--><!-- /ko -->
-      <!-- ko with: selectedNamespace -->
-        <!-- ko template: { ifnot: selectedDatabase, name: 'assist-databases-template' }--><!-- /ko -->
-        <!-- ko with: selectedDatabase -->
-          <!-- ko template: { name: 'assist-tables-template' } --><!-- /ko -->
-        <!-- /ko-->
-      <!-- /ko -->
-    <!-- /ko -->
-  </script>
-
   <script type="text/html" id="assist-s3-header-actions">
     <div class="assist-db-header-actions">
       <a class="inactive-action" href="javascript:void(0)" data-bind="click: function () { huePubSub.publish('assist.s3.refresh'); }"><i class="pointer fa fa-refresh" data-bind="css: { 'fa-spin blue' : loading }" title="${_('Manual refresh')}"></i></a>
@@ -1205,7 +1190,8 @@ from desktop.views import _ko
 
         self.visible = ko.observable(options.visible || true);
         options.apiHelper.withTotalStorage('assist', 'showingPanel_' + self.type, self.visible, false, options.visible);
-        self.templateName = 'assist-' + self.type + '-inner-panel';
+
+        self.templateName = 'assist-' + (['solr', 'kafka'].indexOf(self.type) !== -1 ? 'sql' : self.type) + '-inner-panel';
 
         var loadWhenVisible = function () {
           if (! self.visible()) {
@@ -1232,6 +1218,8 @@ from desktop.views import _ko
        * @param {boolean} options.navigationSettings.openItem
        * @param {boolean} options.navigationSettings.showStats
        * @param {boolean} options.navigationSettings.pinEnabled
+       * @param {boolean} [options.isSolr] - Detfault false;
+       * @param {boolean} [options.isStreams] - Detfault false;
        * @constructor
        **/
       function AssistDbPanel(options) {
@@ -1242,15 +1230,18 @@ from desktop.views import _ko
         self.initialized = false;
         self.initalizing = false;
 
+        self.isStreams = options.isStreams;
+        self.isSolr = options.isSolr;
+
         if (typeof options.sourceTypes === 'undefined') {
           options.sourceTypes = [];
 
-          if (options.isSolr) {
+          if (self.isSolr) {
             options.sourceTypes = [{
               type: 'solr',
               name: 'solr'
             }];
-          } else if (options.isKafka) {
+          } else if (self.isStreams) {
             options.sourceTypes = [{
               type: 'kafka',
               name: 'kafka'
@@ -1296,10 +1287,16 @@ from desktop.views import _ko
             i18n: self.i18n,
             type: sourceType.type,
             name: sourceType.name,
+            nonSqlType: sourceType.type === 'solr' || sourceType.type === 'kafka',
             navigationSettings: options.navigationSettings
           });
           self.sources.push(self.sourceIndex[sourceType.type]);
         });
+
+        if (self.sources().length === 1) {
+          self.selectedSource(self.sources()[0]);
+        }
+
         if (self.sourceIndex['solr']) {
           huePubSub.subscribe('assist.collections.refresh', function() {
             var namespace = self.sourceIndex['solr'].selectedNamespace();
@@ -1334,7 +1331,7 @@ from desktop.views import _ko
           }, 0);
         });
 
-        if (!options.isSolr) {
+        if (!self.isSolr && !self.isStreams) {
           huePubSub.subscribe('assist.set.database', function (databaseDef) {
             if (!databaseDef.source || !self.sourceIndex[databaseDef.source]) {
               return;
@@ -1418,7 +1415,7 @@ from desktop.views import _ko
           });
         }
 
-        if (options.isSolr) {
+        if (self.isSolr || self.isStreams) {
           if (self.sources().length === 1) {
             self.selectedSource(self.sources()[0]);
             self.selectedSource().loadNamespaces().done(function () {
@@ -1434,7 +1431,10 @@ from desktop.views import _ko
         }
 
         self.breadcrumb = ko.computed(function () {
-          if (self.selectedSource()) {
+          if (self.isStreams && self.selectedSource()) {
+            return self.selectedSource().name;
+          }
+          if (!self.isSolr && self.selectedSource()) {
             if (self.selectedSource().selectedNamespace()) {
               if (self.selectedSource().selectedNamespace().selectedDatabase()) {
                 return self.selectedSource().selectedNamespace().selectedDatabase().catalogEntry.name
@@ -1451,6 +1451,10 @@ from desktop.views import _ko
 
       AssistDbPanel.prototype.back = function () {
         var self = this;
+        if (self.isStreams) {
+          self.selectedSource(null);
+          return;
+        }
         if (self.selectedSource()) {
           if (self.selectedSource() && self.selectedSource().selectedNamespace()) {
             if (self.selectedSource().selectedNamespace().selectedDatabase()) {
@@ -1471,8 +1475,10 @@ from desktop.views import _ko
         if (self.initialized) {
           return;
         }
-        if (self.options.isSolr) {
+        if (self.isSolr) {
           self.selectedSource(self.sourceIndex['solr']);
+        } else if (self.isStreams) {
+            self.selectedSource(self.sourceIndex['kafka']);
         } else {
           var storageSourceType = self.apiHelper.getFromTotalStorage('assist', 'lastSelectedSource');
           if (!self.selectedSource()) {
@@ -1918,7 +1924,7 @@ from desktop.views import _ko
           window.setTimeout(function () {
             window.location.hash = hash;
           }, 0);
-        }
+        };
 
         self.lastClickeHBaseEntry = null;
         self.HBaseLoaded = false;
@@ -2111,19 +2117,19 @@ from desktop.views import _ko
               }
 
               if (appConfig['browser'] && appConfig['browser']['interpreter_names'].indexOf('kafka') != -1) {
-                var kafkaPanel = new AssistInnerPanel({
+                var streamsPanel = new AssistInnerPanel({
                   panelData: new AssistDbPanel($.extend({
                     apiHelper: self.apiHelper,
                     i18n: i18nCollections,
-                    isKafka: true
+                    isStreams: true
                   }, params.sql)),
                   apiHelper: self.apiHelper,
                   name: '${ _("Streams") }',
-                  type: 'solr',
+                  type: 'kafka',
                   icon: 'fa-sitemap',
                   minHeight: 75
                 });
-                panels.push(kafkaPanel);
+                panels.push(streamsPanel);
               }
 
               if (appConfig['browser'] && appConfig['browser']['interpreter_names'].indexOf('hbase') != -1) {
@@ -3475,6 +3481,7 @@ from desktop.views import _ko
             initialCompute: collection.activeCompute,
             type: collection.engine(),
             name: collection.engine(),
+            nonSqlType: true,
             navigationSettings: navigationSettings
           });