From d61e0459037889bb662ee9b032da258c625fbca4 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Wed, 26 Mar 2025 11:21:00 +0100 Subject: [PATCH] wip: allow to sync/undo filter added/removed from table editor --- umap/static/umap/js/modules/facets.js | 14 +++++++++----- .../umap/js/modules/rendering/layers/classified.js | 8 ++++---- umap/tests/test_datalayer_s3.py | 1 + umap/tests/test_map_views.py | 1 + 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/umap/static/umap/js/modules/facets.js b/umap/static/umap/js/modules/facets.js index da896af1..e41a7e3d 100644 --- a/umap/static/umap/js/modules/facets.js +++ b/umap/static/umap/js/modules/facets.js @@ -135,7 +135,13 @@ export default class Facets { for (const [property, { label, type }] of parsed) { dumped.push([property, label, type].filter(Boolean).join('|')) } - return dumped.join(',') + const oldValue = this._umap.properties.facetKey + this._umap.properties.facetKey = dumped.join(',') + this._umap.sync.update( + 'properties.facetKey', + this._umap.properties.facetKey, + oldValue + ) } has(property) { @@ -146,15 +152,13 @@ export default class Facets { const defined = this.getDefined() if (!defined.has(property)) { defined.set(property, { label, type }) - this._umap.properties.facetKey = this.dumps(defined) - this._umap.isDirty = true + this.dumps(defined) } } remove(property) { const defined = this.getDefined() defined.delete(property) - this._umap.properties.facetKey = this.dumps(defined) - this._umap.isDirty = true + this.dumps(defined) } } diff --git a/umap/static/umap/js/modules/rendering/layers/classified.js b/umap/static/umap/js/modules/rendering/layers/classified.js index a9b2cfb6..65b234bf 100644 --- a/umap/static/umap/js/modules/rendering/layers/classified.js +++ b/umap/static/umap/js/modules/rendering/layers/classified.js @@ -117,7 +117,7 @@ export const Choropleth = FeatureGroup.extend({ }, _getValue: function (feature) { - const key = this.datalayer.options.choropleth.property || 'value' + const key = this.datalayer.options.choropleth?.property || 'value' const value = +feature.properties[key] if (!Number.isNaN(value)) return value }, @@ -130,12 +130,12 @@ export const Choropleth = FeatureGroup.extend({ this.options.colors = [] return } - const mode = this.datalayer.options.choropleth.mode - let classes = +this.datalayer.options.choropleth.classes || 5 + const mode = this.datalayer.options.choropleth?.mode + let classes = +this.datalayer.options.choropleth?.classes || 5 let breaks classes = Math.min(classes, values.length) if (mode === 'manual') { - const manualBreaks = this.datalayer.options.choropleth.breaks + const manualBreaks = this.datalayer.options.choropleth?.breaks if (manualBreaks) { breaks = manualBreaks .split(',') diff --git a/umap/tests/test_datalayer_s3.py b/umap/tests/test_datalayer_s3.py index fdebb214..f4d337e9 100644 --- a/umap/tests/test_datalayer_s3.py +++ b/umap/tests/test_datalayer_s3.py @@ -103,6 +103,7 @@ def test_get_version(map, datalayer): ], "type": "Point", }, + "id": "ExNTQ", "properties": { "_umap_options": { "color": "DarkCyan", diff --git a/umap/tests/test_map_views.py b/umap/tests/test_map_views.py index 24be6b80..d12045bc 100644 --- a/umap/tests/test_map_views.py +++ b/umap/tests/test_map_views.py @@ -694,6 +694,7 @@ def test_download(client, map, datalayer): "coordinates": [14.68896484375, 48.55297816440071], "type": "Point", }, + "id": "ExNTQ", "properties": { "_umap_options": {"color": "DarkCyan", "iconClass": "Ball"}, "description": "Da place anonymous again 755",