Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add client-side rollback during snapshot import #492

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions teammapper-frontend/mmp/src/map/handlers/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,14 @@ 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) {
this.undo()
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 @@ -120,8 +125,11 @@ export default class History {
* Redraw the map with a new snapshot.
* @param {MapSnapshot} snapshot
*/
private redraw(snapshot: MapSnapshot) {
this.map.nodes.clear()
private redraw(snapshot: MapSnapshot, backup: boolean = false) {
// Save the snapshot before clearing the map for easy rollback
if (backup) {
this.save()
}

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