From 79b251d8b970245ce10693c57f22bc50d3ffb2f4 Mon Sep 17 00:00:00 2001 From: orangemug Date: Thu, 17 May 2018 10:55:55 +0100 Subject: [PATCH] DRY up the code. --- src/components/sources/SourceTypeEditor.jsx | 131 ++++---------------- 1 file changed, 26 insertions(+), 105 deletions(-) diff --git a/src/components/sources/SourceTypeEditor.jsx b/src/components/sources/SourceTypeEditor.jsx index 403a980..c55b46d 100644 --- a/src/components/sources/SourceTypeEditor.jsx +++ b/src/components/sources/SourceTypeEditor.jsx @@ -6,100 +6,6 @@ import StringInput from '../inputs/StringInput' import NumberInput from '../inputs/NumberInput' import SelectInput from '../inputs/SelectInput' -class DemJSONSourceEditor extends React.Component { - static propTypes = { - source: PropTypes.object.isRequired, - onChange: PropTypes.func.isRequired, - } - - render() { - return
- - this.props.onChange({ - ...this.props.source, - url: url - })} - /> - - - this.props.onChange({ - ...this.props.source, - encoding: encoding - })} - value={this.props.source.encoding || styleSpec.latest.source_raster_dem.encoding.default} - /> - -
- } -} - -class DemURLSourceEditor extends React.Component { - static propTypes = { - source: PropTypes.object.isRequired, - onChange: PropTypes.func.isRequired, - } - - changeTileUrl(idx, value) { - const tiles = this.props.source.tiles.slice(0) - tiles[idx] = value - this.props.onChange({ - ...this.props.source, - tiles: tiles - }) - } - - renderTileUrls() { - const prefix = ['1st', '2nd', '3rd', '4th', '5th', '6th', '7th'] - const tiles = this.props.source.tiles || [] - return tiles.map((tileUrl, tileIndex) => { - return - - - }) - } - - render() { - return
- {this.renderTileUrls()} - - this.props.onChange({ - ...this.props.source, - minzoom: minzoom - })} - /> - - - this.props.onChange({ - ...this.props.source, - maxzoom: maxzoom - })} - /> - - - this.props.onChange({ - ...this.props.source, - encoding: encoding - })} - value={this.props.source.encoding || styleSpec.latest.source_raster_dem.encoding.default} - /> - -
- - } -} class TileJSONSourceEditor extends React.Component { static propTypes = { @@ -108,15 +14,18 @@ class TileJSONSourceEditor extends React.Component { } render() { - return - this.props.onChange({ - ...this.props.source, - url: url - })} - /> - + return
+ + this.props.onChange({ + ...this.props.source, + url: url + })} + /> + + {this.props.children} +
} } @@ -169,6 +78,7 @@ class TileURLSourceEditor extends React.Component { })} /> + {this.props.children} } @@ -211,8 +121,19 @@ class SourceTypeEditor extends React.Component { case 'tilexyz_vector': return case 'tilejson_raster': return case 'tilexyz_raster': return - case 'tilejson_raster-dem': return - case 'tilexyz_raster-dem': return + case 'tilejson_raster-dem': return + case 'tilexyz_raster-dem': return + + this.props.onChange({ + ...this.props.source, + encoding: encoding + })} + value={this.props.source.encoding || styleSpec.latest.source_raster_dem.encoding.default} + /> + + default: return null } }