From a981a39691362a3846d6fada75fa712e14b6e03a Mon Sep 17 00:00:00 2001 From: Lukas Martinelli Date: Mon, 19 Dec 2016 14:52:28 +0100 Subject: [PATCH] Split filter editor into more components --- src/fields/input.js | 2 +- src/filter/editor.jsx | 190 +++++++++++++++++++++++++++++++++--------- src/layers/editor.jsx | 2 +- 3 files changed, 152 insertions(+), 42 deletions(-) diff --git a/src/fields/input.js b/src/fields/input.js index ea541c03..484d3878 100644 --- a/src/fields/input.js +++ b/src/fields/input.js @@ -24,7 +24,7 @@ const property = { const input = { ...base, - border: '1px solid rgb(36, 36, 36)', + border: 'none', width: '47%', backgroundColor: theme.colors.gray, color: theme.colors.lowgray, diff --git a/src/filter/editor.jsx b/src/filter/editor.jsx index 86c29c13..7ae2e465 100644 --- a/src/filter/editor.jsx +++ b/src/filter/editor.jsx @@ -2,13 +2,122 @@ import React from 'react' import Immutable from 'immutable' import { PropertyGroup } from '../fields/spec' import PureRenderMixin from 'react-addons-pure-render-mixin'; -import inputStyle from '../fields/input.js' import GlSpec from 'mapbox-gl-style-spec/reference/latest.min.js' +import inputStyle from '../fields/input.js' +import theme from '../theme.js' -export default class FilterEditor extends React.Component { +const combiningFilterOps = ['all', 'any', 'none'] +const otherFilterOps = Object + .keys(GlSpec.filter_operator.values) + .filter(op => combiningFilterOps.indexOf(op) < 0) + +class CombiningOperatorSelect extends React.Component { + static propTypes = { + value: React.PropTypes.string.isRequired, + onChange: React.PropTypes.func.isRequired, + } + + render() { + const options = combiningFilterOps.map(op => { + return + }) + + return
+ + +
+ } +} + +class OperatorSelect extends React.Component { + static propTypes = { + value: React.PropTypes.string.isRequired, + onChange: React.PropTypes.func.isRequired, + } + + render() { + const options = otherFilterOps.map(op => { + return + }) + return + } +} + +class SingleFilterEditor extends React.Component { static propTypes = { filter: React.PropTypes.array.isRequired, - onFilterChanged: React.PropTypes.func.isRequired, + onChange: React.PropTypes.func.isRequired, + } + + onFilterPartChanged(filterOp, propertyName, filterArgs) { + const newFilter = [filterOp, propertyName, ...filterArgs] + this.props.onChange(newFilter) + } + + render() { + const f = this.props.filter + const filterOp = f[0] + const propertyName = f[1] + const filterArgs = f.slice(2) + + return
+ this.onFilterPartChanged(filterOp, newPropertyName, filterArgs)} + /> + this.onFilterPartChanged(newFilterOp, propertyName, filterArgs)} + /> + this.onFilterPartChanged(filterOp, propertyName, newFilterArgs)} + /> +
+ } + +} + +export default class CombiningFilterEditor extends React.Component { + static propTypes = { + filter: React.PropTypes.array.isRequired, + onChange: React.PropTypes.func.isRequired, } constructor(props) { @@ -16,47 +125,48 @@ export default class FilterEditor extends React.Component { this.shouldComponentUpdate = PureRenderMixin.shouldComponentUpdate.bind(this); } + // Convert filter to combining filter + combiningFilter() { + let combiningOp = this.props.filter[0] + let filters = this.props.filter.slice(1) + + if(combiningFilterOps.indexOf(combiningOp) < 0) { + combiningOp = 'all' + filters = [this.props.filter.slice(0)] + } + + return [combiningOp, ...filters] + } + + onFilterPartChanged(filterIdx, newPart) { + const newFilter = this.combiningFilter().slice(0) + newFilter[filterIdx] = newPart + this.props.onChange(newFilter) + } + render() { - const op = this.props.filter[0] - const filters = this.props.filter.slice(1) - const filterElems = filters.map(f => { - const filterOp = f[0] - const prop = f[1] - const args = f.slice(2) + const filter = this.combiningFilter() + let combiningOp = filter[0] + let filters = filter.slice(1) - const availableFilterOperators = Object.keys(GlSpec.filter_operator.values) - const filterOpOptions = availableFilterOperators.map(value => { - return - }) - - return
- - - -
+ const filterEditors = filters.map((f, idx) => { + return }) - return
- -
- {filterElems} + return
+ + {filterEditors}
} } diff --git a/src/layers/editor.jsx b/src/layers/editor.jsx index 9da36ba1..68d45bc0 100644 --- a/src/layers/editor.jsx +++ b/src/layers/editor.jsx @@ -149,7 +149,7 @@ export class LayerEditor extends React.Component { console.log('filter changed', f)} /> {this.props.layer.get('type') !== 'background' &&