Filter out combining operator select

This commit is contained in:
Lukas Martinelli 2017-01-09 17:47:35 +01:00
parent ba0a94f3ad
commit fed530f5f2
4 changed files with 87 additions and 64 deletions

View file

@ -0,0 +1,41 @@
import React from 'react'
import SelectInput from '../inputs/SelectInput'
import input from '../../config/input.js'
import { margins } from '../../config/scales.js'
class CombiningOperatorSelect extends React.Component {
static propTypes = {
value: React.PropTypes.string.isRequired,
onChange: React.PropTypes.func.isRequired,
style: React.PropTypes.object,
}
render() {
return <div style={{
display: 'inline-block',
width: '50%',
}}>
<SelectInput
value={this.props.value}
options={['all', 'any', 'none']}
onChange={this.props.onChange}
style={{
display: 'block',
width: '100%',
}}
/>
<label style={{
...input.label,
width: 'auto',
marginLeft: margins[2],
display: 'block',
width: '100%',
}}>
of the filters match
</label>
</div>
}
}
export default CombiningOperatorSelect

View file

@ -3,11 +3,13 @@ import GlSpec from 'mapbox-gl-style-spec/reference/latest.js'
import input from '../../config/input.js' 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, fontSizes } from '../../config/scales.js'
import CombiningOperatorSelect from './CombiningOperatorSelect'
import DocLabel from '../fields/DocLabel' import DocLabel from '../fields/DocLabel'
import Button from '../Button' import Button from '../Button'
import SelectInput from '../inputs/SelectInput' import SelectInput from '../inputs/SelectInput'
import MultiButtonInput from '../inputs/MultiButtonInput'
import StringInput from '../inputs/StringInput' import StringInput from '../inputs/StringInput'
import AutocompleteInput from '../inputs/AutocompleteInput' import AutocompleteInput from '../inputs/AutocompleteInput'
@ -32,45 +34,6 @@ function hasNestedCombiningFilter(filter) {
return false return false
} }
class CombiningOperatorSelect extends React.Component {
static propTypes = {
value: React.PropTypes.string.isRequired,
onChange: React.PropTypes.func.isRequired,
style: React.PropTypes.object,
}
render() {
const options = combiningFilterOps.map(op => {
return <option key={op} value={op}>{op}</option>
})
return <div
style={{
marginTop: margins[1],
marginBottom: margins[1],
...this.props.style
}}
>
<select
style={{
...input.select,
width: '20.5%',
}}
value={this.props.value}
onChange={e => this.props.onChange(e.target.value)}
>
{options}
</select>
<label style={{
...input.label,
width: '60%',
marginLeft: margins[0],
}}>
of the filters matches
</label>
</div>
}
}
class OperatorSelect extends React.Component { class OperatorSelect extends React.Component {
static propTypes = { static propTypes = {
@ -194,16 +157,18 @@ export default class CombiningFilterEditor extends React.Component {
const filterEditors = filters.map((f, idx) => { const filterEditors = filters.map((f, idx) => {
return <div> return <div>
<Button <div style={{display: 'inline-block', width: '25%'}}>
style={{backgroundColor: null}} <Button
onClick={this.deleteFilterItem.bind(this, idx)} style={{backgroundColor: null}}
> onClick={this.deleteFilterItem.bind(this, idx)}
<DeleteIcon /> >
</Button> <DeleteIcon />
</Button>
</div>
<SingleFilterEditor <SingleFilterEditor
style={{ style={{
display: 'inline-block', display: 'inline-block',
width: '80%' width: '75%'
}} }}
key={idx} key={idx}
properties={this.props.properties} properties={this.props.properties}
@ -219,22 +184,30 @@ export default class CombiningFilterEditor extends React.Component {
} }
return <div> return <div>
<DocLabel <div style={{
label={"Filter"} width: '50%',
doc={GlSpec.layer.filter.doc} verticalAlign: 'top',
style={{ display: 'inline-block',
width: '42.25%', }}>
}} <DocLabel
/> label={"Filter"}
doc={GlSpec.layer.filter.doc}
style={{
display: 'block',
}}
/>
<div>
<Button onClick={this.addFilterItem.bind(this)}>Add filter</Button>
</div>
</div>
<CombiningOperatorSelect <CombiningOperatorSelect
value={combiningOp} value={combiningOp}
onChange={this.onFilterPartChanged.bind(this, 0)} onChange={this.onFilterPartChanged.bind(this, 0)}
style={{ style={{
display: 'inline-block', display: 'inline-block',
width: '80%' width: '50%'
}} }}
/> />
<Button onClick={this.addFilterItem.bind(this)}>Add filter</Button>
{filterEditors} {filterEditors}
</div> </div>
} }

View file

@ -15,21 +15,29 @@ class MultiButtonInput extends React.Component {
} }
render() { render() {
const selectedValue = this.props.value || this.props.options[0][0] let options = this.props.options
const buttons = this.props.options.map(([val, label])=> { if(options.length > 0 && !Array.isArray(options[0])) {
options = options.map(v => [v, v])
}
const selectedValue = this.props.value || options[0][0]
const buttons = options.map(([val, label])=> {
return <Button return <Button
key={val} key={val}
onClick={e => this.props.onChange(val)}
style={{ style={{
marginRight: margins[0], marginRight: margins[0],
backgroundColor: val === selectedValue ? colors.midgray : colors.gray, backgroundColor: val === selectedValue ? colors.midgray : colors.gray,
}} }}
onClick={e => this.props.onChange(val)}
> >
{label} {label}
</Button> </Button>
}) })
return <div style={{display: 'inline-block'}}> return <div style={{
display: 'inline-block',
...this.props.style,
}}>
{buttons} {buttons}
</div> </div>
} }

View file

@ -11,9 +11,10 @@ class SelectInput extends React.Component {
render() { render() {
const options = this.props.options.map(([val, label])=> { let options = this.props.options
return <option key={val} value={val}>{label}</option> if(options.length > 0 && !Array.isArray(options[0])) {
}) options = options.map(v => [v, v])
}
return <select return <select
style={{ style={{
@ -23,7 +24,7 @@ class SelectInput extends React.Component {
value={this.props.value} value={this.props.value}
onChange={e => this.props.onChange(e.target.value)} onChange={e => this.props.onChange(e.target.value)}
> >
{options} { options.map(([val, label]) => <option key={val} value={val}>{label}</option>) }
</select> </select>
} }
} }