Skip to content

Open gallery attachment links in a new tab to avoid losing edits#1547

Draft
maebeale wants to merge 1 commit into
mainfrom
maebeale/gallery-image-new-window
Draft

Open gallery attachment links in a new tab to avoid losing edits#1547
maebeale wants to merge 1 commit into
mainfrom
maebeale/gallery-image-new-window

Conversation

@maebeale
Copy link
Copy Markdown
Collaborator

@maebeale maebeale commented Jun 5, 2026

Closes #1511

What is the goal of this PR and why is this important?

  • Stakeholder report: clicking an image/attachment in the gallery section of an edit form navigated away in the same tab, discarding any unsaved form edits.
  • Show-page galleries already open full-size images in a new tab (via DisplayImagePresenter), but the in-form attachment cards (shared/_form_image_field) were missed — their filename link opened in the same tab.
  • This makes the in-form behavior consistent and protects in-progress work.

How did you approach the change?

  • Added target: "_blank", rel: "noopener" to the persisted-file filename link in app/views/shared/_form_image_field.html.erb.
  • This partial is shared by every model's edit form (stories, resources, workshop variations, etc.), so the fix applies everywhere the gallery/attachment section appears.
  • TDD: added a view spec (spec/views/shared/_form_image_field.html.erb_spec.rb) that asserts the filename link opens in a new tab — confirmed it failed before the change and passes after.

UI Testing Checklist

  • Edit a story (or resource/workshop variation) that has an attached gallery image
  • Click the filename link under an existing attachment → it opens the file in a new tab
  • The original edit form remains open with unsaved changes intact

Anything else to add?

  • Scope kept minimal: the filename link was the only element in this section that actually navigated (the thumbnail image itself is not a link), so this is the precise source of the "lost work" behavior.

Clicking an attachment's filename in the image/gallery section of an
edit form navigated away in the same tab, discarding unsaved form edits.
Open these links in a new tab so in-progress work is preserved, matching
how the show-page galleries already behave.

Fixes #1511

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 5, 2026 00:41
class="text-center text-sm text-gray-500 break-all max-w-[8rem]">
<%= if blob.present? && blob.respond_to?(:persisted?) && blob.persisted?
link_to(blob.filename.to_s, url_for(file), class: "underline")
link_to(blob.filename.to_s, url_for(file), class: "underline", target: "_blank", rel: "noopener")
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This partial is rendered in every model's edit form via shared/_form_image_fields, so adding target: "_blank" here fixes the "navigates away and loses unsaved edits" report (#1511) across stories, resources, workshop variations, etc. in one place. Matches the new-tab behavior the show-page galleries already get from DisplayImagePresenter.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 updates the shared gallery/attachment form partial so clicking an existing attachment’s filename opens the file in a new browser tab, preventing users from losing unsaved edits on the form.

Changes:

  • Add target="_blank" and rel="noopener" to the persisted attachment filename link in shared/_form_image_field.
  • Add a view spec to assert the filename link renders with the expected new-tab attributes.

Reviewed changes

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

File Description
app/views/shared/_form_image_field.html.erb Updates the persisted attachment filename link to open in a new tab.
spec/views/shared/_form_image_field.html.erb_spec.rb Adds coverage to ensure the filename link includes new-tab attributes.

Comment on lines 82 to 84
<%= if blob.present? && blob.respond_to?(:persisted?) && blob.persisted?
link_to(blob.filename.to_s, url_for(file), class: "underline")
link_to(blob.filename.to_s, url_for(file), class: "underline", target: "_blank", rel: "noopener")
else
Comment on lines +11 to +13
it "links the attached file's name so it opens in a new tab" do
expect(rendered).to have_css("a[href][target='_blank'][rel='noopener']", text: asset.file.filename.to_s)
end
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.

Gallery: open image in new window to avoid losing in-progress work

2 participants