Fix: Delete empty cards when dialog is closed without changes#5111
Fix: Delete empty cards when dialog is closed without changes#5111sirrodgepodge wants to merge 1 commit into
Conversation
When a user clicks '+ New' to create a card and immediately closes the dialog without making any changes, the empty card is now automatically deleted. This prevents accidental creation of empty cards. The check verifies the card has no title, no content blocks, no comments, and no attachments before deleting. Template cards are excluded from this cleanup. Fixes mattermost-community#4843
|
Hello @sirrodgepodge, Thanks for your pull request! A Core Committer will review your pull request soon. For code contributions, you can learn more about the review process here. Per the Mattermost Contribution Guide, we need to add you to the list of approved contributors for the Mattermost project. Please help complete the Mattermost contribution license agreement? This is a standard procedure for many open source projects. Please let us know if you have any questions. We are very happy to have you join our growing community! If you're not yet a member, please consider joining our Contributors community channel to meet other contributors and discuss new opportunities with the core team. |
There was a problem hiding this comment.
Pull request overview
Fixes the “empty card created when closing immediately” behavior by adding cleanup logic to delete an unchanged/empty card when the card dialog is closed.
Changes:
- Added an
handleClosecallback inCardDialogto detect an “empty” card (no title/content/comments/attachments) and delete it on close (excluding templates). - Wired the dialog’s
onClosehandler to use the new cleanup-aware close callback.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| await mutator.deleteBlock(card, 'delete empty card') | ||
| } | ||
| props.onClose() | ||
| }, [card, comments, attachments, props.onClose]) |
There was a problem hiding this comment.
handleClose awaits mutator.deleteBlock before calling props.onClose(). Since Dialog calls onClose synchronously (esc / backdrop / close button), this can make the UI feel “stuck” while the DELETE request is in flight, and if the promise rejects the dialog may never close. Consider ensuring the dialog closes regardless (e.g., try/finally around the delete + props.onClose(), and/or triggering the delete without blocking close while handling failures separately).
| if (card && | ||
| !card.fields.isTemplate && | ||
| card.title === '' && | ||
| card.fields.contentOrder.length === 0 && | ||
| comments.length === 0 && | ||
| attachments.length === 0 | ||
| ) { |
There was a problem hiding this comment.
Auto-deleting an empty card on close currently ignores props.readonly. In read-only mode, this can attempt an unauthorized delete and (because it’s awaited) can block closing the dialog. Consider adding a guard (e.g., skip the cleanup when readonly is true) so the close behavior is consistent with the rest of the dialog’s read-only gating.
Summary
Fixes #4843 — Empty cards are created when no changes are made.
Problem
When a user clicks the + New button to create a card and immediately closes the modal without making any changes, an empty card is left behind.
Solution
Added cleanup logic in
CardDialogthat automatically deletes the card when the dialog is closed if the card is still empty (no title, no content blocks, no comments, and no attachments). Template cards are excluded.Changes
webapp/src/components/cardDialog.tsx: AddedhandleClosecallback that checks if the card is empty before closing, and deletes it if so.Testing