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: [bugfix] only filterable columns should show up in FilterBox list (#3105)
Date Wed, 26 Jul 2017 03:50:43 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 95509f2  [bugfix] only filterable columns should show up in FilterBox list (#3105)
95509f2 is described below

commit 95509f20008684470a2c02ca1bb1295f395d4f29
Author: Maxime Beauchemin <maximebeauchemin@gmail.com>
AuthorDate: Tue Jul 25 20:50:41 2017 -0700

    [bugfix] only filterable columns should show up in FilterBox list (#3105)
    
    * [bugfix] only filterable columns should show up in FilterBox list
    
    * Touchups
---
 .../explore/components/ControlPanelsContainer.jsx            | 12 ++++++++++--
 .../explore/components/controls/SelectControl.jsx            |  3 ++-
 superset/assets/javascripts/explore/stores/controls.jsx      |  2 +-
 superset/assets/javascripts/explore/stores/visTypes.js       | 11 ++++++++---
 superset/connectors/base/models.py                           |  4 +++-
 5 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/superset/assets/javascripts/explore/components/ControlPanelsContainer.jsx b/superset/assets/javascripts/explore/components/ControlPanelsContainer.jsx
index 9227390..ac82bb4 100644
--- a/superset/assets/javascripts/explore/components/ControlPanelsContainer.jsx
+++ b/superset/assets/javascripts/explore/components/ControlPanelsContainer.jsx
@@ -4,7 +4,7 @@ import PropTypes from 'prop-types';
 import { bindActionCreators } from 'redux';
 import { connect } from 'react-redux';
 import { Alert } from 'react-bootstrap';
-import { sectionsToRender } from '../stores/visTypes';
+import { sectionsToRender, visTypes } from '../stores/visTypes';
 import ControlPanelSection from './ControlPanelSection';
 import ControlRow from './ControlRow';
 import Control from './Control';
@@ -28,7 +28,15 @@ class ControlPanelsContainer extends React.Component {
     this.getControlData = this.getControlData.bind(this);
   }
   getControlData(controlName) {
-    const mapF = controls[controlName].mapStateToProps;
+    // Identifying mapStateToProps function to apply (logic can't be in store)
+    let mapF = controls[controlName].mapStateToProps;
+
+    // Looking to find mapStateToProps override for this viz type
+    const controlOverrides = visTypes[this.props.controls.viz_type.value].controlOverrides
|| {};
+    if (controlOverrides[controlName] && controlOverrides[controlName].mapStateToProps)
{
+      mapF = controlOverrides[controlName].mapStateToProps;
+    }
+    // Applying mapStateToProps if needed
     if (mapF) {
       return Object.assign({}, this.props.controls[controlName], mapF(this.props.exploreState));
     }
diff --git a/superset/assets/javascripts/explore/components/controls/SelectControl.jsx b/superset/assets/javascripts/explore/components/controls/SelectControl.jsx
index 6998c07..312fced 100644
--- a/superset/assets/javascripts/explore/components/controls/SelectControl.jsx
+++ b/superset/assets/javascripts/explore/components/controls/SelectControl.jsx
@@ -43,7 +43,8 @@ export default class SelectControl extends React.PureComponent {
     this.onChange = this.onChange.bind(this);
   }
   componentWillReceiveProps(nextProps) {
-    if (nextProps.choices !== this.props.choices) {
+    if (nextProps.choices !== this.props.choices ||
+        nextProps.options !== this.props.options) {
       const options = this.getOptions(nextProps);
       this.setState({ options });
     }
diff --git a/superset/assets/javascripts/explore/stores/controls.jsx b/superset/assets/javascripts/explore/stores/controls.jsx
index 1330693..ecfbfe9 100644
--- a/superset/assets/javascripts/explore/stores/controls.jsx
+++ b/superset/assets/javascripts/explore/stores/controls.jsx
@@ -326,7 +326,7 @@ export const controls = {
     valueRenderer: c => <ColumnOption column={c} />,
     valueKey: 'column_name',
     mapStateToProps: state => ({
-      options: (state.datasource) ? state.datasource.columns : [],
+      options: (state.datasource) ? state.datasource.columns.filter(c => c.groupby) :
[],
     }),
   },
 
diff --git a/superset/assets/javascripts/explore/stores/visTypes.js b/superset/assets/javascripts/explore/stores/visTypes.js
index bdebf07..7d3f262 100644
--- a/superset/assets/javascripts/explore/stores/visTypes.js
+++ b/superset/assets/javascripts/explore/stores/visTypes.js
@@ -75,7 +75,7 @@ export const sections = {
   ],
 };
 
-const visTypes = {
+export const visTypes = {
   dist_bar: {
     label: 'Distribution - Bar Chart',
     controlPanelSections: [
@@ -742,8 +742,13 @@ const visTypes = {
     controlOverrides: {
       groupby: {
         label: 'Filter controls',
-        description: 'The controls you want to filter on',
-        default: [],
+        description: (
+          'The controls you want to filter on. Note that only columns ' +
+          'checked as "filterable" will show up on this list.'
+        ),
+        mapStateToProps: state => ({
+          options: (state.datasource) ? state.datasource.columns.filter(c => c.filterable)
: [],
+        }),
       },
     },
   },
diff --git a/superset/connectors/base/models.py b/superset/connectors/base/models.py
index e203ef4..b32bb92 100644
--- a/superset/connectors/base/models.py
+++ b/superset/connectors/base/models.py
@@ -222,7 +222,9 @@ class BaseColumn(AuditMixinNullable, ImportMixin):
 
     @property
     def data(self):
-        attrs = ('column_name', 'verbose_name', 'description', 'expression')
+        attrs = (
+            'column_name', 'verbose_name', 'description', 'expression',
+            'filterable', 'groupby')
         return {s: getattr(self, s) for s in attrs}
 
 

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

Mime
View raw message