瀏覽代碼

HUE-3955 [editor] Saving a query should update its description in the saved query list

Enrico Berti 8 年之前
父節點
當前提交
143327fd75

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

@@ -392,7 +392,7 @@ var EditorViewModel = (function() {
       lastFetchQueriesRequest = self.getApiHelper().searchDocuments({
         successCallback: function (result) {
           self.queriesTotalPages(Math.ceil(result.count / QUERIES_PER_PAGE));
-          self.queries(result.documents);
+          self.queries(ko.mapping.fromJS(result.documents)());
           self.loadingQueries(false);
           self.queriesHasErrors(false);
         },
@@ -1917,14 +1917,18 @@ var EditorViewModel = (function() {
           self.isHistory(false);
           $(document).trigger("info", data.message);
           if (vm.editorMode()) {
-            if (! data.save_as && self.snippets()[0].queries().length != 0) {
-              self.snippets()[0].queries.unshift({
-                'uuid': data.uuid,
-                'name': data.name,
-                'description': data.description,
-                'owner': data.owner,
-                'last_modified': data.last_modified
+            if (data.save_as) {
+              var existingQuery = self.snippets()[0].queries().filter(function (item) {
+                return item.uuid() === data.uuid
               });
+              if (existingQuery.length > 0) {
+                existingQuery[0].name(data.name);
+                existingQuery[0].description(data.description);
+                existingQuery[0].last_modified(data.last_modified);
+              }
+            }
+            else {
+              self.snippets()[0].queries.unshift(ko.mapping.fromJS(data));
             }
 
             if (self.coordinatorUuid()) {

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

@@ -832,11 +832,11 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, ENABLE_
               </tr>
             </thead>
             <tbody data-bind="foreach: queries">
-            <tr data-bind="click: function() { if (uuid != $root.selectedNotebook().uuid()) { $root.openNotebook(uuid, 'savedQueries'); } }, css: { 'highlight': uuid == $root.selectedNotebook().uuid(), 'pointer': uuid != $root.selectedNotebook().uuid() }">
-              <td style="width: 16%"><span data-bind="ellipsis: {data: name, length: 50}"></span></td>
+            <tr data-bind="click: function() { if (uuid() != $root.selectedNotebook().uuid()) { $root.openNotebook(uuid(), 'savedQueries'); } }, css: { 'highlight': uuid() == $root.selectedNotebook().uuid(), 'pointer': uuid() != $root.selectedNotebook().uuid() }">
+              <td style="width: 16%"><span data-bind="ellipsis: {data: name(), length: 50}"></span></td>
               <td style="width: 50%; white-space: normal"><span data-bind="text: description"></span></td>
               <td style="width: 18%"><span data-bind="text: owner"></span></td>
-              <td style="width: 16%"><span data-bind="text: localeFormat(last_modified)"></span></td>
+              <td style="width: 16%"><span data-bind="text: localeFormat(last_modified())"></span></td>
             </tr>
             </tbody>
           </table>