Răsfoiți Sursa

HUE-3470 [editor] Clearing history should delete current query if it is an history

Romain Rigaux 9 ani în urmă
părinte
comite
a5f72ee

+ 4 - 3
desktop/libs/notebook/src/notebook/api.py

@@ -93,6 +93,8 @@ def execute(request):
       if 'handle' in response: # No failure
         _snippet['result']['handle'] = response['handle']
         _snippet['result']['statements_count'] = response['handle']['statements_count']
+      else:
+        _snippet['status'] = 'failed'
       history = _historify(notebook, request.user)
       response['history_id'] = history.id
 
@@ -311,12 +313,11 @@ def clear_history(request):
   notebook = json.loads(request.POST.get('notebook'), '{}')
   doc_type = request.POST.get('doc_type')
 
-  response['status'] = 0
   history = Document2.objects.get_history(doc_type='query-%s' % doc_type, user=request.user)
-  if notebook.get('id'):
-    history = history.exclude(id=notebook.get('id'))
+
   response['updated'] = history.delete()
   response['message'] = _('History cleared !')
+  response['status'] = 0
 
   return JsonResponse(response)
 

+ 1 - 0
desktop/libs/notebook/src/notebook/connectors/base.py

@@ -71,6 +71,7 @@ class Notebook(object):
 
     if self.document is not None:
       _data['id'] = self.document.id
+      _data['is_history'] = self.document.is_history
 
     return _data
 

+ 10 - 5
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -962,6 +962,7 @@
     self.name = ko.observable(typeof notebook.name != "undefined" && notebook.name != null ? notebook.name : 'My Notebook');
     self.description = ko.observable(typeof notebook.description != "undefined" && notebook.description != null ? notebook.description: '');
     self.type = ko.observable(typeof notebook.type != "undefined" && notebook.type != null ? notebook.type : 'notebook');
+    self.isHistory = ko.observable(typeof notebook.is_history != "undefined" && notebook.is_history != null ? notebook.is_history : false);
     self.snippets = ko.observableArray();
     self.selectedSnippet = ko.observable(vm.availableSnippets().length > 0 ? vm.availableSnippets()[0].type() : 'NO_SNIPPETS');
     self.creatingSessionLocks = ko.observableArray();
@@ -1261,11 +1262,15 @@
         notebook: ko.mapping.toJSON(self.getContext()),
         doc_type: self.selectedSnippet()
       }, function (data) {
-          self.history.removeAll();
-          self.showHistory(false);
-        }).fail(function (xhr) {
-           $(document).trigger("error", xhr.responseText);
-        });
+        self.history.removeAll();
+        self.showHistory(false);
+        if (self.isHistory()) {
+          self.id(null);
+          self.uuid(UUID());
+        }
+      }).fail(function (xhr) {
+        $(document).trigger("error", xhr.responseText);
+      });
       $(document).trigger("hideHistoryModal");
     };