From 7e8813f417f53baf04ec03d1e6f89de07e78624f Mon Sep 17 00:00:00 2001 From: Lukas Martinelli Date: Mon, 9 Jan 2017 18:56:04 +0100 Subject: [PATCH] Split filter editor into component per file --- .../filter/CombiningOperatorSelect.jsx | 3 +- src/components/filter/FilterEditor.jsx | 87 +------------------ src/components/filter/OperatorSelect.jsx | 26 ++++++ src/components/filter/SingleFilterEditor.jsx | 62 +++++++++++++ src/libs/filterops.js | 6 ++ 5 files changed, 99 insertions(+), 85 deletions(-) create mode 100644 src/components/filter/OperatorSelect.jsx create mode 100644 src/components/filter/SingleFilterEditor.jsx create mode 100644 src/libs/filterops.js diff --git a/src/components/filter/CombiningOperatorSelect.jsx b/src/components/filter/CombiningOperatorSelect.jsx index 7227be4..83bae99 100644 --- a/src/components/filter/CombiningOperatorSelect.jsx +++ b/src/components/filter/CombiningOperatorSelect.jsx @@ -3,6 +3,7 @@ import SelectInput from '../inputs/SelectInput' import input from '../../config/input.js' import { margins } from '../../config/scales.js' +import { combiningFilterOps } from '../../libs/filterops.js' class CombiningOperatorSelect extends React.Component { static propTypes = { @@ -18,7 +19,7 @@ class CombiningOperatorSelect extends React.Component { }}> combiningFilterOps.indexOf(op) < 0) - function hasCombiningFilter(filter) { return combiningFilterOps.indexOf(filter[0]) >= 0 } @@ -34,80 +27,6 @@ function hasNestedCombiningFilter(filter) { return false } - -class OperatorSelect extends React.Component { - static propTypes = { - value: React.PropTypes.string.isRequired, - onChange: React.PropTypes.func.isRequired, - } - - render() { - return [op, op])} - /> - } -} - -class SingleFilterEditor extends React.Component { - static propTypes = { - filter: React.PropTypes.array.isRequired, - onChange: React.PropTypes.func.isRequired, - properties: React.PropTypes.object, - style: React.PropTypes.object, - } - - static defaultProps = { - properties: {}, - } - - 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
- [propName, propName])} - onChange={newPropertyName => this.onFilterPartChanged(filterOp, newPropertyName, filterArgs)} - /> - this.onFilterPartChanged(newFilterOp, propertyName, filterArgs)} - /> - this.onFilterPartChanged(filterOp, propertyName, v.split(','))} - /> -
- } - -} - export default class CombiningFilterEditor extends React.Component { static propTypes = { /** Properties of the vector layer and the available fields */ diff --git a/src/components/filter/OperatorSelect.jsx b/src/components/filter/OperatorSelect.jsx new file mode 100644 index 0000000..081b0da --- /dev/null +++ b/src/components/filter/OperatorSelect.jsx @@ -0,0 +1,26 @@ +import React from 'react' +import SelectInput from '../inputs/SelectInput' + +import { otherFilterOps } from '../../libs/filterops.js' +import { margins, fontSizes } from '../../config/scales.js' + +class OperatorSelect extends React.Component { + static propTypes = { + value: React.PropTypes.string.isRequired, + onChange: React.PropTypes.func.isRequired, + } + + render() { + return [op, op])} + /> + } +} + +export default OperatorSelect diff --git a/src/components/filter/SingleFilterEditor.jsx b/src/components/filter/SingleFilterEditor.jsx new file mode 100644 index 0000000..63b2aeb --- /dev/null +++ b/src/components/filter/SingleFilterEditor.jsx @@ -0,0 +1,62 @@ +import React from 'react' +import OperatorSelect from './OperatorSelect' + +import { margins, fontSizes } from '../../config/scales.js' +import StringInput from '../inputs/StringInput' +import AutocompleteInput from '../inputs/AutocompleteInput' + +class SingleFilterEditor extends React.Component { + static propTypes = { + filter: React.PropTypes.array.isRequired, + onChange: React.PropTypes.func.isRequired, + properties: React.PropTypes.object, + style: React.PropTypes.object, + } + + static defaultProps = { + properties: {}, + } + + 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
+ [propName, propName])} + onChange={newPropertyName => this.onFilterPartChanged(filterOp, newPropertyName, filterArgs)} + /> + this.onFilterPartChanged(newFilterOp, propertyName, filterArgs)} + /> + this.onFilterPartChanged(filterOp, propertyName, v.split(','))} + /> +
+ } + +} + +export default SingleFilterEditor diff --git a/src/libs/filterops.js b/src/libs/filterops.js new file mode 100644 index 0000000..65984fd --- /dev/null +++ b/src/libs/filterops.js @@ -0,0 +1,6 @@ +import GlSpec from 'mapbox-gl-style-spec/reference/latest.js' +export const combiningFilterOps = ['all', 'any', 'none'] +export const setFilterOps = ['in', '!in'] +export const otherFilterOps = Object + .keys(GlSpec.filter_operator.values) + .filter(op => combiningFilterOps.indexOf(op) < 0)