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 ae7e114  [explore] set working default for MetricsControl (#4803)
ae7e114 is described below

commit ae7e114621867adfd29da523f3326d311a246dc5
Author: Maxime Beauchemin <maximebeauche...@gmail.com>
AuthorDate: Wed Apr 11 15:11:11 2018 -0700

    [explore] set working default for MetricsControl (#4803)
    
    The default setting which would look for either `count` first and then
    any metric stopped working when we landed MetricsControl. This mimics
    the previous behavior
---
 superset/assets/javascripts/explore/stores/controls.jsx | 17 ++++++++++-------
 superset/assets/javascripts/modules/utils.js            |  8 ++++----
 2 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/superset/assets/javascripts/explore/stores/controls.jsx 
b/superset/assets/javascripts/explore/stores/controls.jsx
index a075a1a..2d9f964 100644
--- a/superset/assets/javascripts/explore/stores/controls.jsx
+++ b/superset/assets/javascripts/explore/stores/controls.jsx
@@ -175,14 +175,17 @@ export const controls = {
     label: t('Metrics'),
     validators: [v.nonEmpty],
     default: (c) => {
-      const metric = mainMetric(c.options);
+      const metric = mainMetric(c.savedMetrics);
       return metric ? [metric] : null;
     },
-    mapStateToProps: state => ({
-      columns: state.datasource ? state.datasource.columns : [],
-      savedMetrics: state.datasource ? state.datasource.metrics : [],
-      datasourceType: state.datasource && state.datasource.type,
-    }),
+    mapStateToProps: (state) => {
+      const datasource = state.datasource;
+      return {
+        columns: datasource ? datasource.columns : [],
+        savedMetrics: datasource ? datasource.metrics : [],
+        datasourceType: datasource && datasource.type,
+      };
+    },
     description: t('One or many metrics to display'),
   },
 
@@ -264,7 +267,7 @@ export const controls = {
     label: t('Metric'),
     clearable: false,
     validators: [v.nonEmpty],
-    default: c => mainMetric(c.options),
+    default: props => mainMetric(props.savedMetrics),
     mapStateToProps: state => ({
       columns: state.datasource ? state.datasource.columns : [],
       savedMetrics: state.datasource ? state.datasource.metrics : [],
diff --git a/superset/assets/javascripts/modules/utils.js 
b/superset/assets/javascripts/modules/utils.js
index 6180783..016444a 100644
--- a/superset/assets/javascripts/modules/utils.js
+++ b/superset/assets/javascripts/modules/utils.js
@@ -260,17 +260,17 @@ export function getParam(name) {
   return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, 
' '));
 }
 
-export function mainMetric(metricOptions) {
+export function mainMetric(savedMetrics) {
   // Using 'count' as default metric if it exists, otherwise using whatever 
one shows up first
   let metric;
-  if (metricOptions && metricOptions.length > 0) {
-    metricOptions.forEach((m) => {
+  if (savedMetrics && savedMetrics.length > 0) {
+    savedMetrics.forEach((m) => {
       if (m.metric_name === 'count') {
         metric = 'count';
       }
     });
     if (!metric) {
-      metric = metricOptions[0].metric_name;
+      metric = savedMetrics[0].metric_name;
     }
   }
   return metric;

-- 
To stop receiving notification emails like this one, please contact
maximebeauche...@apache.org.

Reply via email to