This is an automated email from the ASF dual-hosted git repository.

beto 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 96952d0  Search queries when enter is pressed (#6043)
96952d0 is described below

commit 96952d0daf3a393f5eeac68e9b178c2253a5032a
Author: Beto Dealmeida <[email protected]>
AuthorDate: Sun Oct 7 12:48:06 2018 -0700

    Search queries when enter is pressed (#6043)
    
    * Search queries when enter is pressed
    
    * Add unit test
    
    * Remove line
    
    * Improve test
---
 .../assets/spec/javascripts/sqllab/QuerySearch_spec.jsx   | 15 +++++++++++----
 superset/assets/src/SqlLab/components/QuerySearch.jsx     |  7 +++++++
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/superset/assets/spec/javascripts/sqllab/QuerySearch_spec.jsx 
b/superset/assets/spec/javascripts/sqllab/QuerySearch_spec.jsx
index dc25604..66fbf02 100644
--- a/superset/assets/spec/javascripts/sqllab/QuerySearch_spec.jsx
+++ b/superset/assets/spec/javascripts/sqllab/QuerySearch_spec.jsx
@@ -8,6 +8,7 @@ import sinon from 'sinon';
 import QuerySearch from '../../../src/SqlLab/components/QuerySearch';
 
 describe('QuerySearch', () => {
+  const search = sinon.spy(QuerySearch.prototype, 'refreshQueries');
   const mockedProps = {
     actions: {},
     height: 0,
@@ -53,15 +54,21 @@ describe('QuerySearch', () => {
     expect(wrapper.state().searchText).to.equal('text');
   });
 
+  it('refreshes queries when enter (only) is pressed on the input', () => {
+    const callCount = search.callCount;
+    wrapper.find('input').simulate('keyDown', { keyCode: 'a'.charCodeAt(0) });
+    expect(search.callCount).to.equal(callCount);
+    wrapper.find('input').simulate('keyDown', { keyCode: '\r'.charCodeAt(0) });
+    expect(search.callCount).to.equal(callCount + 1);
+  });
+
   it('should have one Button', () => {
     expect(wrapper.find(Button)).to.have.length(1);
   });
 
   it('refreshes queries when clicked', () => {
-    const search = sinon.spy(QuerySearch.prototype, 'refreshQueries');
-    wrapper = shallow(<QuerySearch {...mockedProps} />);
+    const callCount = search.callCount;
     wrapper.find(Button).simulate('click');
-    /* eslint-disable no-unused-expressions */
-    expect(search.called).to.equal(true);
+    expect(search.callCount).to.equal(callCount + 1);
   });
 });
diff --git a/superset/assets/src/SqlLab/components/QuerySearch.jsx 
b/superset/assets/src/SqlLab/components/QuerySearch.jsx
index 17dd9b1..237ed11 100644
--- a/superset/assets/src/SqlLab/components/QuerySearch.jsx
+++ b/superset/assets/src/SqlLab/components/QuerySearch.jsx
@@ -41,6 +41,7 @@ class QuerySearch extends React.PureComponent {
     this.dbMutator = this.dbMutator.bind(this);
     this.onChange = this.onChange.bind(this);
     this.changeSearch = this.changeSearch.bind(this);
+    this.onKeyDown = this.onKeyDown.bind(this);
     this.changeFrom = this.changeFrom.bind(this);
     this.changeTo = this.changeTo.bind(this);
     this.changeStatus = this.changeStatus.bind(this);
@@ -65,6 +66,11 @@ class QuerySearch extends React.PureComponent {
     const val = db ? db.value : null;
     this.setState({ databaseId: val });
   }
+  onKeyDown(event) {
+    if (event.keyCode === 13) {
+      this.refreshQueries();
+    }
+  }
   getTimeFromSelection(selection) {
     switch (selection) {
       case 'now':
@@ -173,6 +179,7 @@ class QuerySearch extends React.PureComponent {
             <input
               type="text"
               onChange={this.changeSearch}
+              onKeyDown={this.onKeyDown}
               className="form-control input-sm"
               placeholder={t('Search Results')}
             />

Reply via email to