Commit 97b51383 authored by Matija Obreza's avatar Matija Obreza
Browse files

Dataset filtering by trait

- Filters code cleaned up
parent fe66d824
......@@ -19,9 +19,10 @@ class BooleanFilterInternal extends React.Component<IBooleanFilterInternal, any>
};
}
private handleChange = (onChange) => (event, value) => {
private handleChange = (event, value) => {
const { input } = this.props;
this.setState({ value });
onChange(value);
input.onChange(value === '' ? null : value);
}
public componentWillReceiveProps(nextProps) {
......@@ -29,14 +30,14 @@ class BooleanFilterInternal extends React.Component<IBooleanFilterInternal, any>
}
public render() {
const { label, input: {onChange} } = this.props;
const { label } = this.props;
return (
<div>
<FormControl component="fieldset">
<FormLabel>{ label }</FormLabel>
<RadioGroup
value={ this.state.value }
onChange={ this.handleChange(onChange) }
onChange={ this.handleChange }
>
<FormControlLabel value="true" control={ <Radio /> } label="Yes" />
<FormControlLabel value="false" control={ <Radio /> } label="No" />
......
......@@ -21,13 +21,6 @@ class StringFilterInternal extends React.Component<IStringFilterInternal, any> {
text: props.input.value[props.searchType] || '',
searchType: props.searchType,
};
this.textChange = this.textChange.bind(this);
this.report = this.report.bind(this);
}
private textChange(value, onChange) {
this.setState({ text: value });
this.report(onChange, value);
}
public componentWillReceiveProps(nextProps) {
......@@ -38,22 +31,24 @@ class StringFilterInternal extends React.Component<IStringFilterInternal, any> {
}
}
private report(onChange, value) {
const r = {};
r[this.state.searchType] = value;
onChange(r);
private report(value) {
const { input } = this.props;
if (value) {
const r = {};
r[this.state.searchType] = value;
input.onChange(r);
} else {
input.onChange(null);
}
}
private handleOnchange = (event, onChange) => {
this.textChange(event.target.value, onChange);
private textChange = (event) => {
this.setState({ text: event.target.value });
this.report(event.target.value);
}
public render() {
const { placeholder, label } = this.props;
const generateHandler = (method, value) => (e) => method(e, value);
const { input } = this.props;
const { onChange } = input;
return (
<div>
<TextField
......@@ -61,7 +56,7 @@ class StringFilterInternal extends React.Component<IStringFilterInternal, any> {
label={ label }
value={ this.state.text }
placeholder={ placeholder }
onChange={ generateHandler(this.handleOnchange, onChange) }
onChange={ this.textChange }
/>
</div>
......
......@@ -9,13 +9,18 @@ import StringFilter from 'ui/common/filter/StringFilter';
import StringArrFilter from 'ui/common/filter/StringArrFilter';
import TextFilter from 'ui/common/filter/TextFilter';
// <StringArrFilter name="language" label="Language" placeholder="Language"/>
const DatasetFilters = ({handleSubmit, initialize, ...other}) => (
<FiltersBlock title="Datasets" handleSubmit={ handleSubmit } initialize={ initialize } { ...other }>
<TextFilter name="_text" label="Keyword search" placeholder="mardi rice" className="p-20" />
<CollapsibleComponentSearch title="Dataset descriptions">
<StringFilter name="title" searchType="contains" label="Title" placeholder="Dataset title"/>
<StringFilter name="description" searchType="contains" label="Description" placeholder="Dataset description"/>
<StringArrFilter name="language" label="Language" placeholder="Language"/>
</CollapsibleComponentSearch>
<CollapsibleComponentSearch title="Traits">
<TextFilter name="descriptor._text" label="Trait keywords" placeholder="mardi rice" />
<StringFilter name="descriptor.title" searchType="contains" label="Trait title" placeholder="Leaf"/>
</CollapsibleComponentSearch>
<CollapsibleComponentSearch title="Accessions">
<StringArrFilter name="accessionIdentifier.genus" label="Genus" placeholder="Manihot"/>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment