Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bugfix] only filterable columns should show up in FilterBox list #3105

Merged
merged 2 commits into from
Jul 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
Expand Down
2 changes: 1 addition & 1 deletion superset/assets/javascripts/explore/stores/controls.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) : [],
}),
},

Expand Down
11 changes: 8 additions & 3 deletions superset/assets/javascripts/explore/stores/visTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const sections = {
],
};

const visTypes = {
export const visTypes = {
dist_bar: {
label: 'Distribution - Bar Chart',
controlPanelSections: [
Expand Down Expand Up @@ -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) : [],
}),
},
},
},
Expand Down
4 changes: 3 additions & 1 deletion superset/connectors/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,9 @@ def expression(self):

@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}


Expand Down