mirror of
https://github.com/umap-project/umap.git
synced 2025-05-04 13:41:49 +02:00
Unset datalayer._future_uuid
after the layer has been saved on the server.
This commit is contained in:
parent
d68a34e591
commit
31c15e7387
2 changed files with 35 additions and 7 deletions
|
@ -129,6 +129,22 @@ export class DataLayer {
|
|||
return this._isDeleted
|
||||
}
|
||||
|
||||
/**
|
||||
* When receiving a reference version, discard the future uuid
|
||||
* because the layer is now created on the server.
|
||||
*/
|
||||
set _reference_version(version){
|
||||
console.debug("set _reference_version", version)
|
||||
if (version !== undefined) {
|
||||
this.__reference_version = version
|
||||
this._future_uuid = undefined
|
||||
}
|
||||
}
|
||||
|
||||
get _reference_version(){
|
||||
return this.__reference_version
|
||||
}
|
||||
|
||||
getSyncMetadata() {
|
||||
return {
|
||||
subject: 'datalayer',
|
||||
|
@ -1057,6 +1073,7 @@ export class DataLayer {
|
|||
// Filename support is shaky, don't do it for now.
|
||||
const blob = new Blob([JSON.stringify(geojson)], { type: 'application/json' })
|
||||
formData.append('geojson', blob)
|
||||
console.log("map_id", this.map.options.umap_id, "pk", this.umap_id || this._future_uuid, "created", this.createdOnServer)
|
||||
const saveURL = this.map.urls.get('datalayer_save', {
|
||||
map_id: this.map.options.umap_id,
|
||||
pk: this.umap_id || this._future_uuid,
|
||||
|
@ -1095,7 +1112,7 @@ export class DataLayer {
|
|||
this._reference_version = response.headers.get('X-Datalayer-Version')
|
||||
this.sync.update('_reference_version', this._reference_version)
|
||||
|
||||
// this.setUmapId(data.id)
|
||||
this.setUmapId(data.id)
|
||||
this.updateOptions(data)
|
||||
this.backupOptions()
|
||||
this.connectToMap()
|
||||
|
|
|
@ -129,32 +129,43 @@ def test_can_change_name(live_server, openmap, page, datalayer):
|
|||
|
||||
|
||||
def test_can_create_new_datalayer(live_server, openmap, page, datalayer):
|
||||
"""
|
||||
Test the creation and editing of a new datalayer.
|
||||
|
||||
This test verifies that:
|
||||
1. A new datalayer can be created and saved.
|
||||
2. The newly created datalayer appears in the UI and is saved in the database.
|
||||
3. Editing the same datalayer updates it instead of creating a new one.
|
||||
4. The UI reflects the changes and the database is updated correctly.
|
||||
5. The 'dirty' state of the map is managed correctly during these operations.
|
||||
"""
|
||||
|
||||
page.goto(
|
||||
f"{live_server.url}{openmap.get_absolute_url()}?edit&onLoadPanel=databrowser"
|
||||
)
|
||||
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("my new layer")
|
||||
expect(page.get_by_text("my new layer")).to_be_visible()
|
||||
page.locator('input[name="name"]').fill("Layer A")
|
||||
expect(page.get_by_text("Layer A")).to_be_visible()
|
||||
with page.expect_response(re.compile(".*/datalayer/create/.*")):
|
||||
page.get_by_role("button", name="Save").click()
|
||||
assert DataLayer.objects.count() == 2
|
||||
saved = DataLayer.objects.last()
|
||||
assert saved.name == "my new layer"
|
||||
assert saved.name == "Layer A"
|
||||
expect(page.locator(".umap-is-dirty")).to_be_hidden()
|
||||
# Edit again, it should not create a new datalayer
|
||||
page.get_by_role("link", name="Manage layers").click()
|
||||
page.locator(".panel.right").get_by_title("Edit", exact=True).first.click()
|
||||
page.locator('input[name="name"]').click()
|
||||
page.locator('input[name="name"]').fill("my new layer with a new name")
|
||||
expect(page.get_by_text("my new layer with a new name")).to_be_visible()
|
||||
page.locator('input[name="name"]').fill("Layer A with a new name")
|
||||
expect(page.get_by_text("Layer A with a new name")).to_be_visible()
|
||||
page.get_by_role("button", name="Save").click()
|
||||
with page.expect_response(re.compile(".*/datalayer/update/.*")):
|
||||
page.get_by_role("button", name="Save").click()
|
||||
assert DataLayer.objects.count() == 2
|
||||
saved = DataLayer.objects.last()
|
||||
assert saved.name == "my new layer with a new name"
|
||||
assert saved.name == "Layer A with a new name"
|
||||
expect(page.locator(".umap-is-dirty")).to_be_hidden()
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue