Skip to content

fix(ui): fall back to own file when hasMany thumbnail upload is empty - #19237

Open
digitalwerber wants to merge 1 commit into
payloadcms:mainfrom
digitalwerber:fix/thumbnail-empty-hasmany
Open

digitalwerber wants to merge 1 commit into
payloadcms:mainfrom
digitalwerber:fix/thumbnail-empty-hasmany

Conversation

@digitalwerber

Copy link
Copy Markdown

What?

getDocumentThumbnail falls back to the document itself when the thumbnail field is an empty hasMany upload.

Why?

An empty single upload field already fell back to the document, an empty hasMany field ([]) resolved to undefined. Upload collections with an attachments-style field therefore showed the placeholder icon in grid cards and dashboard widgets instead of their own file.

How?

Treat an empty array like an empty value. Adds unit cases for empty single, empty hasMany, filled hasMany and no field.

Fixes #19234

Without `admin.useAsThumbnail`, the thumbnail of a card resolves from the
first upload field and falls back to the document itself, so upload
collections show their own file. An empty `hasMany` upload field (`[]`)
resolved to `undefined` instead of falling back, so grid view cards and
the Recents and Pinned dashboard widget showed the placeholder icon
instead of the file. An empty single upload field already fell back
correctly.
@coderabbitai

coderabbitai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 39a9df9 and 5a1415c.

Files selected for processing: 2
  • packages/ui/src/utilities/getDocumentThumbnail.spec.ts
  • packages/ui/src/utilities/getDocumentThumbnail.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

Walkthrough

getDocumentThumbnail now falls back to the document when the configured thumbnail value is an empty array. Tests cover empty and missing upload fields, and confirm that a populated hasMany field takes precedence.

Changes: Document thumbnail fallback

Layer / File(s) Summary
Empty-field fallback behavior
packages/ui/src/utilities/getDocumentThumbnail.ts, packages/ui/src/utilities/getDocumentThumbnail.spec.ts
The utility checks that an array contains an item before selecting its first value. Tests verify fallback to the document thumbnail for empty or missing upload fields and precedence for a populated hasMany field.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: germanjablo

Merge Risk: Minimal · up to 5a141

The localized thumbnail fallback is supported by matching coverage for empty, missing, and populated upload fields.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: fallback to the document’s own file when a hasMany thumbnail upload is empty.
Description check Passed The description directly explains the affected function, the empty hasMany behavior, the user-facing impact, the implementation, and the added test coverage.
Linked Issues check Passed Issue #19234 requires getDocumentThumbnail to use the upload document when the configured hasMany field is empty. The change treats [] as empty and selects doc as the fallback. The tests cover…
Out of Scope Changes check Passed The pull request changes only getDocumentThumbnail and its unit tests. Both changes directly support issue #19234 and do not add unrelated behavior.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Full details: Linked Issues check

Explanation

Issue #19234 requires getDocumentThumbnail to use the upload document when the configured hasMany field is empty. The change treats [] as empty and selects doc as the fallback. The tests cover empty hasMany, empty single upload, absent field, and populated hasMany precedence.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 2 files.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

This branch has not been deployed

No deployments
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.

useAsThumbnail: empty hasMany upload field hides the upload collection's own file in cards

1 participant