Undo/Redo functionality

Hello, I am trying to create an Undo/Redo function with editable table cells. I have some ideas on how to achieve it, but there are some issues I don't know how to handle.

*Save the changes
I can save the changes from the changesetArray into a variable as an array, thus creating a 'history'.

*Undo/Redo Changes
I can assign a variable as the data source for my table and assign the last element of the history to that variable.

*Database
My issue is here, as saving every change to the database is not feasible due to, how to manage the history of that database and undoing them. If a record was added, I would have to delete it.
The most "optimal" solution would be to determine a save period or an event that saves these changes and clears the history, this way all changes will be stored as arrays, but there is a risk of losing changes made if, for some reason, that event does not execute (user disconnects, refreshing page, etc).

*Use case
My app is a Quotation Tool, and such quotations have several amount of data being edited, also i have implemented a copy/paste function between tables and i want users to be able to undo such actions. (Working with RetoolDB, cloud version)

Is there any recommended practice when dealing with these situations? Any suggestions are appreciated, if more information or context is needed, feel free to ask for it. Thank you.

Hi @Oscar_Ortega Thanks for the detailed post! This is a really interesting use case; it's not something I've seen implemented before. I do think the variable approach is likely the most supported way to set this up. There's definitely some limitations though, as you noted. Variables reset to default when you reload the page. You could potentially consider local storage which persists in the browser, even after reloading the page.

Would the user be clicking a button to save or would they expect each change to auto save


Hello, i was thinking of using both button and auto save
Auto save for the changes history and the button to save to the data base
And for the local storage i could try to make a "backup" every X seconds

My concern with the auto save feature is that cannot keep consistency.
I would need to clear the changesetArray or keeping it for every change made, and it looks weird visually because i cannot edit the changesetArray to simulate that an undo was performed and user is able to save that state.

But this is for a feature request :grin:

Thanks!

1 Like

Was this figured out?
I want to implement exactly the same functionality for my project but the DB changes are causing a big problem here.
I would appreciate a solution if this was figured out on your end.
Thanks!