Skip to content

fix: add inventory item image preview#819

Merged
smarcet merged 1 commit into
masterfrom
fix/add-inventory-item-image-preview
Mar 23, 2026
Merged

fix: add inventory item image preview#819
smarcet merged 1 commit into
masterfrom
fix/add-inventory-item-image-preview

Conversation

@priscila-moneo
Copy link
Copy Markdown

@priscila-moneo priscila-moneo commented Mar 10, 2026

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

image
  • Added image preview on hover for the Inventory items list by rendering the item image inside a popover (instead of only opening/downloading on click).
  • Kept the existing click behavior on the image icon to open the file in a new tab, so current workflow is preserved.

Summary by CodeRabbit

  • New Features

    • Inventory item images show a hover/focus preview tooltip (220×220); click opens the image in a new tab. No preview when no image.
  • Improvements

    • Added localized alt text and explicit accessibility labels for image previews.
    • Preview component shows fallback text when an image fails to load.
  • Tests

    • Added tests for preview open/close, accessibility labels, click behavior, and image-error fallback.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 10, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Added three i18n keys and a reusable exported InventoryImagePreviewCell component (uses MUI Popover for a 220×220 preview with load-failure fallback and click-to-open). Replaced inline image rendering in the inventory list, updated useEffect deps, and added tests for preview behavior and accessibility.

Changes

Cohort / File(s) Summary
Localization
src/i18n/en.json
Added three keys under inventory_item_list: image_preview_alt ("Inventory item preview"), image_preview_action_alt ("Open image preview for {itemName} in a new tab"), and image_preview_unavailable ("Image preview unavailable").
Inventory List UI
src/pages/sponsors-global/inventory/inventory-list-page.js
Added exported InventoryImagePreviewCell component (MUI Popover, 220×220 preview, error fallback text, click opens image in new tab); added module constants for preview sizing/behavior; added displayName; updated imports (Popover, Typography); replaced inline image-icon renderer with the new component; updated useEffect dependency array.
Tests
src/pages/sponsors-global/inventory/__tests__/inventory-list-page.test.js
New tests for InventoryImagePreviewCell: hover/focus opens & leave/blur closes, no render when imageUrl missing, aria-label correctness (uses translation/placeholder), image onError shows fallback text, and click opens window with correct args.

Sequence Diagram(s)

sequenceDiagram
    participant User as User
    participant InventoryPage as InventoryPage
    participant Popover as Popover (Preview)
    participant Browser as Browser

    User->>InventoryPage: hover or focus preview button
    InventoryPage->>Popover: open with imageUrl, set size 220x220
    Popover->>User: render image or fallback text (onError)
    User->>InventoryPage: click preview/button
    InventoryPage->>Browser: window.open(imageUrl, "_blank", "noopener,noreferrer")
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • smarcet

Poem

🐰 A tiny peek, a gentle hop,
I nudge the icon, the image pops.
If pixels fail, a message shows,
Click and the window gently goes.
Carrots clap for tiny glows.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: add inventory item image preview' directly reflects the main change: introducing an image preview feature for inventory items, which aligns with all modifications across the three files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/add-inventory-item-image-preview
📝 Coding Plan
  • Generate coding plan for human review comments

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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/pages/sponsors-global/inventory/inventory-list-page.js`:
- Around line 171-213: The render function currently dereferences row.images
without guarding for null/undefined; update the render lambda (the render: (row)
=> ...) to first check that row.images is an array (e.g. row.images &&
row.images.length > 0) before accessing row.images[0] and
row.images[0].file_url, and use optional chaining where helpful
(row.images?.[0]?.file_url) for both the Tooltip src/alt and the IconButton
onClick so the UI won't throw when the relationship is missing.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5d96d6c6-8f89-4ba5-927b-78ce911f2f19

📥 Commits

Reviewing files that changed from the base of the PR and between b29d23f and 26a11d4.

📒 Files selected for processing (2)
  • src/i18n/en.json
  • src/pages/sponsors-global/inventory/inventory-list-page.js

Comment thread src/pages/sponsors-global/inventory/inventory-list-page.js Outdated
@priscila-moneo priscila-moneo force-pushed the fix/add-inventory-item-image-preview branch from 26a11d4 to dbe5ae4 Compare March 10, 2026 14:48
Copy link
Copy Markdown

@martinquiroga-exo martinquiroga-exo left a comment

Choose a reason for hiding this comment

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

@priscila-moneo please see comments.

if (!hasImages || !imageUrl) return null;

return (
<Tooltip
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

For this use case we should use Popover instead of Tooltip

overflow: "hidden"
}}
>
<Box
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This will cause the browser to eagerly load the images. We want preview images to be lazy loaded, conditionally mount them using Popover

>
<Box
component="img"
src={imageUrl}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

There is no fallback we could be rendering a broken preview if the image load fails for instance. Currently the code prevents rendering when the URL is missing but not if the link is broken or there is a network issue, etc.

@priscila-moneo priscila-moneo force-pushed the fix/add-inventory-item-image-preview branch from dbe5ae4 to e3a0014 Compare March 11, 2026 21:19
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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/pages/sponsors-global/inventory/inventory-list-page.js`:
- Around line 177-179: The useEffect is causing duplicate dispatches because
handlers (onPageChange/onSort/onSearch/onFilter) already call getInventoryItems
and the effect also re-dispatches when mapped props change; remove the duplicate
by changing the useEffect to run only once on mount (useEffect(..., [])) and
call getInventoryItems with the current mapped page prop instead of the
hard-coded 1 (use getInventoryItems(term, page, perPage, order, orderDir,
hideArchived)), or alternatively delete this useEffect entirely and keep the
handler-driven calls—ensure you update the effect (or remove it) so it no longer
depends on getInventoryItems, term, perPage, order, orderDir, hideArchived to
avoid double requests.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0e84f382-ab5a-49e1-a3bd-a2026cf7e17a

📥 Commits

Reviewing files that changed from the base of the PR and between dbe5ae4 and e3a0014.

📒 Files selected for processing (3)
  • src/i18n/en.json
  • src/pages/sponsors-global/inventory/__tests__/inventory-list-page.test.js
  • src/pages/sponsors-global/inventory/inventory-list-page.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/i18n/en.json

Comment thread src/pages/sponsors-global/inventory/inventory-list-page.js Outdated
@priscila-moneo priscila-moneo force-pushed the fix/add-inventory-item-image-preview branch from e3a0014 to 77bca5a Compare March 11, 2026 22:20
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: 1

♻️ Duplicate comments (1)
src/pages/sponsors-global/inventory/inventory-list-page.js (1)

177-185: ⚠️ Potential issue | 🟡 Minor

Preserve the stored page on mount.

Line 180 still hard-resets the first fetch to page 1. If this screen is remounted after paging through the list, the Redux-backed list state is discarded and users get bounced back to the first page.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/pages/sponsors-global/inventory/inventory-list-page.js` around lines 177
- 185, The useEffect currently forces the first fetch to DEFAULT_CURRENT_PAGE
which resets Redux-backed paging on remount; change the call to
getInventoryItems(...) to use the stored page value (e.g., currentPage /
inventory.currentPage from props or selector) instead of DEFAULT_CURRENT_PAGE,
falling back to DEFAULT_CURRENT_PAGE only if that stored page is undefined/null;
update the useEffect dependencies if needed so it reads the stored page value on
mount and does not always reset to 1.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/pages/sponsors-global/inventory/inventory-list-page.js`:
- Around line 57-79: The accessible label (previewAlt) used on the IconButton is
generic and doesn't communicate the click action that opens the asset in a new
tab; update the component to accept the item name (e.g., itemName prop) and
build an action-oriented aria-label (replace previewAlt on the IconButton) that
includes the item name and mentions the new-tab behavior (for example: "Open
image preview for {itemName} in a new tab"), while keeping the existing
hover/focus handlers (openPreview, closePreview) and the onClick
window.open(imageUrl, "_blank", "noopener,noreferrer") behavior unchanged.

---

Duplicate comments:
In `@src/pages/sponsors-global/inventory/inventory-list-page.js`:
- Around line 177-185: The useEffect currently forces the first fetch to
DEFAULT_CURRENT_PAGE which resets Redux-backed paging on remount; change the
call to getInventoryItems(...) to use the stored page value (e.g., currentPage /
inventory.currentPage from props or selector) instead of DEFAULT_CURRENT_PAGE,
falling back to DEFAULT_CURRENT_PAGE only if that stored page is undefined/null;
update the useEffect dependencies if needed so it reads the stored page value on
mount and does not always reset to 1.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 34b1fa9c-e171-46f6-9313-77fd4548810a

📥 Commits

Reviewing files that changed from the base of the PR and between e3a0014 and 77bca5a.

📒 Files selected for processing (3)
  • src/i18n/en.json
  • src/pages/sponsors-global/inventory/__tests__/inventory-list-page.test.js
  • src/pages/sponsors-global/inventory/inventory-list-page.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/pages/sponsors-global/inventory/tests/inventory-list-page.test.js

Comment thread src/pages/sponsors-global/inventory/inventory-list-page.js Outdated
@priscila-moneo priscila-moneo force-pushed the fix/add-inventory-item-image-preview branch from 77bca5a to fd56ed7 Compare March 12, 2026 19:07
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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/pages/sponsors-global/inventory/inventory-list-page.js`:
- Around line 59-63: The previewAlt variable and the IconButton label are
reusing the action-oriented translation key, causing the <img> to have an
imperative alt; instead, use two separate translation keys and values: keep
"inventory_item_list.image_preview_action_alt" (with itemName) for the
IconButton's aria-label/label and switch the <img>'s alt to a descriptive key
like "inventory_item_list.image_preview_alt" (also accept itemName if needed for
context); update the code references around previewAlt, the IconButton props,
and the <img> alt so the button announces the action and the image has a
descriptive alt.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 064c253d-ed5e-4d98-898e-a3a53fdb0a01

📥 Commits

Reviewing files that changed from the base of the PR and between 77bca5a and fd56ed7.

📒 Files selected for processing (3)
  • src/i18n/en.json
  • src/pages/sponsors-global/inventory/__tests__/inventory-list-page.test.js
  • src/pages/sponsors-global/inventory/inventory-list-page.js
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/pages/sponsors-global/inventory/tests/inventory-list-page.test.js
  • src/i18n/en.json

Comment thread src/pages/sponsors-global/inventory/inventory-list-page.js Outdated
@priscila-moneo priscila-moneo force-pushed the fix/add-inventory-item-image-preview branch from fd56ed7 to 2910cef Compare March 16, 2026 20:15
@priscila-moneo priscila-moneo force-pushed the fix/add-inventory-item-image-preview branch from 2910cef to b1112c3 Compare March 16, 2026 23:30
Copy link
Copy Markdown

@martinquiroga-exo martinquiroga-exo left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown

@smarcet smarcet left a comment

Choose a reason for hiding this comment

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

LGTM

@smarcet smarcet merged commit 230e1d8 into master Mar 23, 2026
9 checks passed
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