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

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

* Touchups
This commit is contained in:
Maxime Beauchemin 2017-07-25 20:50:41 -07:00 committed by GitHub
parent 49ab09101b
commit 95509f2000
5 changed files with 24 additions and 8 deletions

View File

@ -4,7 +4,7 @@ import PropTypes from 'prop-types';
import { bindActionCreators } from 'redux'; import { bindActionCreators } from 'redux';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { Alert } from 'react-bootstrap'; import { Alert } from 'react-bootstrap';
import { sectionsToRender } from '../stores/visTypes'; import { sectionsToRender, visTypes } from '../stores/visTypes';
import ControlPanelSection from './ControlPanelSection'; import ControlPanelSection from './ControlPanelSection';
import ControlRow from './ControlRow'; import ControlRow from './ControlRow';
import Control from './Control'; import Control from './Control';
@ -28,7 +28,15 @@ class ControlPanelsContainer extends React.Component {
this.getControlData = this.getControlData.bind(this); this.getControlData = this.getControlData.bind(this);
} }
getControlData(controlName) { 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) { if (mapF) {
return Object.assign({}, this.props.controls[controlName], mapF(this.props.exploreState)); return Object.assign({}, this.props.controls[controlName], mapF(this.props.exploreState));
} }

View File

@ -43,7 +43,8 @@ export default class SelectControl extends React.PureComponent {
this.onChange = this.onChange.bind(this); this.onChange = this.onChange.bind(this);
} }
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
if (nextProps.choices !== this.props.choices) { if (nextProps.choices !== this.props.choices ||
nextProps.options !== this.props.options) {
const options = this.getOptions(nextProps); const options = this.getOptions(nextProps);
this.setState({ options }); this.setState({ options });
} }

View File

@ -326,7 +326,7 @@ export const controls = {
valueRenderer: c => <ColumnOption column={c} />, valueRenderer: c => <ColumnOption column={c} />,
valueKey: 'column_name', valueKey: 'column_name',
mapStateToProps: state => ({ mapStateToProps: state => ({
options: (state.datasource) ? state.datasource.columns : [], options: (state.datasource) ? state.datasource.columns.filter(c => c.groupby) : [],
}), }),
}, },

View File

@ -75,7 +75,7 @@ export const sections = {
], ],
}; };
const visTypes = { export const visTypes = {
dist_bar: { dist_bar: {
label: 'Distribution - Bar Chart', label: 'Distribution - Bar Chart',
controlPanelSections: [ controlPanelSections: [
@ -742,8 +742,13 @@ const visTypes = {
controlOverrides: { controlOverrides: {
groupby: { groupby: {
label: 'Filter controls', label: 'Filter controls',
description: 'The controls you want to filter on', description: (
default: [], '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) : [],
}),
}, },
}, },
}, },

View File

@ -222,7 +222,9 @@ class BaseColumn(AuditMixinNullable, ImportMixin):
@property @property
def data(self): 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} return {s: getattr(self, s) for s in attrs}