소스 검색

HUE-3890 [editor] Creating a new query should not reset the tab to query history when on saved query tab

Enrico Berti 8 년 전
부모
커밋
1dd8fee6b4

+ 6 - 3
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -2685,14 +2685,17 @@ var EditorViewModel = (function() {
       });
     };
 
-    self.newNotebook = function (editorType, callback) {
+    self.newNotebook = function (editorType, callback, queryTab) {
       $.post("/notebook/api/create_notebook", {
         type: editorType || options.editor_type,
         directory_uuid: window.location.getParameter('directory_uuid')
       }, function (data) {
         self.loadNotebook(data.notebook);
         if (self.editorMode() && !self.isNotificationManager()) {
-          self.selectedNotebook().newSnippet(self.editorType());
+          var snippet = self.selectedNotebook().newSnippet(self.editorType());
+          if (queryTab && ['queryHistory', 'savedQueries', 'queryBuilderTab'].indexOf(queryTab) > -1) {
+            snippet.currentQueryTab(queryTab);
+          }
           huePubSub.publish('detach.scrolls', self.selectedNotebook().snippets()[0]);
           if (window.location.getParameter('type') === '') {
             hueUtils.changeURLParameter('type', self.editorType());
@@ -2700,7 +2703,7 @@ var EditorViewModel = (function() {
           huePubSub.publish('active.snippet.type.changed', editorType);
         }
 
-        if (typeof callback !== 'undefined'){
+        if (typeof callback !== 'undefined' && callback !== null){
           callback();
         }
       });

+ 2 - 2
desktop/libs/notebook/src/notebook/templates/editor_components.mako

@@ -259,7 +259,7 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, ENABLE_
         <!-- /ko -->
 
         <!-- ko if: editorMode -->
-        <a class="btn" href="javascript:void(0)" data-bind="click: function() { newNotebook($root.editorType()); }, attr: { 'title': '${ _('New ') }' +  editorTypeTitle() + '${ _(' Query') }' }" rel="tooltip" data-placement="bottom">
+        <a class="btn" href="javascript:void(0)" data-bind="click: function() { newNotebook($root.editorType(), null, selectedNotebook() ? $root.selectedNotebook().snippets()[0].currentQueryTab() : null); }, attr: { 'title': '${ _('New ') }' +  editorTypeTitle() + '${ _(' Query') }' }" rel="tooltip" data-placement="bottom">
           <i class="fa fa-file-o"></i>
         </a>
         <!-- /ko -->
@@ -3229,7 +3229,7 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, ENABLE_
           viewModel.selectedNotebook().newSnippet();
         }
         else {
-          viewModel.newNotebook(viewModel.editorType());
+          viewModel.newNotebook(viewModel.editorType(), null, viewModel.selectedNotebook() ? viewModel.selectedNotebook().snippets()[0].currentQueryTab() : null);
         }
       }