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: fix: onSave datasource raises React error (#8049)
Date Thu, 15 Aug 2019 21:13:33 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 5e0c91e   fix: onSave datasource raises React error (#8049)
5e0c91e is described below

commit 5e0c91ef49c29d7b5de8164ccdd0f91cf21ddc0d
Author: Maxime Beauchemin <maximebeauchemin@gmail.com>
AuthorDate: Thu Aug 15 14:13:18 2019 -0700

     fix: onSave datasource raises React error (#8049)
    
    * fix: datasource save raises React error
    
    * add test
---
 .../spec/javascripts/explore/components/MetricsControl_spec.jsx    | 7 +++++++
 superset/assets/src/explore/components/controls/MetricsControl.jsx | 6 ++++--
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/superset/assets/spec/javascripts/explore/components/MetricsControl_spec.jsx b/superset/assets/spec/javascripts/explore/components/MetricsControl_spec.jsx
index 143bf8f..b6fbf1b 100644
--- a/superset/assets/spec/javascripts/explore/components/MetricsControl_spec.jsx
+++ b/superset/assets/spec/javascripts/explore/components/MetricsControl_spec.jsx
@@ -368,5 +368,12 @@ describe('MetricsControl', () => {
       wrapper.setProps({ ...props, columns: [] });
       expect(onChange.calledOnce).toEqual(false);
     });
+    it('Does not fail if no columns or savedMetrics are passed', () => {
+      const { wrapper } = setup({
+        savedMetrics: null,
+        columns: null,
+      });
+      expect(wrapper.exists('.metrics-select')).toEqual(true);
+    });
   });
 });
diff --git a/superset/assets/src/explore/components/controls/MetricsControl.jsx b/superset/assets/src/explore/components/controls/MetricsControl.jsx
index 9498b08..a998283 100644
--- a/superset/assets/src/explore/components/controls/MetricsControl.jsx
+++ b/superset/assets/src/explore/components/controls/MetricsControl.jsx
@@ -54,6 +54,8 @@ const propTypes = {
 const defaultProps = {
   onChange: () => {},
   clearable: true,
+  savedMetrics: [],
+  columns: [],
 };
 
 function isDictionaryForAdhocMetric(value) {
@@ -62,7 +64,7 @@ function isDictionaryForAdhocMetric(value) {
 
 function columnsContainAllMetrics(value, nextProps) {
   const columnNames = new Set(
-    [...nextProps.columns, ...nextProps.savedMetrics]
+    [...(nextProps.columns || []), ...(nextProps.savedMetrics || [])]
     // eslint-disable-next-line camelcase
       .map(({ column_name, metric_name }) => (column_name || metric_name)),
   );
@@ -243,7 +245,7 @@ export default class MetricsControl extends React.PureComponent {
       Object.keys(AGGREGATES).map(aggregate => ({ aggregate_name: aggregate })) :
       [];
     const options = [
-      ...columns,
+      ...(columns || []),
       ...aggregates,
       ...(savedMetrics || []),
     ];


Mime
View raw message