From ebd3896e91857ff8a1c557b55838eff17c0225dc Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Fri, 4 Oct 2024 17:05:32 +0200 Subject: [PATCH] chore: replace native confirm by our styled ones --- umap/static/umap/js/modules/data/layer.js | 34 +++++++++++-------- umap/static/umap/js/umap.js | 16 ++++----- umap/tests/integration/test_edit_datalayer.py | 9 +++-- umap/tests/integration/test_owned_map.py | 2 +- 4 files changed, 33 insertions(+), 28 deletions(-) diff --git a/umap/static/umap/js/modules/data/layer.js b/umap/static/umap/js/modules/data/layer.js index 5668b2f5..5fa8def9 100644 --- a/umap/static/umap/js/modules/data/layer.js +++ b/umap/static/umap/js/modules/data/layer.js @@ -874,18 +874,21 @@ export class DataLayer { async restore(version) { if (!this.map.editEnabled) return - if (!confirm(translate('Are you sure you want to restore this version?'))) return - const [geojson, response, error] = await this.map.server.get( - this.getVersionUrl(version) - ) - if (!error) { - if (geojson._storage) geojson._umap_options = geojson._storage // Retrocompat. - if (geojson._umap_options) this.setOptions(geojson._umap_options) - this.empty() - if (this.isRemoteLayer()) this.fetchRemoteData() - else this.addData(geojson) - this.isDirty = true - } + this.map.dialog + .confirm(translate('Are you sure you want to restore this version?')) + .then(async () => { + const [geojson, response, error] = await this.map.server.get( + this.getVersionUrl(version) + ) + if (!error) { + if (geojson._storage) geojson._umap_options = geojson._storage // Retrocompat. + if (geojson._umap_options) this.setOptions(geojson._umap_options) + this.empty() + if (this.isRemoteLayer()) this.fetchRemoteData() + else this.addData(geojson) + this.isDirty = true + } + }) } featuresToGeoJSON() { @@ -1160,8 +1163,11 @@ export class DataLayer { 'click', function () { if (!this.isVisible()) return - if (!confirm(translate('Are you sure you want to delete this layer?'))) return - this._delete() + this.map.dialog + .confirm(translate('Are you sure you want to delete this layer?')) + .then(() => { + this._delete() + }) }, this ) diff --git a/umap/static/umap/js/umap.js b/umap/static/umap/js/umap.js index a5792c07..034e2ebf 100644 --- a/umap/static/umap/js/umap.js +++ b/umap/static/umap/js/umap.js @@ -13,7 +13,7 @@ L.Map.mergeOptions({ // we cannot rely on this because of the y is overriden by Leaflet // See https://github.com/Leaflet/Leaflet/pull/9201 // And let's remove this -y when this PR is merged and released. - demoTileInfos: { 's': 'a', 'z': 9, 'x': 265, 'y': 181, '-y': 181, 'r': '' }, + demoTileInfos: { s: 'a', z: 9, x: 265, y: 181, '-y': 181, r: '' }, licences: [], licence: '', enableMarkerDraw: true, @@ -1658,13 +1658,13 @@ U.Map = L.Map.extend({ }, clone: async function () { - if ( - confirm(L._('Are you sure you want to clone this map and all its datalayers?')) - ) { - const url = this.urls.get('map_clone', { map_id: this.options.umap_id }) - const [data, response, error] = await this.server.post(url) - if (data.redirect) window.location = data.redirect - } + this.dialog + .confirm(L._('Are you sure you want to clone this map and all its datalayers?')) + .then(async () => { + const url = this.urls.get('map_clone', { map_id: this.options.umap_id }) + const [data, response, error] = await this.server.post(url) + if (data.redirect) window.location = data.redirect + }) }, removeDataLayers: function () { diff --git a/umap/tests/integration/test_edit_datalayer.py b/umap/tests/integration/test_edit_datalayer.py index 12c92c10..37d234c7 100644 --- a/umap/tests/integration/test_edit_datalayer.py +++ b/umap/tests/integration/test_edit_datalayer.py @@ -60,12 +60,11 @@ def test_cancel_deleting_datalayer_should_restore( expect(layers).to_have_count(1) expect(markers).to_have_count(1) page.get_by_role("link", name="Manage layers").click() - page.once("dialog", lambda dialog: dialog.accept()) page.locator(".panel.right").get_by_title("Delete layer").click() + page.get_by_role("button", name="OK").click() expect(markers).to_have_count(0) page.get_by_role("button", name="Open browser").click() expect(page.get_by_text("test datalayer")).to_be_hidden() - page.once("dialog", lambda dialog: dialog.accept()) page.get_by_role("button", name="Cancel edits").click() page.locator("dialog").get_by_role("button", name="OK").click() expect(markers).to_have_count(1) @@ -174,8 +173,8 @@ def test_can_restore_version(live_server, openmap, page, datalayer): page.get_by_role("link", name="Manage layers").click() page.locator(".panel.right").get_by_title("Edit", exact=True).click() page.get_by_text("Versions").click() - page.once("dialog", lambda dialog: dialog.accept()) page.get_by_role("button", name="Restore this version").last.click() + page.get_by_role("button", name="OK").click() expect(marker).to_have_class(re.compile(".*umap-ball-icon.*")) @@ -196,8 +195,8 @@ def test_deleting_datalayer_should_remove_from_browser_and_layers_list( page.get_by_role("link", name="Manage layers").click() expect(panel.get_by_text("test datalayer")).to_be_visible() expect(edit_panel.get_by_text("test datalayer")).to_be_visible() - page.once("dialog", lambda dialog: dialog.accept()) page.locator(".panel.right").get_by_title("Delete layer").click() + page.get_by_role("button", name="OK").click() expect(panel.get_by_text("test datalayer")).to_be_hidden() expect(edit_panel.get_by_text("test datalayer")).to_be_hidden() @@ -210,6 +209,6 @@ def test_deleting_datalayer_should_remove_from_caption( page.get_by_role("button", name="About").click() page.get_by_role("link", name="Manage layers").click() expect(panel.get_by_text("test datalayer")).to_be_visible() - page.once("dialog", lambda dialog: dialog.accept()) page.locator(".panel.right").get_by_title("Delete layer").click() + page.get_by_role("button", name="OK").click() expect(panel.get_by_text("test datalayer")).to_be_hidden() diff --git a/umap/tests/integration/test_owned_map.py b/umap/tests/integration/test_owned_map.py index 77518d69..34222650 100644 --- a/umap/tests/integration/test_owned_map.py +++ b/umap/tests/integration/test_owned_map.py @@ -234,8 +234,8 @@ def test_can_delete_datalayer(live_server, map, login, datalayer): expect(layers).to_have_count(1) expect(markers).to_have_count(1) page.get_by_role("link", name="Manage layers").click() - page.once("dialog", lambda dialog: dialog.accept()) page.locator(".panel.right").get_by_title("Delete layer").click() + page.get_by_role("button", name="OK").click() with page.expect_response(re.compile(r".*/datalayer/delete/.*")): page.get_by_role("button", name="Save").click() expect(markers).to_have_count(0)