You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by mi...@apache.org on 2019/06/19 22:36:13 UTC

[incubator-superset] 06/08: Allowing withVerification to remove all options if none are valid (#7652)

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

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

commit f4e47008094b75cf34e095d6e3667e08dbae136e
Author: michellethomas <mi...@gmail.com>
AuthorDate: Tue Jun 18 14:06:05 2019 -0700

    Allowing withVerification to remove all options if none are valid (#7652)
    
    
    (cherry picked from commit 5864ddc07944c9b6f4a235a4be604a93976e30af)
---
 .../explore/components/withVerification_spec.jsx           | 14 ++++++++++++--
 .../src/explore/components/controls/withVerification.jsx   |  4 ++--
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/superset/assets/spec/javascripts/explore/components/withVerification_spec.jsx b/superset/assets/spec/javascripts/explore/components/withVerification_spec.jsx
index 44377ea..bef2140 100644
--- a/superset/assets/spec/javascripts/explore/components/withVerification_spec.jsx
+++ b/superset/assets/spec/javascripts/explore/components/withVerification_spec.jsx
@@ -44,7 +44,7 @@ const defaultProps = {
 
 const VALID_METRIC = { metric_name: 'sum__value', expression: 'SUM(energy_usage.value)' };
 
-function setup(overrides) {
+function setup(overrides, validMetric) {
   const onChange = sinon.spy();
   const props = {
     onChange,
@@ -53,7 +53,7 @@ function setup(overrides) {
   };
   const VerifiedControl = withVerification(MetricsControl, 'metric_name', 'savedMetrics');
   const wrapper = shallow(<VerifiedControl {...props} />);
-  fetchMock.mock('glob:*/valid_metrics*', `["${VALID_METRIC.metric_name}"]`);
+  fetchMock.mock('glob:*/valid_metrics*', validMetric || `["${VALID_METRIC.metric_name}"]`);
   return { props, wrapper, onChange };
 }
 
@@ -103,4 +103,14 @@ describe('VerifiedMetricsControl', () => {
       fetchMock.reset();
     }, 0);
   });
+
+  it('Returns no verified options if none are valid', () => {
+    const { wrapper } = setup({}, []);
+    setTimeout(() => {
+      expect(fetchMock.calls(defaultProps.getEndpoint())).toHaveLength(1);
+      const child = wrapper.find(MetricsControl);
+      expect(child.props().savedMetrics).toEqual([]);
+      fetchMock.reset();
+    }, 0);
+  });
 });
diff --git a/superset/assets/src/explore/components/controls/withVerification.jsx b/superset/assets/src/explore/components/controls/withVerification.jsx
index 8f1e549..87195fa 100644
--- a/superset/assets/src/explore/components/controls/withVerification.jsx
+++ b/superset/assets/src/explore/components/controls/withVerification.jsx
@@ -31,7 +31,7 @@ export default function withVerification(WrappedComponent, optionLabel, optionsN
     constructor(props) {
       super(props);
       this.state = {
-        validOptions: new Set(),
+        validOptions: null,
         hasRunVerification: false,
       };
 
@@ -69,7 +69,7 @@ export default function withVerification(WrappedComponent, optionLabel, optionsN
     render() {
       const { validOptions } = this.state;
       const options = this.props[optionsName];
-      const verifiedOptions = validOptions.size ?
+      const verifiedOptions = validOptions ?
         options.filter(o => (validOptions.has(o[optionLabel]))) :
         options;