Skip to content

fix: add image preview and download link for upload input v3#257

Open
tomrndom wants to merge 3 commits into
mainfrom
fix/upload-input-v3-preview-download
Open

fix: add image preview and download link for upload input v3#257
tomrndom wants to merge 3 commits into
mainfrom
fix/upload-input-v3-preview-download

Conversation

@tomrndom
Copy link
Copy Markdown
Contributor

@tomrndom tomrndom commented May 27, 2026

ref: https://app.clickup.com/t/86b9axe92

image

Signed-off-by: Tomás Castillo tcastilloboireau@gmail.com

Summary by CodeRabbit

  • Bug Fixes

    • Improved file preview robustness with fallback icon support when thumbnails fail to load.
  • New Features

    • Uploaded files now display as clickable thumbnails with direct download links, replacing generic upload icons for better user experience.

Review Change Stack

Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 27, 2026

Warning

Review limit reached

@tomrndom, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 35 minutes and 27 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8c009c22-1c6f-4fd0-adae-d783e2ec991b

📥 Commits

Reviewing files that changed from the base of the PR and between 4804426 and 43d5e68.

📒 Files selected for processing (2)
  • package.json
  • src/components/inputs/upload-input-v3/__tests__/upload-input-v3.test.js
📝 Walkthrough

Walkthrough

The component enhances the uploaded file display by rendering clickable thumbnail images instead of generic icons. It imports a fallback icon for load failures, derives proper URLs from file metadata, rewrites query parameters for correct rendering, and converts filenames to download links.

Changes

Uploaded file thumbnail and download rendering

Layer / File(s) Summary
Thumbnail and download link rendering
src/components/inputs/upload-input-v3/index.js
Imports a fallback file_icon asset and updates the uploaded file row renderer to display clickable thumbnail <img> elements sourced from private_url/public_url, with query rewriting from ?dl=0 to ?raw=1 and special handling for placeholder URLs (src === '#'), plus converts filenames to linked download targets with updated styling.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • OpenStackweb/openstack-uicore-foundation#200: Both PRs center on the UploadInputV3 component, with the related PR introducing the component and this PR enhancing its uploaded-file row rendering with thumbnails and download links.

Suggested reviewers

  • smarcet
  • santipalenque

Poem

🐰 A thumbnail springs to life,
No longer just a generic square,
Download links and fallback sprites,
The upload form shows extra care!
Files now preview with delight! 🖼️

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding image preview and download link functionality to the upload input v3 component, which matches the file modifications and PR objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/upload-input-v3-preview-download

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 and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/components/inputs/upload-input-v3/index.js`:
- Around line 386-387: The preview/download anchors currently render with
href={src} even when src is empty, producing broken links; update the render
logic in the UploadInputV3 component (the JSX that outputs the <a href={src}
...> preview and download anchors) to conditionally render those <a> elements
only when src is truthy, and otherwise render a non-interactive fallback (e.g.,
a <span> or icon button with no href and appropriate aria-disabled) so the UI
isn’t clickable when no URL exists; apply this gate to both the preview anchor
and the download anchor render paths that reference the src variable.
- Around line 390-391: The onError handler for the image fallback currently sets
e.target.src = file_icon but leaves the same handler in place, risking an
infinite loop if the fallback also fails; update the onError callback used on
the image element (the onError prop in this component) to first remove or
nullify the handler (e.g., e.target.onerror = null or e.currentTarget.onerror =
null) and then set the fallback src, and optionally guard by checking if
e.target.src is already the fallback before assigning to avoid reassigning the
same value.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 95d83902-9a42-48cc-8c43-de00acf18754

📥 Commits

Reviewing files that changed from the base of the PR and between 051c04b and 4804426.

📒 Files selected for processing (1)
  • src/components/inputs/upload-input-v3/index.js

Comment on lines +386 to +387
<a href={src} target="_blank" rel="noreferrer" title="Preview file">
<img
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Avoid rendering preview/download anchors when URL is missing.

Line 386 and Line 399 can render <a> with an empty/undefined href, which creates broken interactive UI (click does nothing). Gate anchors on src and render plain text/icon when absent.

Proposed fix
-<a href={src} target="_blank" rel="noreferrer" title="Preview file">
-  <img
-    src={previewSrc}
-    alt={filename}
-    onError={(e) => { e.target.src = file_icon; }}
-    style={{ width: 70, height: 70, objectFit: 'contain', display: 'block', borderRadius: 4 }}
-  />
-</a>
+{src ? (
+  <a href={src} target="_blank" rel="noreferrer" title="Preview file">
+    <img
+      src={previewSrc}
+      alt={filename}
+      onError={(e) => { e.currentTarget.onerror = null; e.currentTarget.src = file_icon; }}
+      style={{ width: 70, height: 70, objectFit: 'contain', display: 'block', borderRadius: 4 }}
+    />
+  </a>
+) : (
+  <img
+    src={file_icon}
+    alt={filename}
+    style={{ width: 70, height: 70, objectFit: 'contain', display: 'block', borderRadius: 4 }}
+  />
+)}
@@
-<Typography
-  component="a"
-  href={src}
-  target="_blank"
-  rel="noreferrer"
-  download
+<Typography
+  component={src ? "a" : "span"}
+  href={src || undefined}
+  target={src ? "_blank" : undefined}
+  rel={src ? "noreferrer" : undefined}
+  download={Boolean(src)}

Also applies to: 398-403

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/components/inputs/upload-input-v3/index.js` around lines 386 - 387, The
preview/download anchors currently render with href={src} even when src is
empty, producing broken links; update the render logic in the UploadInputV3
component (the JSX that outputs the <a href={src} ...> preview and download
anchors) to conditionally render those <a> elements only when src is truthy, and
otherwise render a non-interactive fallback (e.g., a <span> or icon button with
no href and appropriate aria-disabled) so the UI isn’t clickable when no URL
exists; apply this gate to both the preview anchor and the download anchor
render paths that reference the src variable.

Comment on lines +390 to +391
onError={(e) => { e.target.src = file_icon; }}
style={{ width: 70, height: 70, objectFit: 'contain', display: 'block', borderRadius: 4 }}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Harden image fallback handler against recursive error loops.

Line 390 sets a fallback src but keeps the same onError. If the fallback asset fails (bad path/CSP), this can repeatedly fire.

Proposed fix
-onError={(e) => { e.target.src = file_icon; }}
+onError={(e) => {
+  e.currentTarget.onerror = null;
+  e.currentTarget.src = file_icon;
+}}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/components/inputs/upload-input-v3/index.js` around lines 390 - 391, The
onError handler for the image fallback currently sets e.target.src = file_icon
but leaves the same handler in place, risking an infinite loop if the fallback
also fails; update the onError callback used on the image element (the onError
prop in this component) to first remove or nullify the handler (e.g.,
e.target.onerror = null or e.currentTarget.onerror = null) and then set the
fallback src, and optionally guard by checking if e.target.src is already the
fallback before assigning to avoid reassigning the same value.

tomrndom added 2 commits May 26, 2026 23:19
Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
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.

1 participant