Ver Fonte

HUE-6976 [editor] Add a fix action to the missing filters risk

Johan Ahlen há 8 anos atrás
pai
commit
2ca6587a3f

Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
desktop/core/src/desktop/static/desktop/css/hue.css


Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
desktop/core/src/desktop/static/desktop/css/hue3-extra.css


+ 4 - 0
desktop/core/src/desktop/static/desktop/less/hue-assist.less

@@ -975,5 +975,9 @@
       white-space: normal;
       font-style: italic;
     }
+
+    .risk-quickfix {
+      margin-left: 5px;
+    }
   }
 }

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

@@ -1944,6 +1944,9 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, get_ord
             <li>
               <div class="risk-list-title" data-bind="css: { 'risk-list-high' : risk === 'high', 'risk-list-normal':  risk !== 'high' }, tooltip: { title: risk + ' ' + riskTables }"><span data-bind="text: riskAnalysis"></span></div>
               <div class="risk-list-description" data-bind="text: riskRecommendation"></div>
+              <div class="risk-quickfix" data-bind="visible: riskId === 17 && $parent.activeEditor() && $parent.activeLocations(), with: $parent" style="display:none;">
+                <a href="javascript:void(0);" data-bind="click: addFilter">${ _('Add filter') }</a>
+              </div>
             </li>
           </ul>
           <!-- /ko -->
@@ -1975,11 +1978,13 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, get_ord
         self.activeStatement = ko.observable();
         self.activeTables = ko.observableArray();
         self.activeRisks = ko.observable({});
+        self.activeEditor = ko.observable();
         self.activeRisks.subscribe(function() {
           if (self.isMissingDDL()) {
             self.uploadTableStats(false);
           }
         });
+        self.activeLocations = ko.observable();
         self.statementCount = ko.observable(0);
         self.activeStatementIndex = ko.observable(0);
 
@@ -2054,8 +2059,10 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, get_ord
         var handleLocationUpdate = function (activeLocations) {
           assistDbSource.sourceType = activeLocations.type;
           if (!activeLocations) {
+            self.activeLocations(undefined);
             return;
           }
+          self.activeLocations(activeLocations);
           self.statementCount(activeLocations.totalStatementCount);
           self.activeStatementIndex(activeLocations.activeStatementIndex);
 
@@ -2129,10 +2136,14 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, get_ord
 
         var activeLocationsSub = huePubSub.subscribe('editor.active.locations', handleLocationUpdate);
 
-        var activeRisksSub = huePubSub.subscribe('editor.active.risks', self.activeRisks);
+        var activeRisksSub = huePubSub.subscribe('editor.active.risks', function (details) {
+          self.activeRisks(details.risks);
+          self.activeEditor(details.editor);
+        });
 
-        huePubSub.publish('editor.get.active.risks', function (risks) {
-          self.activeRisks(risks || {});
+        huePubSub.publish('editor.get.active.risks', function (details) {
+          self.activeRisks(details.risks);
+          self.activeEditor(details.editor);
         });
 
         self.disposals.push(function () {
@@ -2142,6 +2153,35 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, get_ord
 
       }
 
+      AssistantPanel.prototype.addFilter = function () {
+        var self = this;
+        if (self.activeLocations() && self.activeEditor()) {
+          self.activeLocations().locations.every(function (location) {
+            if (location.type === 'whereClause' && location.missing) {
+
+              self.activeEditor().moveCursorToPosition({
+                row: location.location.last_line - 1,
+                column: location.location.last_column - 1
+              });
+              self.activeEditor().clearSelection();
+
+              if (/\S$/.test(self.activeEditor().getTextBeforeCursor())) {
+                self.activeEditor().session.insert(self.activeEditor().getCursorPosition(), ' ');
+              }
+              self.activeEditor().session.insert(self.activeEditor().getCursorPosition(), 'where ');
+              self.activeEditor().focus();
+
+              window.setTimeout(function () {
+                self.activeEditor().execCommand("startAutocomplete");
+              }, 1);
+
+              return false;
+            }
+            return true;
+          })
+        }
+      };
+
       AssistantPanel.prototype.uploadTableStats = function (showProgress) {
         var self = this;
         if (self.uploadingTableStats()) {

+ 8 - 2
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -996,7 +996,10 @@ var EditorViewModel = (function() {
         self.complexityCheckRunning(true);
         self.hasSuggestion(null);
         self.complexity({});
-        huePubSub.publish('editor.active.risks', {});
+        huePubSub.publish('editor.active.risks', {
+          editor: self.ace(),
+          risks: {}
+        });
 
         var changeSubscription = self.statement.subscribe(function () {
           changeSubscription.dispose();
@@ -1020,7 +1023,10 @@ var EditorViewModel = (function() {
               self.hasSuggestion('error');
               self.complexity({'hints': []});
             }
-            huePubSub.publish('editor.active.risks', self.complexity());
+            huePubSub.publish('editor.active.risks', {
+              editor: self.ace(),
+              risks: self.complexity() || {}
+            });
             lastCheckedComplexityStatement = self.statement();
           },
           always: function(data) {

+ 10 - 3
desktop/libs/notebook/src/notebook/templates/editor_components.mako

@@ -3485,19 +3485,26 @@ ${ sqlSyntaxDropdown.sqlSyntaxDropdown() }
       }, HUE_PUB_SUB_EDITOR_ID);
 
       huePubSub.subscribe('editor.get.active.risks', function (callback) {
+        var result = {
+          editor: undefined,
+          risks : {}
+        };
         if (viewModel.selectedNotebook()) {
           if (viewModel.selectedNotebook().snippets().length === 1) {
-            callback(viewModel.selectedNotebook().snippets()[0].complexity());
+            result.editor = viewModel.selectedNotebook().snippets()[0].ace();
+            result.risks = viewModel.selectedNotebook().snippets()[0].complexity() || {};
           } else {
-            viewModel.selectedNotebook().snippets().every(function (snippet) {
+            var notFound = viewModel.selectedNotebook().snippets().every(function (snippet) {
               if (snippet.inFocus()) {
-                callback(snippet.complexity());
+                result.editor = snippet.ace();
+                result.risks = snippet.complexity() || {};
                 return false;
               }
               return true;
             });
           }
         }
+        callback(result);
       });
 
       $(document).on("gridShown", function (e, snippet) {

Alguns ficheiros não foram mostrados porque muitos ficheiros mudaram neste diff