Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update layers list in import panel #1749

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
20 changes: 20 additions & 0 deletions umap/tests/integration/test_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,26 @@
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
Loading