Enable freeform-select with fetched column values for filter values (#1697)

* Enable freeform-select with fetched column values for filter values
 - db migration to add filter_select_enabled
 - add freeform-multi option for Selectfield
 - modify formatFilter() function on query to accomodate filter-select

* Fix js tests

* Fix codeclimate issue

* Changes based on comments

* Add test for filter endpoint

* Extract out renderFilterFormField function from render

* Fix landscape issues
This commit is contained in:
vera-liu
2016-12-16 14:23:48 -08:00
committed by GitHub
parent bb04e6fcfa
commit 6732f01cb7
13 changed files with 335 additions and 21 deletions

View File

@@ -58,8 +58,18 @@ export default class SelectField extends React.Component {
if (this.props.freeForm) {
// For FreeFormSelect, insert value into options if not exist
const values = choices.map((c) => c[0]);
if (values.indexOf(this.props.value) === -1) {
options.push({ value: this.props.value, label: this.props.value });
if (this.props.value) {
if (typeof this.props.value === 'object') {
this.props.value.forEach((v) => {
if (values.indexOf(v) === -1) {
options.push({ value: v, label: v });
}
});
} else {
if (values.indexOf(this.props.value) === -1) {
options.push({ value: this.props.value, label: this.props.value });
}
}
}
}
@@ -77,13 +87,19 @@ export default class SelectField extends React.Component {
// Tab, comma or Enter will trigger a new option created for FreeFormSelect
const selectWrap = this.props.freeForm ?
(<Creatable {...selectProps} />) : (<Select {...selectProps} />);
if (this.props.label) {
return (
<div id={`formControlsSelect-${slugify(this.props.label)}`}>
<ControlLabelWithTooltip
label={this.props.label}
description={this.props.description}
/>
{selectWrap}
</div>
);
}
return (
<div id={`formControlsSelect-${slugify(this.props.label)}`}>
<ControlLabelWithTooltip
label={this.props.label}
description={this.props.description}
/>
<div>
{selectWrap}
</div>
);