[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.
This commit is contained in:
Maxime Beauchemin
2018-03-29 14:32:03 -07:00
committed by GitHub
parent 9ee78d16d4
commit ed9a56b4ab
2 changed files with 17 additions and 6 deletions

View File

@@ -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}