From c674436267d467abd2767d366a6b237a9cd840a3 Mon Sep 17 00:00:00 2001 From: Lukas Martinelli Date: Thu, 22 Dec 2016 15:49:36 +0100 Subject: [PATCH] Support id and type switching --- src/components/App.jsx | 14 ++++++++++++++ src/components/filter/FilterEditor.jsx | 6 ------ src/components/layers/LayerEditor.jsx | 23 ++++++++++++++++------- src/components/layers/LayerList.jsx | 11 ----------- 4 files changed, 30 insertions(+), 24 deletions(-) diff --git a/src/components/App.jsx b/src/components/App.jsx index b569ec42..0a9111a6 100644 --- a/src/components/App.jsx +++ b/src/components/App.jsx @@ -78,7 +78,20 @@ export default class App extends React.Component { this.setState({ mapStyle: changedStyle }) } + onLayerIdChange(oldId, newId) { + const changedLayers = this.state.mapStyle.layers.slice(0) + const idx = style.indexOfLayer(changedLayers, oldId) + + changedLayers[idx] = { + ...changedLayers[idx], + id: newId + } + + this.onLayersChange(changedLayers) + } + onLayerChanged(layer) { + console.log('layer changed', layer) const changedLayers = this.state.mapStyle.layers.slice(0) const idx = style.indexOfLayer(changedLayers, layer.id) changedLayers[idx] = layer @@ -133,6 +146,7 @@ export default class App extends React.Component { sources={this.layerWatcher.sources} vectorLayers={this.layerWatcher.vectorLayers} onLayerChanged={this.onLayerChanged.bind(this)} + onLayerIdChange={this.onLayerIdChange.bind(this)} /> : null return {}, + onLayerIdChange: () => {}, onLayerDestroyed: () => {}, } @@ -74,14 +76,20 @@ export default class LayerEditor extends React.Component { * to a {@newValue}. */ onPropertyChange(group, property, newValue) { - const changedLayer = { - ...this.props.layer, - [group]: { - ...this.props.layer[group], + if(group) { + this.props.onLayerChanged({ + ...this.props.layer, + [group]: { + ...this.props.layer[group], + [property]: newValue + } + }) + } else { + this.props.onLayerChanged({ + ...this.props.layer, [property]: newValue - } + }) } - this.props.onLayerChanged(changedLayer) } onFilterChange(newValue) { @@ -107,6 +115,8 @@ export default class LayerEditor extends React.Component { case 'settings': return this.onPropertyChange(null, 'type', v)} + onIdChange={newId => this.props.onLayerIdChange(this.props.layer.id, newId)} /> case 'source': return
{ return !(this.props.layer.type === 'background' && group.type === 'source') diff --git a/src/components/layers/LayerList.jsx b/src/components/layers/LayerList.jsx index a9410eef..b98b89ca 100644 --- a/src/components/layers/LayerList.jsx +++ b/src/components/layers/LayerList.jsx @@ -1,5 +1,4 @@ import React from 'react' -import PureRenderMixin from 'react-addons-pure-render-mixin'; import cloneDeep from 'lodash.clonedeep' import LayerListItem from './LayerListItem' @@ -24,11 +23,6 @@ class LayerListContainer extends React.Component { onLayerSelect: () => {}, } - constructor(props) { - super(props) - this.shouldComponentUpdate = PureRenderMixin.shouldComponentUpdate.bind(this); - } - onLayerDestroy(layerId) { const remainingLayers = this.props.layers.slice(0) const idx = style.indexOfLayer(remainingLayers, layerId) @@ -87,11 +81,6 @@ class LayerListContainer extends React.Component { export default class LayerList extends React.Component { static propTypes = {...layerListPropTypes} - constructor(props) { - super(props) - this.shouldComponentUpdate = PureRenderMixin.shouldComponentUpdate.bind(this); - } - onSortEnd(move) { const { oldIndex, newIndex } = move if(oldIndex === newIndex) return