Skip to content

Commit

Permalink
fix: update layers list in import panel
Browse files Browse the repository at this point in the history
fix #1729
  • Loading branch information
yohanboniface committed Apr 16, 2024
1 parent 05fd33d commit 80db180
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 13 deletions.
27 changes: 14 additions & 13 deletions umap/static/umap/js/umap.importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,6 @@ U.Importer = L.Class.extend({
{ type: 'checkbox', name: 'clear', id: 'datalayer-clear-check' },
this.clearLabel
)
let option
this.map.eachDataLayerReverse((datalayer) => {
if (datalayer.isLoaded() && !datalayer.isRemoteLayer()) {
const id = L.stamp(datalayer)
option = L.DomUtil.add('option', '', this.layerInput, datalayer.options.name)
option.value = id
}
})
L.DomUtil.element(
'option',
{ value: '', textContent: L._('Import in a new layer') },
this.layerInput
)
L.DomUtil.element(
'option',
{ value: '', textContent: L._('Choose the data format') },
Expand Down Expand Up @@ -123,6 +110,20 @@ U.Importer = L.Class.extend({
const onLoad = this.map.editPanel.open({ data: { html: this.container } })
onLoad.then(() => {
this.fileInput.value = null
this.layerInput.innerHTML = ''
let option
this.map.eachDataLayerReverse((datalayer) => {
if (datalayer.isLoaded() && !datalayer.isRemoteLayer()) {
const id = L.stamp(datalayer)
option = L.DomUtil.add('option', '', this.layerInput, datalayer.options.name)
option.value = id
}
})
L.DomUtil.element(
'option',
{ value: '', textContent: L._('Import in a new layer') },
this.layerInput
)
})
},

Expand Down
22 changes: 22 additions & 0 deletions umap/tests/integration/test_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,28 @@
pytestmark = pytest.mark.django_db


def test_layers_list_is_updated(live_server, tilelayer, page):
page.goto(f"{live_server.url}/map/new/")
page.get_by_role("link", name="Import data (Ctrl+I)").click()
# Should work
page.get_by_label("Choose the layer to import").select_option(
label="Import in a new layer"
)
page.get_by_role("link", name="Manage layers").click()
page.get_by_role("button", name="Add a layer").click()
page.locator('input[name="name"]').click()
page.locator('input[name="name"]').fill("foobar")
page.get_by_role("link", name="Import data (Ctrl+I)").click()
# Should still work
page.get_by_label("Choose the layer to import").select_option(
label="Import in a new layer"
)
# Now layer should be visible in the options
page.get_by_label("Choose the layer to import").select_option(
label="foobar"
)


def test_umap_import_from_file(live_server, tilelayer, page):
page.goto(f"{live_server.url}/map/new/")
page.get_by_title("Import data").click()
Expand Down

0 comments on commit 80db180

Please sign in to comment.