Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Ways to handle 'undo' delete actions

Options
  • 02-04-2015 10:09am
    #1
    Registered Users Posts: 47


    Hi all,

    I'm building a new feature into our web application and would like to add an 'undo' feature to some actions on the page.

    Currently I'm working on a 'notes' section where you can add notes with attachments to a product.

    Users can only edit/delete their own notes and users see all notes from every user.

    When a user clicks 'delete' the note fades away from the list in the UI.

    I then show an action bar at the top of the page where it shows 'The note has been deleted. Undo?'

    I'm looking for the best ways to handle that 'Undo' action.

    The application is built with AngularJS and .Net WebApi 2.

    - I was thinking of using AngularJS to store a copy of the deleted note and just add it again when 'undo' is clicked. However having file attachments complicates that since the attachments will be deleted on the initial action.

    - Maybe flag the note as 'deleted' in the database and add the delete action to a background 'queue' which delays deleting the note for a few minutes.
    If in the mean time the user clicks undo, then I just revert the 'delete' flag in the database and then the queued job will see that the note is no longer marked as 'deleted' and just leave it alone.

    Any other suggestions on how to achieve this sort of action?

    Thanks


Comments

  • Registered Users Posts: 586 ✭✭✭Aswerty


    Another option is to have a separate page where users can view, purge, or undo deleted comments. In this way any delete action in the database is completely user driven and you don't have to deal with client side caching or chron jobs. This page would be accessible via a settings/account menu. When a comment is deleted you could still give them the undo prompt and also a link to the deleted comments page.

    Alternatively you might not need an undo action. If the problem is you don't want people accidentally deleting comments then you could have something like the following:

    "User clicks delete, dialog window appears with warning that they are performing an unrecoverable action, dialog window asks user for their password so it can authenticate before deleting the comment, the user then enters the password and clicks a submit button."

    Though if I was to use one of the options you presented it would be the latter one. But I wouldn't be mad about it because you'd have to manage a new process in your system.


  • Registered Users Posts: 6,037 ✭✭✭Talisman


    Add a boolean field indicating that the note has been "deleted".

    You could also add an additional timestamp e.g. "deleted_at". This data could be persisted to the database and allow users to undo changes between sessions.

    The timestamp would allow you to perform hard deletes from the database on a schedule basis, e.g. deleted notes are automatically removed after 30 days:
    [PHP]DELETE FROM Notes WHERE deleted = 1 AND deleted_at < DATEADD(day, -30, GETDATE())[/PHP]

    You're free to determine the grace period for the hard delete, giving people more than a few minutes to undo their changes will give a better user experience.


  • Registered Users Posts: 47 NoelOC


    Thanks for the suggestions guys.

    I thinking I'm going to press ahead with a boolean deleted flag on a note.
    Then use a scheduled background task to delete the flagged items after maybe 7 days or some time period like that.
    The task could run every few hours and clean up any flagged items that have passed the grace period.

    @Talisman - thanks for the timestamp tip. I'll add that also.

    I just really like the user experience of having an 'undo' rather than prompted for confirmation each time.
    It gives a faster and smoother experience to users.

    However for major actions like deleting full products etc I do like the github method of typing the name of the repo to confirm the delete.
    These deletes would be infrequently used so I don't mind the occasional prompt for those.


  • Moderators, Technology & Internet Moderators Posts: 1,334 Mod ✭✭✭✭croo


    The most common example of what to do with Command pattern is to implement an undo function I'm sure if you google both you will find lots of examples.


Advertisement