Skip to content

Fix: Delete empty cards when dialog is closed without changes#5111

Open
sirrodgepodge wants to merge 1 commit into
mattermost-community:mainfrom
sirrodgepodge:fix/empty-card-cleanup
Open

Fix: Delete empty cards when dialog is closed without changes#5111
sirrodgepodge wants to merge 1 commit into
mattermost-community:mainfrom
sirrodgepodge:fix/empty-card-cleanup

Conversation

@sirrodgepodge

Copy link
Copy Markdown

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 CardDialog that 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: Added handleClose callback that checks if the card is empty before closing, and deletes it if so.

Testing

  1. Click + New to create a card → immediately close → ✅ empty card removed
  2. Click + New → add title/content → close → ✅ card preserved

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
Copilot AI review requested due to automatic review settings March 1, 2026 07:43
@mattermost-build

Copy link
Copy Markdown
Contributor

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?
Once you have signed the CLA, please comment with /check-cla and confirm that the CLA check is green.

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 handleClose callback in CardDialog to detect an “empty” card (no title/content/comments/attachments) and delete it on close (excluding templates).
  • Wired the dialog’s onClose handler to use the new cleanup-aware close callback.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +72 to +75
await mutator.deleteBlock(card, 'delete empty card')
}
props.onClose()
}, [card, comments, attachments, props.onClose])

Copilot AI Mar 1, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
Comment on lines +65 to +71
if (card &&
!card.fields.isTemplate &&
card.title === '' &&
card.fields.contentOrder.length === 0 &&
comments.length === 0 &&
attachments.length === 0
) {

Copilot AI Mar 1, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Empty cards are created when no changes are made

3 participants