Extend collections to include a soft delete feature for restoring deleting documents #4420
Replies: 3 comments 5 replies
-
Just wanted to implement a custom "soft delete" feature by overriding the delete endpoints. Unfortunately the frontend will only show custom notifications on errors. I would like to show something like "Image was moved to trash" instead of "Image was deleted successfully". So a start for custom solutions would be to change the response handler in the |
Beta Was this translation helpful? Give feedback.
-
@DanRibbens if I have a custom query param, which should filter for "trashed" items. But it will be removed somewhere in the list component where the fetch request will be triggered. So, if I use something like this: Adding a virtual field with type Adding a "normal" checkbox field, which is in sync with the deleteAt field could work. But I don't like it. Is it possible to search for date fields with null values? |
Beta Was this translation helpful? Give feedback.
-
I discarded my first idea and tried another approach.
|
Beta Was this translation helpful? Give feedback.
-
In other frameworks or ORMs there is usually a concept for enabling soft deleting an entity where a request to delete does not remove it from the database, but only marks it as deleted. This is useful for implementing trash can like functionality where documents can easily be restored or read later.
Typically this is done by adding a
deletedAt
timestamp to the document that can be nullable or undefined for non-deleted documents.This would fall under the opt-in config pattern so that each collection could have a flag for retaining documents.
The default behavior when fetching (find, findByID and bulk update/delete) would not return documents that have
deletedAt
set unless a flag is specifically sent to include deleted, similar to howdrafts: true
currently works.New endpoints could be added to restore documents, or we could simply rely on
PATCH
to set thedeletedAt
back to null.This could be done at the database and API layer only and then in another feature we can add features to the UI to make it easier to view deleted documents and restore them.
#1968
Beta Was this translation helpful? Give feedback.
All reactions