Support delete filter

This commit is contained in:
Lukas Martinelli 2017-01-09 16:24:42 +01:00
parent cfeaf2cdce
commit 5bb68a38c2

View file

@ -5,10 +5,14 @@ import input from '../../config/input.js'
import colors from '../../config/colors.js' import colors from '../../config/colors.js'
import { margins } from '../../config/scales.js' import { margins } from '../../config/scales.js'
import Button from '../Button'
import SelectInput from '../inputs/SelectInput' import SelectInput from '../inputs/SelectInput'
import StringInput from '../inputs/StringInput' import StringInput from '../inputs/StringInput'
import AutocompleteInput from '../inputs/AutocompleteInput' import AutocompleteInput from '../inputs/AutocompleteInput'
import AddIcon from 'react-icons/lib/md/add-circle-outline'
import DeleteIcon from 'react-icons/lib/md/delete'
const combiningFilterOps = ['all', 'any', 'none'] const combiningFilterOps = ['all', 'any', 'none']
const setFilterOps = ['in', '!in'] const setFilterOps = ['in', '!in']
const otherFilterOps = Object const otherFilterOps = Object
@ -89,6 +93,7 @@ class SingleFilterEditor extends React.Component {
filter: React.PropTypes.array.isRequired, filter: React.PropTypes.array.isRequired,
onChange: React.PropTypes.func.isRequired, onChange: React.PropTypes.func.isRequired,
properties: React.PropTypes.object, properties: React.PropTypes.object,
style: React.PropTypes.object,
} }
static defaultProps = { static defaultProps = {
@ -109,10 +114,11 @@ class SingleFilterEditor extends React.Component {
return <div style={{ return <div style={{
marginTop: margins[1], marginTop: margins[1],
marginBottom: margins[1], marginBottom: margins[1],
...this.props.style
}}> }}>
<AutocompleteInput <AutocompleteInput
wrapperStyle={{ wrapperStyle={{
width: '31%', width: '30%',
marginRight: margins[0] marginRight: margins[0]
}} }}
value={propertyName} value={propertyName}
@ -163,18 +169,37 @@ export default class CombiningFilterEditor extends React.Component {
this.props.onChange(newFilter) this.props.onChange(newFilter)
} }
deleteFilterItem(filterIdx) {
const newFilter = this.combiningFilter().slice(0)
console.log('Delete', filterIdx, newFilter)
newFilter.splice(filterIdx + 1, 1)
this.props.onChange(newFilter)
}
render() { render() {
const filter = this.combiningFilter() const filter = this.combiningFilter()
let combiningOp = filter[0] let combiningOp = filter[0]
let filters = filter.slice(1) let filters = filter.slice(1)
const filterEditors = filters.map((f, idx) => { const filterEditors = filters.map((f, idx) => {
return <SingleFilterEditor return <div>
key={idx} <Button
properties={this.props.properties} style={{backgroundColor: null}}
filter={f} onClick={this.deleteFilterItem.bind(this, idx)}
onChange={this.onFilterPartChanged.bind(this, idx + 1)} >
/> <DeleteIcon />
</Button>
<SingleFilterEditor
style={{
display: 'inline-block',
width: '80%'
}}
key={idx}
properties={this.props.properties}
filter={f}
onChange={this.onFilterPartChanged.bind(this, idx + 1)}
/>
</div>
}) })
//TODO: Implement support for nested filter //TODO: Implement support for nested filter