diff --git a/umap/static/umap/js/umap.importer.js b/umap/static/umap/js/umap.importer.js index ec1aea09c..386e45da9 100644 --- a/umap/static/umap/js/umap.importer.js +++ b/umap/static/umap/js/umap.importer.js @@ -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') }, @@ -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 + ) }) }, diff --git a/umap/tests/integration/test_import.py b/umap/tests/integration/test_import.py index 684eae046..1be5ffd6d 100644 --- a/umap/tests/integration/test_import.py +++ b/umap/tests/integration/test_import.py @@ -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()