superset-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From michel...@apache.org
Subject [incubator-superset] 09/13: Remove aggregates from metric options if datasource has no columns (#7586)
Date Sat, 01 Jun 2019 01:28:23 GMT
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 99de5a44fceffb402ef7223436a1af89516035ff
Author: michellethomas <michelle.q.thomas@gmail.com>
AuthorDate: Fri May 24 11:10:35 2019 -0700

    Remove aggregates from metric options if datasource has no columns (#7586)
    
    
    (cherry picked from commit 47ba2ad3947a83bb5299c9f80a9aedd4a756a004)
---
 .../javascripts/explore/components/MetricsControl_spec.jsx     |  8 ++++++++
 .../assets/src/explore/components/controls/MetricsControl.jsx  | 10 +++++++---
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/superset/assets/spec/javascripts/explore/components/MetricsControl_spec.jsx b/superset/assets/spec/javascripts/explore/components/MetricsControl_spec.jsx
index 6f2c657..31bddf8 100644
--- a/superset/assets/spec/javascripts/explore/components/MetricsControl_spec.jsx
+++ b/superset/assets/spec/javascripts/explore/components/MetricsControl_spec.jsx
@@ -85,6 +85,14 @@ describe('MetricsControl', () => {
       ]);
     });
 
+    it('does not show aggregates in options if no columns', () => {
+      const { wrapper } = setup({ columns: [] });
+      expect(wrapper.state('options')).toEqual([
+        { optionName: 'sum__value', metric_name: 'sum__value', expression: 'SUM(energy_usage.value)'
},
+        { optionName: 'avg__value', metric_name: 'avg__value', expression: 'AVG(energy_usage.value)'
},
+      ]);
+    });
+
     it('coerces Adhoc Metrics from form data into instances of the AdhocMetric class and
leaves saved metrics', () => {
       const { wrapper } = setup({
         value: [
diff --git a/superset/assets/src/explore/components/controls/MetricsControl.jsx b/superset/assets/src/explore/components/controls/MetricsControl.jsx
index b42cc81..1e49355 100644
--- a/superset/assets/src/explore/components/controls/MetricsControl.jsx
+++ b/superset/assets/src/explore/components/controls/MetricsControl.jsx
@@ -238,10 +238,14 @@ export default class MetricsControl extends React.PureComponent {
   }
 
   optionsForSelect(props) {
+    const { columns, savedMetrics } = props;
+    const aggregates = columns && columns.length ?
+      Object.keys(AGGREGATES).map(aggregate => ({ aggregate_name: aggregate })) :
+      [];
     const options = [
-      ...props.columns,
-      ...Object.keys(AGGREGATES).map(aggregate => ({ aggregate_name: aggregate })),
-      ...props.savedMetrics,
+      ...columns,
+      ...aggregates,
+      ...savedMetrics,
     ];
 
     return options.reduce((results, option) => {


Mime
View raw message