Added layer comments via 'metadata.maputnik:comment' (issue #28)

This commit is contained in:
orangemug 2017-03-07 12:24:15 +00:00
parent bbf26a3f38
commit a53d7763ba
5 changed files with 98 additions and 19 deletions

View file

@ -20,16 +20,33 @@ class StringInput extends React.Component {
} }
render() { render() {
return <input let tag;
className="maputnik-string" let classes;
style={this.props.style}
value={this.state.value} if(!!this.props.multi) {
placeholder={this.props.default} tag = "textarea"
onChange={e => this.setState({ value: e.target.value })} classes = [
onBlur={() => { "maputnik-string",
"maputnik-string--multi"
]
}
else {
tag = "input"
classes = [
"maputnik-string"
]
}
return React.createElement(tag, {
className: classes.join(" "),
style: this.props.style,
value: this.state.value,
placeholder: this.props.default,
onChange: e => this.setState({ value: e.target.value }),
onBlur: () => {
if(this.state.value!==this.props.value) this.props.onChange(this.state.value) if(this.state.value!==this.props.value) this.props.onChange(this.state.value)
}} }
/> });
} }
} }

View file

@ -0,0 +1,24 @@
import React from 'react'
import InputBlock from '../inputs/InputBlock'
import StringInput from '../inputs/StringInput'
class MetadataBlock extends React.Component {
static propTypes = {
value: React.PropTypes.string,
onChange: React.PropTypes.func.isRequired,
}
render() {
return <InputBlock label={"Comments"}>
<StringInput
multi={true}
value={this.props.value}
onChange={this.props.onChange}
default="Comment..."
/>
</InputBlock>
}
}
export default MetadataBlock

View file

@ -8,6 +8,7 @@ import LayerTypeBlock from './LayerTypeBlock'
import LayerIdBlock from './LayerIdBlock' import LayerIdBlock from './LayerIdBlock'
import MinZoomBlock from './MinZoomBlock' import MinZoomBlock from './MinZoomBlock'
import MaxZoomBlock from './MaxZoomBlock' import MaxZoomBlock from './MaxZoomBlock'
import CommentBlock from './CommentBlock'
import LayerSourceBlock from './LayerSourceBlock' import LayerSourceBlock from './LayerSourceBlock'
import LayerSourceLayerBlock from './LayerSourceLayerBlock' import LayerSourceLayerBlock from './LayerSourceLayerBlock'
@ -110,6 +111,11 @@ export default class LayerEditor extends React.Component {
} }
renderGroupType(type, fields) { renderGroupType(type, fields) {
let comment = ""
if(this.props.layer.metadata) {
comment = this.props.layer.metadata['maputnik:comment']
}
switch(type) { switch(type) {
case 'layer': return <div> case 'layer': return <div>
<LayerIdBlock <LayerIdBlock
@ -140,6 +146,10 @@ export default class LayerEditor extends React.Component {
value={this.props.layer.maxzoom} value={this.props.layer.maxzoom}
onChange={v => this.changeProperty(null, 'maxzoom', v)} onChange={v => this.changeProperty(null, 'maxzoom', v)}
/> />
<CommentBlock
value={comment}
onChange={v => this.changeProperty('metadata', 'maputnik:comment', v == "" ? undefined : v)}
/>
</div> </div>
case 'filter': return <div> case 'filter': return <div>
<div className="maputnik-filter-editor-wrapper"> <div className="maputnik-filter-editor-wrapper">

View file

@ -27,18 +27,41 @@ export function changeType(layer, newType) {
* to a {@newValue}. * to a {@newValue}.
*/ */
export function changeProperty(layer, group, property, newValue) { export function changeProperty(layer, group, property, newValue) {
if(group) { // Remove the property if undefined
return { if(newValue === undefined) {
...layer, if(group) {
[group]: { const newLayer = {
...layer[group], ...layer
};
delete newLayer[group][property];
// Remove the group if it is now empty
if(Object.keys(newLayer[group]).length < 1) {
delete newLayer[group];
}
return newLayer;
} else {
const newLayer = {
...layer
};
delete newLayer[property];
return newLayer;
}
}
else {
if(group) {
return {
...layer,
[group]: {
...layer[group],
[property]: newValue
}
}
} else {
return {
...layer,
[property]: newValue [property]: newValue
} }
} }
} else {
return {
...layer,
[property]: newValue
}
} }
} }

View file

@ -15,6 +15,11 @@
.maputnik-string { .maputnik-string {
@extend .maputnik-input; @extend .maputnik-input;
&--multi {
resize: vertical;
height: 78px;
}
} }
.maputnik-number { .maputnik-number {