浏览代码

HUE-7961 [metastore] Make sure we always show at least 5 columns in the initial column list

Johan Ahlen 7 年之前
父节点
当前提交
2ef0599
共有 1 个文件被更改,包括 10 次插入10 次删除
  1. 10 10
      apps/metastore/src/metastore/static/metastore/js/metastore.model.js

+ 10 - 10
apps/metastore/src/metastore/static/metastore/js/metastore.model.js

@@ -433,26 +433,26 @@ var MetastoreTable = (function () {
         self.catalogEntry.getNavOptMeta().done(function (navOptMeta) {
           self.optimizerDetails(navOptMeta);
 
-          var topFiveIndex = {};
           var topColIndex = {};
-          for (var i = 0; i < navOptMeta.topCols.length; i++) {
-            var topCol = navOptMeta.topCols[i];
-            if (i < 5) {
-              topFiveIndex[topCol.name] = topCol;
-            }
+          navOptMeta.topCols.forEach(function (topCol) {
             topColIndex[topCol.name] = topCol;
-          }
+          });
 
           var favorites = [];
+          var nonFavorites = [];
           self.columns().forEach(function (column) {
             if (topColIndex[column.catalogEntry.name]) {
               favorites.push(column);
-            }
-            if (topColIndex[column.catalogEntry.name]) {
               column.popularity(topColIndex[column.catalogEntry.name].score);
+            } else {
+              nonFavorites.push(column);
             }
           });
-          self.favouriteColumns(favorites);
+          favorites.sort(function (colA, colB) {
+            return colB.popularity() - colA.popularity();
+          });
+
+          self.favouriteColumns(favorites.concat(nonFavorites).slice(0, 5));
         }).always(function () {
           self.loadingQueries(false);
         });