superset-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maximebeauche...@apache.org
Subject [incubator-superset] branch master updated: [sql lab] ctrl-r hotkey should run latest SQL (#4719)
Date Thu, 29 Mar 2018 21:32:07 GMT
This is an automated email from the ASF dual-hosted git repository.

maximebeauchemin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git


The following commit(s) were added to refs/heads/master by this push:
     new ed9a56b  [sql lab] ctrl-r hotkey should run latest SQL (#4719)
ed9a56b is described below

commit ed9a56b4ab050f1a95a0e13cfce0c284d857605b
Author: Maxime Beauchemin <maximebeauchemin@gmail.com>
AuthorDate: Thu Mar 29 14:32:03 2018 -0700

    [sql lab] ctrl-r hotkey should run latest SQL (#4719)
    
    Turns out the SQL would only be committed to the redux store `onBlur`
    event to avoid the laggy typing. The delay come from the localStorage
    binding that add enough millisecs of delay to feel odd while typing.
    
    I now store the most recent SQL in the local and use that instead.
---
 .../javascripts/SqlLab/components/AceEditorWrapper.jsx       | 12 ++++++++----
 superset/assets/javascripts/SqlLab/components/SqlEditor.jsx  | 11 +++++++++--
 2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/superset/assets/javascripts/SqlLab/components/AceEditorWrapper.jsx b/superset/assets/javascripts/SqlLab/components/AceEditorWrapper.jsx
index 24e9e25..9a9b037 100644
--- a/superset/assets/javascripts/SqlLab/components/AceEditorWrapper.jsx
+++ b/superset/assets/javascripts/SqlLab/components/AceEditorWrapper.jsx
@@ -37,10 +37,12 @@ const propTypes = {
     descr: PropTypes.string.isRequired,
     func: PropTypes.func.isRequired,
   })),
+  onChange: PropTypes.func,
 };
 
 const defaultProps = {
   onBlur: () => {},
+  onChange: () => {},
   tables: [],
 };
 
@@ -51,6 +53,7 @@ class AceEditorWrapper extends React.PureComponent {
       sql: props.sql,
       selectedText: '',
     };
+    this.onChange = this.onChange.bind(this);
   }
   componentDidMount() {
     // Making sure no text is selected from previous mount
@@ -97,6 +100,10 @@ class AceEditorWrapper extends React.PureComponent {
       }
     });
   }
+  onChange(text) {
+    this.setState({ sql: text });
+    this.props.onChange(text);
+  }
   getCompletions(aceEditor, session, pos, prefix, callback) {
     callback(null, this.state.words);
   }
@@ -125,9 +132,6 @@ class AceEditorWrapper extends React.PureComponent {
       }
     });
   }
-  textChange(text) {
-    this.setState({ sql: text });
-  }
   render() {
     return (
       <AceEditor
@@ -136,7 +140,7 @@ class AceEditorWrapper extends React.PureComponent {
         onLoad={this.onEditorLoad.bind(this)}
         onBlur={this.onBlur.bind(this)}
         height={this.props.height}
-        onChange={this.textChange.bind(this)}
+        onChange={this.onChange}
         width="100%"
         editorProps={{ $blockScrolling: true }}
         enableLiveAutocompletion
diff --git a/superset/assets/javascripts/SqlLab/components/SqlEditor.jsx b/superset/assets/javascripts/SqlLab/components/SqlEditor.jsx
index 57be300..04f1fd1 100644
--- a/superset/assets/javascripts/SqlLab/components/SqlEditor.jsx
+++ b/superset/assets/javascripts/SqlLab/components/SqlEditor.jsx
@@ -53,12 +53,15 @@ class SqlEditor extends React.PureComponent {
     this.state = {
       autorun: props.queryEditor.autorun,
       ctas: '',
+      sql: props.queryEditor.sql,
     };
 
     this.onResize = this.onResize.bind(this);
     this.throttledResize = throttle(this.onResize, 250);
     this.runQuery = this.runQuery.bind(this);
     this.stopQuery = this.stopQuery.bind(this);
+    this.onSqlChanged = this.onSqlChanged.bind(this);
+    this.setQueryEditorSql = this.setQueryEditorSql.bind(this);
   }
   componentWillMount() {
     if (this.state.autorun) {
@@ -88,6 +91,9 @@ class SqlEditor extends React.PureComponent {
       this.props.actions.persistEditorHeight(this.props.queryEditor, this.refs.ace.clientHeight);
     }
   }
+  onSqlChanged(sql) {
+    this.setState({ sql });
+  }
   getHotkeyConfig() {
     return [
       {
@@ -126,7 +132,7 @@ class SqlEditor extends React.PureComponent {
     const qe = this.props.queryEditor;
     const query = {
       dbId: qe.dbId,
-      sql: qe.selectedText ? qe.selectedText : qe.sql,
+      sql: qe.selectedText ? qe.selectedText : this.state.sql,
       sqlEditorId: qe.id,
       tab: qe.title,
       schema: qe.schema,
@@ -301,7 +307,8 @@ class SqlEditor extends React.PureComponent {
                 <div>
                   <AceEditorWrapper
                     actions={this.props.actions}
-                    onBlur={this.setQueryEditorSql.bind(this)}
+                    onBlur={this.setQueryEditorSql}
+                    onChange={this.onSqlChanged}
                     queryEditor={this.props.queryEditor}
                     sql={this.props.queryEditor.sql}
                     tables={this.props.tables}

-- 
To stop receiving notification emails like this one, please contact
maximebeauchemin@apache.org.

Mime
View raw message