Pārlūkot izejas kodu

[notebook] Historify the snippet with the good query handle

Romain Rigaux 10 gadi atpakaļ
vecāks
revīzija
dfc53f8

+ 14 - 13
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -23,7 +23,7 @@
 }(this, function (ko, AssistHelper, Autocompleter) {
 
   var SPARK_MAPPING = {
-    ignore: ["ace", "images", "autocompleter", "selectedStatement", "assistHelpers", "user", "inFocus"]
+    ignore: ["ace", "images", "autocompleter", "selectedStatement", "assistHelpers", "user", "inFocus", "history", "availableSnippets"]
   };
 
   var Result = function (snippet, result) {
@@ -434,16 +434,6 @@
         self.close();
       }
 
-      if (notebook.type() != 'notebook') {
-        $.post("/notebook/api/historify", {
-          notebook: ko.mapping.toJSON(notebook, SPARK_MAPPING)
-        }, function(data){
-          if (vm.editorMode && data && data.status == 0 && data.id && typeof history.pushState != 'undefined'){
-            history.pushState(null, null, '/notebook/editor?editor=' + data.id);
-          }
-        });
-      }
-
       $.post("/notebook/api/execute", {
         notebook: ko.mapping.toJSON(notebook.getContext()),
         snippet: ko.mapping.toJSON(self.getContext())
@@ -465,6 +455,17 @@
       }).fail(function (xhr, textStatus, errorThrown) {
         $(document).trigger("error", xhr.responseText);
         self.status('failed');
+      })
+      .always(function() {
+        if (notebook.type() != 'notebook') {
+          $.post("/notebook/api/historify", {
+            notebook: ko.mapping.toJSON(notebook, SPARK_MAPPING)
+          }, function(data){
+            if (vm.editorMode && data && data.status == 0 && data.id && typeof history.pushState != 'undefined'){
+              history.pushState(null, null, '/notebook/editor?editor=' + data.id);
+            }
+          });
+        }
       });
     };
 
@@ -1148,8 +1149,8 @@
 
     self.availableSessionProperties = ko.computed(function () { // Only Spark
       return ko.utils.arrayFilter(options.session_properties, function (item) {
-          return item.name != ''; // Could filter out the ones already selected + yarn only or not
-        });
+        return item.name != ''; // Could filter out the ones already selected + yarn only or not
+      });
     });
     self.getSessionProperties = function(name) {
       var _prop = null;

+ 1 - 1
desktop/libs/notebook/src/notebook/views.py

@@ -79,7 +79,7 @@ def editor(request):
   else:
     editor = Notebook()
     data = editor.get_data()
-    data['name'] = '%s Query' % editor_type.title()
+    data['name'] = 'Untitled %s Query' % editor_type.title()
     data['type'] = 'query-%s' % editor_type
     editor.data = json.dumps(data)