Bladeren bron

HUE-8768 [editor] Clean up the snippet model to prepare for notebook 2

Johan Ahlen 6 jaren geleden
bovenliggende
commit
dac20a2c2c

+ 0 - 3
apps/beeswax/src/beeswax/templates/execute.mako

@@ -1168,9 +1168,6 @@ var editorViewModel = {
 var snippet = {
   type: ko.observable(snippetType),
   isSqlDialect: ko.observable(true),
-  getApiHelper: function() {
-    return apiHelper;
-  },
   database: ko.observable()
 };
 

+ 0 - 4
desktop/core/src/desktop/js/apps/notebook/snippet.js

@@ -244,10 +244,6 @@ class Snippet {
       return vm.getSnippetViewSettings(self.type()).placeHolder;
     };
 
-    self.getApiHelper = function() {
-      return apiHelper;
-    };
-
     // namespace and compute might be initialized as empty object {}
     self.namespace = ko.observable(
       snippet.namespace && snippet.namespace.id ? snippet.namespace : undefined

+ 0 - 7
desktop/core/src/desktop/js/apps/notebook/spec/aceAutocompleteWrapperSpec.js

@@ -28,13 +28,6 @@ describe('aceAutocompleteWrapper.js', () => {
         type: ko.observable('hive'),
         database: function() {
           return 'default';
-        },
-        getApiHelper: function() {
-          return {
-            loadDatabases: function(options) {
-              options.successCallback(['bla', undefined]);
-            }
-          };
         }
       }
     });

+ 1 - 1
desktop/core/src/desktop/js/apps/notebook2/editorViewModel.js

@@ -23,7 +23,7 @@ import ChartTransformers from 'apps/notebook/chartTransformers';
 import huePubSub from 'utils/huePubSub';
 import hueUtils from 'utils/hueUtils';
 
-import Notebook from 'apps/notebook2/notebook';
+import { Notebook } from 'apps/notebook2/notebook';
 import Snippet from 'apps/notebook2/snippet';
 
 class EditorViewModel {

+ 4 - 1
desktop/core/src/desktop/js/apps/notebook2/notebook.js

@@ -29,6 +29,7 @@ import Snippet from 'apps/notebook2/snippet';
 const NOTEBOOK_MAPPING = {
   ignore: [
     'ace',
+    'aceEditor',
     'aceMode',
     'autocompleter',
     'availableDatabases',
@@ -45,6 +46,8 @@ const NOTEBOOK_MAPPING = {
     'history',
     'images',
     'inFocus',
+    'parentNotebook',
+    'parentVm',
     'queries',
     'saveResultsModalVisible',
     'selectedStatement',
@@ -949,4 +952,4 @@ class Notebook {
   }
 }
 
-export default Notebook;
+export { Notebook, NOTEBOOK_MAPPING };

File diff suppressed because it is too large
+ 195 - 672
desktop/core/src/desktop/js/apps/notebook2/snippet.js


+ 1 - 1
desktop/core/src/desktop/js/ko/bindings/ko.aceResizer.js

@@ -22,7 +22,7 @@ import huePubSub from 'utils/huePubSub';
 ko.bindingHandlers.aceResizer = {
   init: function(element, valueAccessor) {
     const options = ko.unwrap(valueAccessor());
-    const ace = options.snippet.ace;
+    const ace = options.snippet.ace.bind(options.snippet);
     const $target = $(options.target);
     const $resizer = $(element);
     const $contentPanel = $('.content-panel');

+ 37 - 27
desktop/core/src/desktop/js/parse/spec/sqlAutocompleteParser_Locations_Spec.js

@@ -1861,34 +1861,38 @@ describe('sqlAutocompleteParser.js locations', () => {
   it('should report definitions for "CREATE DATABASE boo; |"', () => {
     assertLocations({
       dialect: 'impala',
-      beforeCursor: "CREATE DATABASE boo;",
+      beforeCursor: 'CREATE DATABASE boo;',
       expectedLocations: [
         {
           type: 'statement',
           location: { first_line: 1, last_line: 1, first_column: 1, last_column: 20 }
-        }, {
+        },
+        {
           type: 'statementType',
           location: { first_line: 1, last_line: 1, first_column: 1, last_column: 7 },
           identifier: 'CREATE DATABASE'
         }
       ],
-      expectedDefinitions: [{
-        type: 'database',
-        location: { first_line: 1, last_line: 1, first_column: 17, last_column: 20 },
-        identifierChain: [{ name: 'boo' }]
-      }]
+      expectedDefinitions: [
+        {
+          type: 'database',
+          location: { first_line: 1, last_line: 1, first_column: 17, last_column: 20 },
+          identifierChain: [{ name: 'boo' }]
+        }
+      ]
     });
   });
 
   it('should report definitions for "CREATE TABLE boo (id int, foo bigint, bar varchar); |"', () => {
     assertLocations({
       dialect: 'impala',
-      beforeCursor: "CREATE TABLE boo (id int, foo bigint, bar string);",
+      beforeCursor: 'CREATE TABLE boo (id int, foo bigint, bar string);',
       expectedLocations: [
         {
           type: 'statement',
           location: { first_line: 1, last_line: 1, first_column: 1, last_column: 50 }
-        }, {
+        },
+        {
           type: 'statementType',
           location: { first_line: 1, last_line: 1, first_column: 1, last_column: 7 },
           identifier: 'CREATE TABLE'
@@ -1899,19 +1903,23 @@ describe('sqlAutocompleteParser.js locations', () => {
           type: 'table',
           location: { first_line: 1, last_line: 1, first_column: 14, last_column: 17 },
           identifierChain: [{ name: 'boo' }],
-          columns: [{
-            identifierChain: [{ name: 'id' }],
-            type: 'int',
-            location: { first_line: 1, last_line: 1, first_column: 19, last_column: 21 }
-          }, {
-            identifierChain: [{ name: 'foo' }],
-            type: 'bigint',
-            location: { first_line: 1, last_line: 1, first_column: 27, last_column: 30 }
-          }, {
-            identifierChain: [{ name: 'bar' }],
-            type: 'string',
-            location: { first_line: 1, last_line: 1, first_column: 39, last_column: 42 }
-          }]
+          columns: [
+            {
+              identifierChain: [{ name: 'id' }],
+              type: 'int',
+              location: { first_line: 1, last_line: 1, first_column: 19, last_column: 21 }
+            },
+            {
+              identifierChain: [{ name: 'foo' }],
+              type: 'bigint',
+              location: { first_line: 1, last_line: 1, first_column: 27, last_column: 30 }
+            },
+            {
+              identifierChain: [{ name: 'bar' }],
+              type: 'string',
+              location: { first_line: 1, last_line: 1, first_column: 39, last_column: 42 }
+            }
+          ]
         }
       ]
     });
@@ -1966,11 +1974,13 @@ describe('sqlAutocompleteParser.js locations', () => {
             type: 'table',
             location: { first_line: 1, last_line: 1, first_column: 14, last_column: 17 },
             identifierChain: [{ name: 'bla' }],
-            columns: [{
-              identifierChain: [{ name: 'id' }],
-              type: 'INT',
-              location: { first_line: 1, last_line: 1, first_column: 19, last_column: 21 }
-            }]
+            columns: [
+              {
+                identifierChain: [{ name: 'id' }],
+                type: 'INT',
+                location: { first_line: 1, last_line: 1, first_column: 19, last_column: 21 }
+              }
+            ]
           }
         ]
       });

+ 8 - 8
desktop/core/src/desktop/js/parse/sqlParseSupport.js

@@ -2170,24 +2170,24 @@ const initSqlParser = function(parser) {
     return loc;
   };
 
-  parser.addNewDatabaseLocation = function (location, identifierChain) {
+  parser.addNewDatabaseLocation = function(location, identifierChain) {
     parser.yy.definitions.push({
       type: 'database',
       location: adjustLocationForCursor(location),
       identifierChain: identifierChain
-    })
+    });
   };
 
-  parser.addNewTableLocation = function (location, identifierChain, colSpec) {
-    var columns = [];
+  parser.addNewTableLocation = function(location, identifierChain, colSpec) {
+    const columns = [];
     if (colSpec) {
-      colSpec.forEach(function (col) {
+      colSpec.forEach(col => {
         columns.push({
-          identifierChain: [ col.identifier ], // TODO: Complex
+          identifierChain: [col.identifier], // TODO: Complex
           type: col.type,
           location: adjustLocationForCursor(col.location)
-        })
-      })
+        });
+      });
     }
     parser.yy.definitions.push({
       type: 'table',

+ 0 - 4
desktop/core/src/desktop/js/utils/spec/hdfsAutocompleterSpec.js

@@ -18,7 +18,6 @@ import $ from 'spec/jquery.test';
 import 'spec/jquery.plugins';
 import ko from 'knockout';
 
-import apiHelper from 'api/apiHelper';
 import HdfsAutocompleter from '../hdfsAutocompleter';
 import SqlTestUtils from 'parse/spec/sqlTestUtils';
 
@@ -37,9 +36,6 @@ describe('hdfsAutocompleter.js', () => {
     },
     getContext: function() {
       return ko.mapping.fromJS(null);
-    },
-    getApiHelper: function() {
-      return apiHelper;
     }
   };
 

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

@@ -1183,7 +1183,7 @@ ${ sqlSyntaxDropdown.sqlSyntaxDropdown() }
           minLines: $root.editorMode() ? null : 3
         }
       }, style: {opacity: statementType() !== 'text' || $root.isPresentationMode() ? '0.75' : '1', 'min-height': $root.editorMode() ? '0' : '48px', 'top': $root.editorMode() && statementType() !== 'text' ? '60px' : '0'}"></div>
-      <!-- ko component: { name: 'hueAceAutocompleter', params: { editor: ace, snippet: $data } } --><!-- /ko -->
+      <!-- ko component: { name: 'hueAceAutocompleter', params: { editor: ace.bind($data), snippet: $data } } --><!-- /ko -->
 
       <ul class="table-drop-menu hue-context-menu">
         <li class="editor-drop-value"><a href="javascript:void(0);">"<span class="editor-drop-identifier"></span>"</a></li>

Some files were not shown because too many files changed in this diff