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: minor filter select enhancements (#3933)
Date Tue, 28 Nov 2017 05:05:55 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 f9202ba  minor filter select enhancements (#3933)
f9202ba is described below

commit f9202ba179ac0fc2f78451a8c36a338b165a287b
Author: kkalyan <kalyan.kumar@gmail.com>
AuthorDate: Mon Nov 27 21:05:53 2017 -0800

    minor filter select enhancements (#3933)
    
    * `values_for_column` configurable row limit
    
    * `FilterControl` cancels active ajax request if any
---
 .../explore/components/controls/FilterControl.jsx  | 27 +++++++++++-------
 .../explore/components/FilterControl_spec.jsx      | 32 +++++++++++++++++++++-
 superset/config.py                                 |  2 ++
 superset/views/core.py                             |  5 +++-
 4 files changed, 54 insertions(+), 12 deletions(-)

diff --git a/superset/assets/javascripts/explore/components/controls/FilterControl.jsx b/superset/assets/javascripts/explore/components/controls/FilterControl.jsx
index 80f43ca..041dd6f 100644
--- a/superset/assets/javascripts/explore/components/controls/FilterControl.jsx
+++ b/superset/assets/javascripts/explore/components/controls/FilterControl.jsx
@@ -28,6 +28,7 @@ export default class FilterControl extends React.Component {
     }));
     this.state = {
       filters: initialFilters,
+      activeRequest: null,
     };
   }
 
@@ -45,16 +46,22 @@ export default class FilterControl extends React.Component {
         newStateFilters[index].valuesLoading = true;
         return { filters: newStateFilters };
       });
-      $.ajax({
-        type: 'GET',
-        url: `/superset/filter/${datasource.type}/${datasource.id}/${col}/`,
-        success: (data) => {
-          this.setState((prevState) => {
-            const newStateFilters = Object.assign([], prevState.filters);
-            newStateFilters[index] = { valuesLoading: false, valueChoices: data };
-            return { filters: newStateFilters };
-          });
-        },
+      // if there is an outstanding request to fetch values, cancel it.
+      if (this.state.activeRequest) {
+        this.state.activeRequest.abort();
+      }
+      this.setState({
+        activeRequest: $.ajax({
+          type: 'GET',
+          url: `/superset/filter/${datasource.type}/${datasource.id}/${col}/`,
+          success: (data) => {
+            this.setState((prevState) => {
+              const newStateFilters = Object.assign([], prevState.filters);
+              newStateFilters[index] = { valuesLoading: false, valueChoices: data };
+              return { filters: newStateFilters, activeRequest: null };
+            });
+          },
+        }),
       });
     }
   }
diff --git a/superset/assets/spec/javascripts/explore/components/FilterControl_spec.jsx b/superset/assets/spec/javascripts/explore/components/FilterControl_spec.jsx
index 562cbc6..02beedc 100644
--- a/superset/assets/spec/javascripts/explore/components/FilterControl_spec.jsx
+++ b/superset/assets/spec/javascripts/explore/components/FilterControl_spec.jsx
@@ -109,12 +109,15 @@ describe('FilterControl', () => {
     ]);
   });
 
+  before(() => {
+    sinon.stub($, 'ajax');
+  });
+
   after(() => {
     $.ajax.restore();
   });
 
   it('makes a GET request to retrieve value choices', () => {
-    sinon.stub($, 'ajax');
     wrapper.instance().fetchFilterValues(0, 'col1');
     expect($.ajax.getCall(0).args[0].type).to.deep.equal('GET');
     expect($.ajax.getCall(0).args[0].url).to.deep.equal('/superset/filter/qtable/1/col1/');
@@ -214,4 +217,31 @@ describe('FilterControl', () => {
       },
     ]);
   });
+
+  it('tracks an active filter select ajax request', () => {
+    const spyReq = sinon.spy();
+    $.ajax.reset();
+    $.ajax.onFirstCall().returns(spyReq);
+    wrapper.instance().fetchFilterValues(0, 'col1');
+    expect(wrapper.state().activeRequest).to.equal(spyReq);
+    // Sets active to null after success
+    $.ajax.getCall(0).args[0].success('choices');
+    expect(wrapper.state().filters[0].valuesLoading).to.equal(false);
+    expect(wrapper.state().filters[0].valueChoices).to.equal('choices');
+    expect(wrapper.state().activeRequest).to.equal(null);
+  });
+
+  it('cancels active request if another is submitted', () => {
+    const spyReq = sinon.spy();
+    spyReq.abort = sinon.spy();
+    $.ajax.reset();
+    $.ajax.onFirstCall().returns(spyReq);
+    wrapper.instance().fetchFilterValues(0, 'col1');
+    expect(wrapper.state().activeRequest).to.equal(spyReq);
+    const spyReq1 = sinon.spy();
+    $.ajax.onSecondCall().returns(spyReq1);
+    wrapper.instance().fetchFilterValues(1, 'col2');
+    expect(spyReq.abort.called).to.equal(true);
+    expect(wrapper.state().activeRequest).to.equal(spyReq1);
+  });
 });
diff --git a/superset/config.py b/superset/config.py
index 2d168a9..ebc4777 100644
--- a/superset/config.py
+++ b/superset/config.py
@@ -41,6 +41,8 @@ with open(PACKAGE_FILE) as package_file:
 
 ROW_LIMIT = 50000
 VIZ_ROW_LIMIT = 10000
+# max rows retrieved by filter select auto complete
+FILTER_SELECT_ROW_LIMIT = 10000
 SUPERSET_WORKERS = 2
 SUPERSET_CELERY_WORKERS = 32
 
diff --git a/superset/views/core.py b/superset/views/core.py
index 18f6622..261696c 100755
--- a/superset/views/core.py
+++ b/superset/views/core.py
@@ -1171,7 +1171,10 @@ class Superset(BaseSupersetView):
             return json_error_response(DATASOURCE_ACCESS_ERR)
 
         payload = json.dumps(
-            datasource.values_for_column(column),
+            datasource.values_for_column(
+                column,
+                config.get('FILTER_SELECT_ROW_LIMIT', 10000),
+            ),
             default=utils.json_int_dttm_ser)
         return json_success(payload)
 

-- 
To stop receiving notification emails like this one, please contact
['"commits@superset.apache.org" <commits@superset.apache.org>'].

Mime
View raw message