Skip to content

fix: attachment behavior allows and respects custom view definitions#7811

Merged
acwhite211 merged 6 commits intomainfrom
issue-5078
Mar 18, 2026
Merged

fix: attachment behavior allows and respects custom view definitions#7811
acwhite211 merged 6 commits intomainfrom
issue-5078

Conversation

@kwhuber
Copy link
Contributor

@kwhuber kwhuber commented Mar 13, 2026

Fixes #5078

Before this fix, when a user defined a custom view definition for an attachment form (CollectionObjectAttachment, for example), the "Edit Form Definition" link never appeared in the form meta tools button. This was because attachment views were resolved from a local hardcoded definition; the server was never queried, so no viewSetId was ever available.

This fix introduces changes that enable a user to define a custom view definition and have it honored when they are uploading an image to a Collection Object, for example.

Regarding image uploads, Specify defines the following view definitions (non-exhaustive):

  • ObjectAttachment view definition is assigned when viewing an attachment from Gift, Loan, Permit, Preparation, Locality, etc.
  • CollectionObjectAttachment view definition when viewing a Collection Object’s attachment
  • AttachmentForm view definition when viewing an Attachment form directly

The specific changes are outlined as follows:

  • useViewDefinition.tsx: When resolving an attachment view, now fetches both the specific table view (CollectionObjectAttachment) and the generic ObjectAttachment view in parallel. Whichever has a viewsetId wins, and that ID is surfaced as viewSetId on the returned ViewDescription so the "Edit Form Definition" link can appear
  • index.ts: Added isAttachmentPlugin?: true to the ViewDescription type. This is a flag set on all attachment views, used by SpecifyForm.tsx and FormTable.tsx to decide when to render the attachment plugin
  • SpecifyForm.tsx and FormTable.tsx: Replaced the viewDefinition.name === 'ObjectAttachment' condition with viewDefinition.isAttachmentPluginso any view with a different name (like CollectionObjectAttachment) is now accepted
  • Plugin.tsx: Fixed tableID being set incorrectly on upload. The code now removes the "Attachment" suffix from the resource's table name to find the parent table (locates CollectionObject from CollectionObjectAttachment, for example) and uses that table's ID instead to determine where the attachment should live

Checklist

  • Self-review the PR after opening it to make sure the changes look good and
    self-explanatory (or properly documented)
  • Add relevant issue to release milestone
  • Add pr to documentation list
  • Add automated tests
  • Add a reverse migration if a migration is present in the PR

Testing instructions

  • Define a custom Attachment view definition (Collection Object Attachment, for example)
  • Upload an attachment to a Collection Object
  • Confirm that custom view definition is respected in the UI
  • Click on the form’s meta tools button then click the "From Definition" button and see that there is a link to “Edit Form Definition”
  • Confirm that you are routed to the correct view definition
  • Go back to the image you uploaded on the CO form and save it
  • Confirm that custom view definition is still respected
  • Confirm that image is saved (via Attachments tab or QB)

@kwhuber kwhuber added this to the 7.12.1 milestone Mar 13, 2026
@kwhuber kwhuber requested a review from a team March 13, 2026 18:24
@github-project-automation github-project-automation bot moved this to 📋Back Log in General Tester Board Mar 13, 2026
Copy link
Contributor

@alesan99 alesan99 left a comment

Choose a reason for hiding this comment

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

  • Define a custom Attachment view definition (Collection Object Attachment, for example)
  • Upload an attachment to a Collection Object
  • Confirm that custom view definition is respected in the UI
  • Click on the form’s meta tools button then click the "From Definition" button and see that there is a link to “Edit Form Definition”
  • Confirm that you are routed to the correct view definition
  • Go back to the image you uploaded on the CO form and save it
  • Confirm that custom view definition is still respected
  • Confirm that image is saved (via Attachments tab or QB)

Edit form definition button appears correctly
Works for both Collection Object Attachments and Accession Attachments, nice job!

@alesan99 alesan99 requested review from a team March 16, 2026 20:12
Copy link
Collaborator

@bhumikaguptaa bhumikaguptaa left a comment

Choose a reason for hiding this comment

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

  • Define a custom Attachment view definition (Collection Object Attachment, for example)
  • Upload an attachment to a Collection Object
  • Confirm that custom view definition is respected in the UI
  • Click on the form’s meta tools button then click the "From Definition" button and see that there is a link to “Edit Form Definition”
  • Confirm that you are routed to the correct view definition
  • Go back to the image you uploaded on the CO form and save it
  • Confirm that custom view definition is still respected
  • Confirm that image is saved (via Attachments tab or QB)

--

Looks good! I am able to see the correct view definition and verify image being saved.

@acwhite211 acwhite211 merged commit 0906e1e into main Mar 18, 2026
14 checks passed
@acwhite211 acwhite211 deleted the issue-5078 branch March 18, 2026 17:58
@github-project-automation github-project-automation bot moved this from 📋Back Log to ✅Done in General Tester Board Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅Done

Development

Successfully merging this pull request may close these issues.

Custom Attachment view definition not being used when present

5 participants