Skip to content

Commit

Permalink
Add client-side rollback during snapshot import (#492)
Browse files Browse the repository at this point in the history
  • Loading branch information
sorenjohanson authored Oct 21, 2024
1 parent c127abb commit 9058c58
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions teammapper-frontend/mmp/src/map/handlers/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,16 @@ export default class History {

this.map.zoom.center('position', 0)

this.save()
if (notifyWithEvent) this.map.events.call(Event.create, this.map.dom, { previousMap: previousData })
// If the amount of nodes is == 0, automatically rollback to the last clean snapshot and display a toast
if (this.map.nodes.getNodes().length === 0) {
if (previousData.length > 0) {
this.redraw(previousData)
}
Log.error('There was an error importing the map; changes have been rolled back.')
} else {
this.save()
if (notifyWithEvent) this.map.events.call(Event.create, this.map.dom, { previousMap: previousData })
}
} else {
Log.error('The snapshot is not correct')
}
Expand Down Expand Up @@ -121,7 +129,7 @@ export default class History {
*/
private redraw(snapshot: MapSnapshot) {
this.map.nodes.clear()

snapshot.forEach((property: ExportNodeProperties) => {
// in case the data model changes this makes sure all properties are at least present using defaults
const mergedProperty = { ...DefaultNodeValues, ...property } as ExportNodeProperties
Expand Down

0 comments on commit 9058c58

Please sign in to comment.