From 9718f11faff9c6dfd0688f9e55912ece5d4db235 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Fri, 21 Mar 2025 16:33:09 +0100 Subject: [PATCH] wip: allow to mark an operation as not undoable Co-authored-by: David Larlet --- umap/static/umap/js/modules/data/layer.js | 6 +++++- umap/static/umap/js/modules/sync/engine.js | 6 +++--- umap/static/umap/js/modules/sync/undo.js | 11 ++++------- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/umap/static/umap/js/modules/data/layer.js b/umap/static/umap/js/modules/data/layer.js index eaf9a4ce..4f42a1e1 100644 --- a/umap/static/umap/js/modules/data/layer.js +++ b/umap/static/umap/js/modules/data/layer.js @@ -1098,7 +1098,11 @@ export class DataLayer extends ServerStored { setReferenceVersion({ response, sync }) { this._referenceVersion = response.headers.get('X-Datalayer-Version') - if (sync) this.sync.update('_referenceVersion', this._referenceVersion) + if (sync) { + this.sync.update('_referenceVersion', this._referenceVersion, null, { + undo: false, + }) + } } async save() { diff --git a/umap/static/umap/js/modules/sync/engine.js b/umap/static/umap/js/modules/sync/engine.js index 04a07927..ccdd3dff 100644 --- a/umap/static/umap/js/modules/sync/engine.js +++ b/umap/static/umap/js/modules/sync/engine.js @@ -169,7 +169,7 @@ export class SyncEngine { this._send(operation) } - update(subject, metadata, key, value, oldValue) { + update(subject, metadata, key, value, oldValue, { undo } = { undo: true }) { const operation = { verb: 'update', subject, @@ -186,7 +186,7 @@ export class SyncEngine { this._batch.push(stage) return } - this._undoManager.add(stage) + if (undo) this._undoManager.add(stage) this._send(operation) } @@ -211,7 +211,7 @@ export class SyncEngine { async save() { const needSave = new Map() if (!this._umap.id) { - // There is no operation for fist map save + // There is no operation for first map save needSave.set(this._umap, []) } for (const operation of this._operations.sorted()) { diff --git a/umap/static/umap/js/modules/sync/undo.js b/umap/static/umap/js/modules/sync/undo.js index 8ee57890..d16263cc 100644 --- a/umap/static/umap/js/modules/sync/undo.js +++ b/umap/static/umap/js/modules/sync/undo.js @@ -35,13 +35,10 @@ export class UndoManager { } add(stage) { - // FIXME make it more generic - if (!stage.operation || stage.operation.key !== '_referenceVersion') { - stage.operation.dirty = true - this._redoStack = [] - this._undoStack.push(stage) - this.toggleState() - } + stage.operation.dirty = true + this._redoStack = [] + this._undoStack.push(stage) + this.toggleState() } copyOperation(stage, redo) {