From 4070da392ac84368c35e994f62baedfe3e2a0624 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Sat, 7 Dec 2024 13:01:41 +0100 Subject: [PATCH 1/3] chore: catch all "tile*" URL in playwright --- umap/tests/base.py | 3 ++- umap/tests/integration/conftest.py | 3 ++- umap/tests/integration/test_import.py | 2 -- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/umap/tests/base.py b/umap/tests/base.py index 7833d00a..81aaac3c 100644 --- a/umap/tests/base.py +++ b/umap/tests/base.py @@ -42,7 +42,7 @@ class LicenceFactory(factory.django.DjangoModelFactory): class TileLayerFactory(factory.django.DjangoModelFactory): name = "Test zoom layer" - url_template = "https://{s}.test.org/osmfr/{z}/{x}/{y}.png" + url_template = "https://tile.openstreetmap.org/{z}/{x}/{y}.png" attribution = "Test layer attribution" class Meta: @@ -156,5 +156,6 @@ def login_required(response): def mock_tiles(route): + print("Intercepted route", route.request.url) path = Path(__file__).parent / "fixtures/empty_tile.png" route.fulfill(path=path) diff --git a/umap/tests/integration/conftest.py b/umap/tests/integration/conftest.py index 9bf1aad9..733cec4d 100644 --- a/umap/tests/integration/conftest.py +++ b/umap/tests/integration/conftest.py @@ -1,4 +1,5 @@ import os +import re import subprocess import time from pathlib import Path @@ -25,7 +26,7 @@ def set_timeout(context): @pytest.fixture(autouse=True) def mock_osm_tiles(page): if not bool(os.environ.get("PWDEBUG", False)): - page.route("*/**/osmfr/**", mock_tiles) + page.route(re.compile(r".*tile\..*"), mock_tiles) @pytest.fixture diff --git a/umap/tests/integration/test_import.py b/umap/tests/integration/test_import.py index 11413eaa..757a766f 100644 --- a/umap/tests/integration/test_import.py +++ b/umap/tests/integration/test_import.py @@ -72,8 +72,6 @@ def test_umap_import_from_file(live_server, tilelayer, page): def test_umap_import_from_textarea(live_server, tilelayer, page, settings): - page.route("https://tile.openstreetmap.fr/hot/**", mock_tiles) - settings.UMAP_ALLOW_ANONYMOUS = True page.goto(f"{live_server.url}/map/new/") page.get_by_role("button", name="Open browser").click() From bf2ed185dbfe1fa2926237b97c6be4f6fc8fa7ff Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Sat, 7 Dec 2024 13:02:04 +0100 Subject: [PATCH 2/3] fix: make sure to redraw tile after a .umap import Broken since 20b2290d0033df9de20dcea51a53c24dc6f8db76 --- umap/static/umap/js/modules/umap.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/umap/static/umap/js/modules/umap.js b/umap/static/umap/js/modules/umap.js index 68a325d2..ffee4ed0 100644 --- a/umap/static/umap/js/modules/umap.js +++ b/umap/static/umap/js/modules/umap.js @@ -1554,7 +1554,8 @@ export default class Umap extends ServerStored { dataLayer.fromUmapGeoJSON(geojson) } - this._leafletMap.renderUI() + // Do a whole render + this.render(['name', 'tilelayer', 'limitBounds']) this.eachDataLayer((datalayer) => { if (mustReindex) datalayer.reindex() datalayer.redraw() From f3c95bd13d97645da2d22efa28fb894d12f0dbfa Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Sat, 7 Dec 2024 15:41:16 +0100 Subject: [PATCH 3/3] chore: refactor render and propagate to better target UI changes --- umap/static/umap/js/modules/sync/updaters.js | 1 - umap/static/umap/js/modules/umap.js | 26 +++++++++----------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/umap/static/umap/js/modules/sync/updaters.js b/umap/static/umap/js/modules/sync/updaters.js index bcc311d1..eafb51f2 100644 --- a/umap/static/umap/js/modules/sync/updaters.js +++ b/umap/static/umap/js/modules/sync/updaters.js @@ -55,7 +55,6 @@ export class DataLayerUpdater extends BaseUpdater { upsert({ value }) { // Upsert only happens when a new datalayer is created. this._umap.createDataLayer(value, false) - this._umap.render([]) } update({ key, metadata, value }) { diff --git a/umap/static/umap/js/modules/umap.js b/umap/static/umap/js/modules/umap.js index ffee4ed0..56199b08 100644 --- a/umap/static/umap/js/modules/umap.js +++ b/umap/static/umap/js/modules/umap.js @@ -1261,9 +1261,10 @@ export default class Umap extends ServerStored { } } - render(fields) { - const impacted = this.propagate(fields) - if (impacted) return // No need to run a wider reflow + render(fields = []) { + // Propagate will remove the fields it has already + // processed + fields = this.propagate(fields) const impacts = Utils.getImpactsFromSchema(fields) for (const impact of impacts) { @@ -1327,14 +1328,13 @@ export default class Umap extends ServerStored { }) }, } - let impacted = false for (const [field, impact] of Object.entries(impacts)) { if (!fields.length || fields.includes(field)) { impact() - impacted = true + fields = fields.filter((item) => item !== field) } } - return impacted + return fields } // TODO: allow to control the default datalayer @@ -1537,7 +1537,6 @@ export default class Umap extends ServerStored { importRaw(rawData) { const importedData = JSON.parse(rawData) - const mustReindex = 'sortKey' in Object.keys(importedData.properties) this.setProperties(importedData.properties) @@ -1554,13 +1553,12 @@ export default class Umap extends ServerStored { dataLayer.fromUmapGeoJSON(geojson) } - // Do a whole render - this.render(['name', 'tilelayer', 'limitBounds']) - this.eachDataLayer((datalayer) => { - if (mustReindex) datalayer.reindex() - datalayer.redraw() - }) - this.propagate() + // For now render->propagate expect a `properties.` prefix. + // Remove this when we have refactored schema and render. + const fields = Object.keys(importedData.properties).map( + (field) => `properties.${field}` + ) + this.render(fields) this._leafletMap._setDefaultCenter() this.isDirty = true }