Skip to content

fix: prevent selecting duplicate files in the same modal session - #2748

Open
andrewleith wants to merge 7 commits into
mainfrom
fix/attach-stop-dupes
Open

fix: prevent selecting duplicate files in the same modal session#2748
andrewleith wants to merge 7 commits into
mainfrom
fix/attach-stop-dupes

Conversation

@andrewleith

@andrewleith andrewleith commented Jul 28, 2026

Copy link
Copy Markdown
Member

Summary | Résumé

This pull request improves the file attachment modal by preventing users from selecting the same file more than once in a single session. It also adds a test to verify that duplicate files are detected and reported as issues.

Test instructions | Instructions pour tester la modification

Prevents duplicates between reloads

  • Go to an email template, click attach more files
  • Click choose files, select a file and attach it
  • Reload the page
  • Attach the same file
  • An error message is triggered and the file is not attached

Prevents duplicates done one at a time

  • Go to an email template, click attach more files
  • Click choose files, select a file and attach it
  • Click attach more files again
  • Select the same file and attach it again
  • An error message is triggered and the file is not attached

Prevents duplicates done at the same time

  • Go to an email template, click attach more files
  • Click choose files, select a file and attach it
  • Click choose files, select the same file and attach it again
  • An error message is triggered and the file is not attached

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR enhances the attachments UI by blocking users from selecting the same file more than once during a single “Attach files” modal session, and adds a regression test to ensure duplicates are detected and reported.

Changes:

  • Add in-modal duplicate detection (against already-selected pending files) and filter duplicates out of the accepted selection.
  • Deduplicate reported validation issues before surfacing them to the parent via onIssuesChange.
  • Add a Jest test covering duplicate selection within the same modal session.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
app/assets/javascripts/attachments/AttachFilesModal.js Filters newly selected files to prevent duplicates against the modal’s existing pending selection and reports a duplicate issue.
tests/javascripts/attachments/AttachFilesModal.test.js Adds a test verifying duplicate selection triggers an issue and does not add a second pending item.
Comments suppressed due to low confidence (1)

app/assets/javascripts/attachments/AttachFilesModal.js:177

  • After handling a file selection, the file input should be cleared (set to an empty string) so choosing the same file again reliably fires a change event across browsers. Without this, the duplicate-selection validation may not run if the user re-selects the same file.
    const normalizedFiles = filteredAcceptedFiles.map((file) => ({
      id: `${file.name}-${file.size}-${file.lastModified || 0}-${Math.random()}`,
      file,
    }));
    setSelectedFiles((currentFiles) => [...currentFiles, ...normalizedFiles]);
  };

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

Comment thread app/assets/javascripts/attachments/AttachFilesModal.js
@github-actions

Copy link
Copy Markdown

@andrewleith
andrewleith marked this pull request as ready for review July 28, 2026 13:03
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.

3 participants