mirror of
https://github.com/umap-project/umap.git
synced 2025-04-28 19:42:36 +02:00
fixup: prevent to reload a datalayer after other peer has saved it
The scenario to reproduce is: - peer A creates a datalayer - peer B add a marker on that datalayer - peer B saves the datalayer Before this fix, after the save, peer A would get a new _referenceVersion for this datalayer, and the render method would make a hide/show, which would refetch the data from the server, duplicating it. So forcing the _loaded to be true in this situation prevent this. We may want to rework the "_loaded" pattern, maybe with the server returning in a datalayer metadata the length of the data it get for this given datalayer, so the client knows if it is worth getting data for a layer when itself (the client) does not have any. Co-authored-by: David Larlet <david@larlet.fr>
This commit is contained in:
parent
a172c4abea
commit
eca7ad4772
2 changed files with 8 additions and 5 deletions
|
@ -63,6 +63,7 @@ export class DataLayerUpdater extends BaseUpdater {
|
||||||
update({ key, metadata, value }) {
|
update({ key, metadata, value }) {
|
||||||
const datalayer = this.getDataLayerFromID(metadata.id)
|
const datalayer = this.getDataLayerFromID(metadata.id)
|
||||||
if (fieldInSchema(key)) {
|
if (fieldInSchema(key)) {
|
||||||
|
datalayer._loaded = true
|
||||||
this.updateObjectValue(datalayer, key, value)
|
this.updateObjectValue(datalayer, key, value)
|
||||||
} else {
|
} else {
|
||||||
console.debug(
|
console.debug(
|
||||||
|
@ -92,7 +93,7 @@ export class FeatureUpdater extends BaseUpdater {
|
||||||
upsert({ metadata, value }) {
|
upsert({ metadata, value }) {
|
||||||
const { id, layerId } = metadata
|
const { id, layerId } = metadata
|
||||||
const datalayer = this.getDataLayerFromID(layerId)
|
const datalayer = this.getDataLayerFromID(layerId)
|
||||||
const feature = this.getFeatureFromMetadata(metadata, value)
|
const feature = this.getFeatureFromMetadata(metadata)
|
||||||
|
|
||||||
if (feature) {
|
if (feature) {
|
||||||
feature.geometry = value.geometry
|
feature.geometry = value.geometry
|
||||||
|
@ -109,7 +110,7 @@ export class FeatureUpdater extends BaseUpdater {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (key === 'geometry') {
|
if (key === 'geometry') {
|
||||||
const feature = this.getFeatureFromMetadata(metadata, value)
|
const feature = this.getFeatureFromMetadata(metadata)
|
||||||
feature.geometry = value
|
feature.geometry = value
|
||||||
} else {
|
} else {
|
||||||
this.updateObjectValue(feature, key, value)
|
this.updateObjectValue(feature, key, value)
|
||||||
|
|
|
@ -421,9 +421,11 @@ def test_should_sync_datalayers(new_page, asgi_live_server, tilelayer):
|
||||||
1
|
1
|
||||||
).click()
|
).click()
|
||||||
|
|
||||||
# Now peerA saves the layer 2 to the server
|
# Peer A should not be in dirty state
|
||||||
with peerA.expect_response(re.compile(".*/datalayer/update/.*")):
|
expect(peerA.locator("body")).not_to_have_class(re.compile(".*umap-is-dirty.*"))
|
||||||
peerA.get_by_role("button", name="Save").click()
|
|
||||||
|
# Peer A should only have two markers
|
||||||
|
expect(peerA.locator(".leaflet-marker-icon")).to_have_count(2)
|
||||||
|
|
||||||
assert DataLayer.objects.count() == 2
|
assert DataLayer.objects.count() == 2
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue