mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2024-12-27 09:35:25 +01:00
Duplicate layer ids now show errors inline.
This commit is contained in:
parent
b5c09a4f17
commit
61ba399e1c
4 changed files with 31 additions and 15 deletions
|
@ -335,22 +335,33 @@ export default class App extends React.Component {
|
||||||
newStyle.layers.forEach((layer, index) => {
|
newStyle.layers.forEach((layer, index) => {
|
||||||
if (layer.id === "" && foundLayers.has(layer.id)) {
|
if (layer.id === "" && foundLayers.has(layer.id)) {
|
||||||
const message = `Duplicate layer: ${formatLayerId(layer.id)}`;
|
const message = `Duplicate layer: ${formatLayerId(layer.id)}`;
|
||||||
layerErrors.push({
|
const error = new Error(
|
||||||
message,
|
`layers[${index}]: duplicate layer id [empty_string], previously used`
|
||||||
parsed: {
|
);
|
||||||
type: "layer",
|
layerErrors.push(error);
|
||||||
data: {
|
|
||||||
index,
|
|
||||||
message,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
foundLayers.set(layer.id, true);
|
foundLayers.set(layer.id, true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const mappedErrors = errors.map(error => {
|
const mappedErrors = layerErrors.concat(errors).map(error => {
|
||||||
|
const dupMatch = error.message.match(/layers\[(\d+)\]: (duplicate layer id "?(.*)"?, previously used)/);
|
||||||
|
if (dupMatch) {
|
||||||
|
const [matchStr, index, message] = dupMatch;
|
||||||
|
return {
|
||||||
|
message: error.message,
|
||||||
|
parsed: {
|
||||||
|
type: "layer",
|
||||||
|
data: {
|
||||||
|
index,
|
||||||
|
key: "id",
|
||||||
|
message,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// duplicate layer id
|
||||||
const layerMatch = error.message.match(/layers\[(\d+)\]\.(?:(\S+)\.)?(\S+): (.*)/);
|
const layerMatch = error.message.match(/layers\[(\d+)\]\.(?:(\S+)\.)?(\S+): (.*)/);
|
||||||
if (layerMatch) {
|
if (layerMatch) {
|
||||||
const [matchStr, index, group, property, message] = layerMatch;
|
const [matchStr, index, group, property, message] = layerMatch;
|
||||||
|
@ -372,7 +383,7 @@ export default class App extends React.Component {
|
||||||
message: error.message,
|
message: error.message,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}).concat(layerErrors);
|
});
|
||||||
|
|
||||||
let dirtyMapStyle = undefined;
|
let dirtyMapStyle = undefined;
|
||||||
if (errors.length > 0) {
|
if (errors.length > 0) {
|
||||||
|
@ -753,6 +764,7 @@ export default class App extends React.Component {
|
||||||
|
|
||||||
const bottomPanel = (this.state.errors.length + this.state.infos.length) > 0 ? <MessagePanel
|
const bottomPanel = (this.state.errors.length + this.state.infos.length) > 0 ? <MessagePanel
|
||||||
currentLayer={selectedLayer}
|
currentLayer={selectedLayer}
|
||||||
|
selectedLayerIndex={this.state.selectedLayerIndex}
|
||||||
onLayerSelect={this.onLayerSelect}
|
onLayerSelect={this.onLayerSelect}
|
||||||
mapStyle={this.state.mapStyle}
|
mapStyle={this.state.mapStyle}
|
||||||
errors={this.state.errors}
|
errors={this.state.errors}
|
||||||
|
|
|
@ -9,6 +9,7 @@ class MessagePanel extends React.Component {
|
||||||
mapStyle: PropTypes.object,
|
mapStyle: PropTypes.object,
|
||||||
onLayerSelect: PropTypes.func,
|
onLayerSelect: PropTypes.func,
|
||||||
currentLayer: PropTypes.object,
|
currentLayer: PropTypes.object,
|
||||||
|
selectedLayerIndex: PropTypes.number,
|
||||||
}
|
}
|
||||||
|
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
|
@ -16,6 +17,7 @@ class MessagePanel extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
const {selectedLayerIndex} = this.props;
|
||||||
const errors = this.props.errors.map((error, idx) => {
|
const errors = this.props.errors.map((error, idx) => {
|
||||||
let content;
|
let content;
|
||||||
if (error.parsed && error.parsed.type === "layer") {
|
if (error.parsed && error.parsed.type === "layer") {
|
||||||
|
@ -25,12 +27,12 @@ class MessagePanel extends React.Component {
|
||||||
content = (
|
content = (
|
||||||
<>
|
<>
|
||||||
Layer <span>{formatLayerId(layerId)}</span>: {parsed.data.message}
|
Layer <span>{formatLayerId(layerId)}</span>: {parsed.data.message}
|
||||||
{currentLayer.id !== layerId &&
|
{selectedLayerIndex !== parsed.data.index &&
|
||||||
<>
|
<>
|
||||||
—
|
—
|
||||||
<button
|
<button
|
||||||
className="maputnik-message-panel__switch-button"
|
className="maputnik-message-panel__switch-button"
|
||||||
onClick={() => this.props.onLayerSelect(layerId)}
|
onClick={() => this.props.onLayerSelect(parsed.data.index)}
|
||||||
>
|
>
|
||||||
switch to layer
|
switch to layer
|
||||||
</button>
|
</button>
|
||||||
|
|
|
@ -19,6 +19,7 @@ import {MdMoreVert} from 'react-icons/md'
|
||||||
|
|
||||||
import { changeType, changeProperty } from '../../libs/layer'
|
import { changeType, changeProperty } from '../../libs/layer'
|
||||||
import layout from '../../config/layout.json'
|
import layout from '../../config/layout.json'
|
||||||
|
import {formatLayerId} from '../util/format';
|
||||||
|
|
||||||
|
|
||||||
function getLayoutForType (type) {
|
function getLayoutForType (type) {
|
||||||
|
@ -292,7 +293,7 @@ export default class LayerEditor extends React.Component {
|
||||||
<header>
|
<header>
|
||||||
<div className="layer-header">
|
<div className="layer-header">
|
||||||
<h2 className="layer-header__title">
|
<h2 className="layer-header__title">
|
||||||
Layer: {this.props.layer.id}
|
Layer: {formatLayerId(this.props.layer.id)}
|
||||||
</h2>
|
</h2>
|
||||||
<div className="layer-header__info">
|
<div className="layer-header__info">
|
||||||
<Wrapper
|
<Wrapper
|
||||||
|
|
|
@ -15,6 +15,7 @@ class LayerIdBlock extends React.Component {
|
||||||
render() {
|
render() {
|
||||||
return <InputBlock label={"ID"} fieldSpec={latest.layer.id}
|
return <InputBlock label={"ID"} fieldSpec={latest.layer.id}
|
||||||
data-wd-key={this.props.wdKey}
|
data-wd-key={this.props.wdKey}
|
||||||
|
error={this.props.error}
|
||||||
>
|
>
|
||||||
<StringInput
|
<StringInput
|
||||||
value={this.props.value}
|
value={this.props.value}
|
||||||
|
|
Loading…
Reference in a new issue