Merge pull request #1832 from umap-project/delete-datalayer-propagate

fix: do not close blindly editPanel when deleting a layer
This commit is contained in:
Yohan Boniface 2024-05-17 17:20:36 +02:00 committed by GitHub
commit 0e24e3041e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 47 additions and 1 deletions

View file

@ -7,6 +7,15 @@ export default class Caption {
this.map = map this.map = map
} }
isOpen() {
return Boolean(document.querySelector('.on .umap-caption'))
}
refresh() {
if (!this.isOpen()) return
this.open()
}
open() { open() {
const container = DomUtil.create('div', 'umap-caption') const container = DomUtil.create('div', 'umap-caption')
DomUtil.createTitle(container, this.map.options.name, 'icon-caption') DomUtil.createTitle(container, this.map.options.name, 'icon-caption')

View file

@ -607,7 +607,6 @@ U.DataLayer.include({
if (!this.isVisible()) return if (!this.isVisible()) return
if (!confirm(L._('Are you sure you want to delete this layer?'))) return if (!confirm(L._('Are you sure you want to delete this layer?'))) return
this._delete() this._delete()
this.map.editPanel.close()
}, },
this this
) )
@ -626,6 +625,13 @@ U.DataLayer.include({
return `show_with_datalayer_${L.stamp(this)}` return `show_with_datalayer_${L.stamp(this)}`
}, },
propagateDelete: function () {
const els = this.getHidableElements()
for (const el of els) {
L.DomUtil.remove(el)
}
},
propagateRemote: function () { propagateRemote: function () {
const els = this.getHidableElements() const els = this.getHidableElements()
for (const el of els) { for (const el of els) {
@ -653,6 +659,7 @@ U.DataLayer.include({
U.DataLayer.addInitHook(function () { U.DataLayer.addInitHook(function () {
this.on('hide', this.propagateHide) this.on('hide', this.propagateHide)
this.on('show', this.propagateShow) this.on('show', this.propagateShow)
this.on('erase', this.propagateDelete)
if (this.isVisible()) this.propagateShow() if (this.isVisible()) this.propagateShow()
}) })

View file

@ -468,6 +468,7 @@ U.Map = L.Map.extend({
onDataLayersChanged: function () { onDataLayersChanged: function () {
if (this.browser) this.browser.update() if (this.browser) this.browser.update()
this.caption.refresh()
}, },
ensurePanesOrder: function () { ensurePanesOrder: function () {

View file

@ -183,3 +183,32 @@ def test_can_edit_layer_on_ctrl_shift_click(live_server, openmap, page, datalaye
page.goto(f"{live_server.url}{openmap.get_absolute_url()}?edit") page.goto(f"{live_server.url}{openmap.get_absolute_url()}?edit")
page.locator(".leaflet-marker-icon").click(modifiers=[modifier, "Shift"]) page.locator(".leaflet-marker-icon").click(modifiers=[modifier, "Shift"])
expect(page.get_by_text("Layer properties")).to_be_visible() expect(page.get_by_text("Layer properties")).to_be_visible()
def test_deleting_datalayer_should_remove_from_browser_and_layers_list(
live_server, openmap, datalayer, page
):
page.goto(f"{live_server.url}{openmap.get_absolute_url()}?edit")
panel = page.locator(".panel.left")
edit_panel = page.locator(".panel.right")
page.get_by_title("See layers").click()
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()
expect(panel.get_by_text("test datalayer")).to_be_hidden()
expect(edit_panel.get_by_text("test datalayer")).to_be_hidden()
def test_deleting_datalayer_should_remove_from_caption(
live_server, openmap, datalayer, page
):
page.goto(f"{live_server.url}{openmap.get_absolute_url()}?edit")
panel = page.locator(".panel.left")
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()
expect(panel.get_by_text("test datalayer")).to_be_hidden()