APP-44Required
Let people undo or confirm destructive actions
For deletes and other changes that lose data, offer undo when the change can be reversed, and ask for confirmation when it can't. Name the object and the count in both.
How to do it
Prefer undo. Mark the record deleted at once, show "Invoice 1042 deleted" with an Undo button, and purge it after a set time, such as 30 days. For actions that can't be reversed, confirm in a dialog. Its button names the action, such as "Delete 3 projects", never "OK". For large or account-wide deletes, ask people to type the name. This meets error prevention.
Examples
TypeScript example
export async function deleteInvoice(invoice: Invoice) {
await api.post(`/api/invoices/${invoice.id}/delete`);
showUndo(`Invoice ${invoice.number} deleted`, () => api.post(`/api/invoices/${invoice.id}/restore`));
}
Python example
PURGE_AFTER = timedelta(days=30)
@app.post("/api/invoices/<invoice_id>/delete")
def delete_invoice(invoice_id):
invoices.mark_deleted(current_user().account_id, invoice_id, purge_at=datetime.now(timezone.utc) + PURGE_AFTER)
return "", 204
@app.post("/api/invoices/<invoice_id>/restore")
def restore_invoice(invoice_id):
invoices.restore(current_user().account_id, invoice_id)
return "", 204
How to check
A browser test deletes a record and presses Undo, and the record is back with the same ID. A test of each action that can't be reversed finds a confirmation whose button names the action.
Sources
Related rules
- AIF-5 Design for wrong answers in AI features
- APP-30 Undo optimistic updates that fail in Web app interface
- APP-39 Say what select all selects in Web app interface
- AXS-29 Let people check before they commit in Accessibility
- APP-80 Show which environment a tool is connected to in Web app interface
- APP-73 Undo only your own changes in a shared document in Web app interface
- APP-84 Gather every setting on one settings page in Web app interface
- MED-4 Keep deleted files restorable for 30 days in Files and media
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/app-ui/feedback-and-dialogs/confirm-or-undo">Agent Wranglers web app interface playbook</a>. In code you write, add a comment next to it with the same link.