Skip to content

Commit

Permalink
Warn if map rendering is broken due possibly due to an invalid filter
Browse files Browse the repository at this point in the history
  • Loading branch information
manisandro committed Feb 28, 2024
1 parent 387a865 commit c7af7f5
Show file tree
Hide file tree
Showing 21 changed files with 73 additions and 2 deletions.
39 changes: 37 additions & 2 deletions plugins/MapFilter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import {connect} from 'react-redux';
import axios from 'axios';
import classNames from 'classnames';
import isEmpty from 'lodash.isempty';
import {v1 as uuidv1} from 'uuid';
Expand Down Expand Up @@ -105,7 +106,8 @@ class MapFilter extends React.Component {
filters: {},
geomFilter: {},
customFilters: {},
filterEditor: null
filterEditor: null,
filterInvalid: false
};
componentDidUpdate(prevProps, prevState) {
if (this.props.theme !== prevProps.theme) {
Expand Down Expand Up @@ -210,6 +212,27 @@ class MapFilter extends React.Component {
}
});
this.props.setFilter(layerExpressions, this.state.geomFilter.geom);
// Validate parameters with test request
const themeLayer = this.props.layers.find(layer => layer.role === LayerRole.THEME);
const wmsParams = LayerUtils.buildWMSLayerParams({...themeLayer, filterParams: layerExpressions, filterGeom: this.state.geomFilter.geom}).params;
const wmsLayers = wmsParams.LAYERS.split(",");
const reqParams = {
SERVICE: 'WMS',
REQUEST: 'GetMap',
VERSION: '1.3.0',
CRS: 'EPSG:4326',
WIDTH: 10,
HEIGHT: 10,
BBOX: "-0.5,-0.5,0.5,0.5",
FILTER: wmsParams.FILTER,
FILTER_GEOM: wmsParams.FILTER_GEOM,
LAYERS: Object.keys(layerExpressions).filter(layer => wmsLayers.includes(layer)).join(",")
};
axios.get(themeLayer.url, {params: reqParams}).then(() => {
this.setState({filterInvalid: false});
}).catch(() => {
this.setState({filterInvalid: true});
});
const permalinkState = Object.entries(this.state.filters).reduce((res, [key, value]) => {
if (value.active) {
return {...res, [key]: value.values};
Expand Down Expand Up @@ -264,7 +287,8 @@ class MapFilter extends React.Component {
const classes = classNames({
"map-button": true,
"map-button-active": taskActive,
"map-button-engaged": filterActive
"map-button-engaged": filterActive && !this.state.filterInvalid,
"filter-map-button-error": filterActive && this.state.filterInvalid
});
const title = LocaleUtils.tr("appmenu.items.MapFilter");
button = (
Expand Down Expand Up @@ -317,13 +341,24 @@ class MapFilter extends React.Component {
return this.renderFilterEditor();
} else {
return [
this.renderInvalidWarning(),
...this.renderPredefinedFilters(),
this.props.allowFilterByTime ? this.renderTimeFilter() : null,
this.props.allowFilterByGeom ? this.renderGeomFilter() : null,
...this.renderCustomFilters()
];
}
};
renderInvalidWarning = () => {
if (this.state.filterInvalid) {
return (
<div className="map-filter-invalid-warning" key="InvalidFilterWarning">
<Icon icon="warning" /> <div>{LocaleUtils.tr("mapfilter.brokenrendering")}</div>
</div>
);
}
return null;
};
renderFilterEditor = () => {
const commitButtons = [
{key: 'Save', icon: 'ok', label: LocaleUtils.trmsg("mapfilter.save"), extraClasses: "button-accept"},
Expand Down
17 changes: 17 additions & 0 deletions plugins/style/MapFilter.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@
padding: 0.25em;
}

#MapFilter div.map-filter-invalid-warning {
background-color: orange;
display: flex;
align-items: center;
padding: 0.25em 0.5em;
margin: 0.25em;
}

#MapFilter div.map-filter-invalid-warning > div {
margin-left: 0.25em;
}

#MapFilter table.map-filter-entry-fields {
border-collapse: collapse;
width: 100%;
Expand Down Expand Up @@ -81,4 +93,9 @@

#MapFilter div.map-filter-editor-invalid {
background-color: rgba(255, 127, 127);
}

button.filter-map-button-error {
background-color: orange;

}
1 change: 1 addition & 0 deletions translations/ca-ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@
},
"mapfilter": {
"addcustomfilter": "",
"brokenrendering": "",
"cancel": "",
"geomfilter": "",
"invalidfilter": "",
Expand Down
1 change: 1 addition & 0 deletions translations/cs-CZ.json
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@
},
"mapfilter": {
"addcustomfilter": "",
"brokenrendering": "",
"cancel": "",
"geomfilter": "",
"invalidfilter": "",
Expand Down
1 change: 1 addition & 0 deletions translations/de-CH.json
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@
},
"mapfilter": {
"addcustomfilter": "Benutzerdef. filter hinzufügen",
"brokenrendering": "Die Kartendarstellung könnte aufgrund eines ungültigen Filterausdrucks fehlerhaft sein",
"cancel": "Abbrechen",
"geomfilter": "Geometrie",
"invalidfilter": "Ungültiger Filterausdruck",
Expand Down
1 change: 1 addition & 0 deletions translations/de-DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@
},
"mapfilter": {
"addcustomfilter": "Benutzerdef. filter hinzufügen",
"brokenrendering": "Die Kartendarstellung könnte aufgrund eines ungültigen Filterausdrucks fehlerhaft sein",
"cancel": "Abbrechen",
"geomfilter": "Geometrie",
"invalidfilter": "Ungültiger Filterausdruck",
Expand Down
1 change: 1 addition & 0 deletions translations/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@
},
"mapfilter": {
"addcustomfilter": "Add custom filter",
"brokenrendering": "Map rendering may be broken due to an invalid filter expression",
"cancel": "Cancel",
"geomfilter": "Geometry",
"invalidfilter": "Invalid filter expression",
Expand Down
1 change: 1 addition & 0 deletions translations/es-ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@
},
"mapfilter": {
"addcustomfilter": "",
"brokenrendering": "",
"cancel": "",
"geomfilter": "",
"invalidfilter": "",
Expand Down
1 change: 1 addition & 0 deletions translations/fi-FI.json
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@
},
"mapfilter": {
"addcustomfilter": "",
"brokenrendering": "",
"cancel": "",
"geomfilter": "",
"invalidfilter": "",
Expand Down
1 change: 1 addition & 0 deletions translations/fr-FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@
},
"mapfilter": {
"addcustomfilter": "Ajouter filtre personnalisé",
"brokenrendering": "Le rendu de la carte peut être interrompu à cause d'une expression filtre invalide",
"cancel": "Annuler",
"geomfilter": "Géométrique",
"invalidfilter": "Expression de filtre non valide",
Expand Down
1 change: 1 addition & 0 deletions translations/hu-HU.json
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@
},
"mapfilter": {
"addcustomfilter": "",
"brokenrendering": "",
"cancel": "",
"geomfilter": "",
"invalidfilter": "",
Expand Down
1 change: 1 addition & 0 deletions translations/it-IT.json
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@
},
"mapfilter": {
"addcustomfilter": "Aggiungi filtro personalizzato",
"brokenrendering": "Il rendering della mappa potrebbe essere interrotto a causa di un'espressione filtro invalida",
"cancel": "Annulla",
"geomfilter": "Geometrico",
"invalidfilter": "Espressione filtro non valida",
Expand Down
1 change: 1 addition & 0 deletions translations/no-NO.json
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@
},
"mapfilter": {
"addcustomfilter": "",
"brokenrendering": "",
"cancel": "",
"geomfilter": "",
"invalidfilter": "",
Expand Down
1 change: 1 addition & 0 deletions translations/pl-PL.json
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@
},
"mapfilter": {
"addcustomfilter": "",
"brokenrendering": "",
"cancel": "",
"geomfilter": "",
"invalidfilter": "",
Expand Down
1 change: 1 addition & 0 deletions translations/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@
},
"mapfilter": {
"addcustomfilter": "",
"brokenrendering": "",
"cancel": "",
"geomfilter": "",
"invalidfilter": "",
Expand Down
1 change: 1 addition & 0 deletions translations/pt-PT.json
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@
},
"mapfilter": {
"addcustomfilter": "",
"brokenrendering": "",
"cancel": "",
"geomfilter": "",
"invalidfilter": "",
Expand Down
1 change: 1 addition & 0 deletions translations/ro-RO.json
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@
},
"mapfilter": {
"addcustomfilter": "",
"brokenrendering": "",
"cancel": "",
"geomfilter": "",
"invalidfilter": "",
Expand Down
1 change: 1 addition & 0 deletions translations/ru-RU.json
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@
},
"mapfilter": {
"addcustomfilter": "",
"brokenrendering": "",
"cancel": "",
"geomfilter": "",
"invalidfilter": "",
Expand Down
1 change: 1 addition & 0 deletions translations/sv-SE.json
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@
},
"mapfilter": {
"addcustomfilter": "",
"brokenrendering": "",
"cancel": "",
"geomfilter": "",
"invalidfilter": "",
Expand Down
1 change: 1 addition & 0 deletions translations/tr-TR.json
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@
},
"mapfilter": {
"addcustomfilter": "",
"brokenrendering": "",
"cancel": "",
"geomfilter": "",
"invalidfilter": "",
Expand Down
1 change: 1 addition & 0 deletions translations/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@
"mapexport.usersize",
"mapexport.wait",
"mapfilter.addcustomfilter",
"mapfilter.brokenrendering",
"mapfilter.cancel",
"mapfilter.geomfilter",
"mapfilter.invalidfilter",
Expand Down

0 comments on commit c7af7f5

Please sign in to comment.