Skip to content

feat(admin): admin libraries UX polish — full-table unmatched search, larger match-candidate posters with hover preview, paginated Ambiguous Roots - #20

Merged
Quick104 merged 6 commits into
Silo-Server:mainfrom
fluxis:mr/b-admin-ux
May 28, 2026
Merged

Quick104 merged 6 commits into
Silo-Server:mainfrom
fluxis:mr/b-admin-ux

Conversation

@fluxis

@fluxis fluxis commented May 28, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Three small but real admin-page UX issues:

  1. Match-candidate posters in the "Match Item" dialog rendered at 44×64 px — too small to identify a film at a glance.
  2. Unmatched-items search on the admin Libraries page filtered only the current page's rows client-side — the placeholder even said "Filter this page". With many unmatched items spread across pages, the search was effectively unusable.
  3. Ambiguous Roots table had no pagination — long lists scrolled forever.

Approach

  • Posters (web/src/components/MatchItemDialog.tsx): base size bumped to 64×96 (correct 2:3 aspect), and the poster is wrapped in a portaled Radix Tooltip that shows a 192×288 preview on hover. Uses the existing w300/w500 poster variants already produced by the image resolver — no backend change. Tooltip portals out of the dialog's overflow-y-auto scroll container so it isn't clipped. Click still selects the row (Tooltip's asChild on the <img> doesn't create a nested-button problem).
  • Unmatched search (internal/api/handlers/libraries.go, hooks, page): HandleListUnmatchedItems takes a new optional q param and filters title / type / status / library_name server-side with parameterised ILIKE (injection-safe; the LATERAL join carries lib.folder_name into both COUNT and LIST queries so predicate parity holds). The frontend hook gains a debounced search parameter; the page resets to page 1 in the input's onChange (no setState-in-useEffect cascade); the section stays mounted while a search is active so the "no matches" state stays visible. q is optional — existing callers are unaffected.
  • Ambiguous Roots pagination uses the existing usePagination helper and resets to page 0 on filter/library change.

Testing

cd web && pnpm exec tsc --noEmit               # PASS
cd web && pnpm exec prettier --check ...       # clean on changed files
cd web && pnpm exec eslint ...                 # clean on changed files
cd web && pnpm exec vitest run src/pages/AdminLibraries.test.tsx
#   5 passed, 1 skipped (the skipped one is a stale test mocking the wrong
#   hook for a refactored troubleshooting section — clearly TODO'd inline)

This MR also includes a test-infra fix (web/src/pages/AdminLibraries.test.tsx): the suite was failing all 6 tests with No QueryClient set on main (pre-existing pre-merge gate gap). With QueryClientProvider wired and five additional hooks mocked (useCancelLibraryScans, useLibraryRoots, useUpsertLibraryRootOverride, useDeleteLibraryRootOverride, useActiveScans) plus the UNMATCHED_PAGE_SIZE constant export, the suite actually runs. The one test that remains skipped is the deeper troubleshooting-section refactor (useSkippedLibraryRoots → useLibraryRoots(_, "ambiguous")); fixing it is a test rewrite, not a one-liner, and is intentionally out of scope.

The frontend build (pnpm run build) succeeded; the rebuilt image was deployed to a personal instance and the three flows visually verified.

Watch out

  • The unmatched-items endpoint's LATERAL ... LIMIT 1 subquery picks an arbitrary folder when an item belongs to multiple libraries (pre-existing behaviour, not introduced here) — the new q filter on lib.folder_name therefore matches only that arbitrary folder name. Pinning this to "any library the item is in" is a sensible follow-up.
  • Repository-wide pnpm run lint reports 115 warnings (0 errors) and pnpm run format:check flags 18 files needing prettier — all pre-existing, none introduced by this MR.

Compatibility

  • API: GET /libraries/unmatched-items adds optional q query param. Existing callers continue to work unchanged.
  • No schema migrations.

Note on process

I did not open an issue first; happy to retroactively if preferred.

AI disclosure

AI (Claude) meaningfully shaped this implementation across the three changes and the test-infra fix; every line was read locally before commit.

Summary by CodeRabbit

  • New Features

    • Server-side, case-insensitive search for unmatched items with debounced input (resets to page 0 on query change)
    • Preview tooltips showing enlarged images on hover for candidate thumbnails; compact thumbnail sizing
    • Pagination for Ambiguous Roots
  • Behavioral Fixes

    • Deterministic ordering and correct total counts when searching; "no matches" state preserved during active queries
  • Tests

    • Expanded test setup with React Query provider, updated mocks, and a render helper

Review Change Stack

fluxis and others added 2 commits May 28, 2026 16:59
Match the sibling tables on the Admin Libraries page (Troubleshooting/unmatched):
use the existing usePagination hook + PaginationBar (10/page, auto-hidden when
<=10 rows), render pag.rows, and reset to page 0 when the library selector or
search filter changes.
Unmatched-item match dialog rendered candidate posters at 44x64px, too small
to identify a film. Bump to 64x96 (2:3) and add a portaled Tooltip hover preview
(192x288) using the existing poster image, so operators can tell candidates apart.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented May 28, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 34613871-070a-4aa4-ab12-da6665f4f209

📥 Commits

Reviewing files that changed from the base of the PR and between e2a14f6 and b1c5ff3.

📒 Files selected for processing (1)
  • internal/api/handlers/libraries.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/api/handlers/libraries.go

📝 Walkthrough

Walkthrough

This PR adds server-side unmatched-item search (optional q), frontend debounced searching and query-key changes, ambiguous-roots pagination, candidate image preview tooltips, and test updates to exercise the new shapes and providers.

Changes

Library Items Search, Pagination, and Preview Features

Layer / File(s) Summary
Server-side search in handler
internal/api/handlers/libraries.go
Handler accepts optional q, builds ILIKE filter including an EXISTS over media-folder name joins, conditionally includes the filter in the count SQL, and enforces deterministic ORDER BY with adjusted LIMIT/OFFSET parameter indexing.
Query key update
web/src/hooks/queries/keys.ts
adminKeys.unmatchedItems now accepts search?: string and includes search ?? "" in the query key tuple.
Hook integration for unmatched items search
web/src/hooks/queries/admin/libraries.ts
useUnmatchedLibraryItems(page, search) trims search, uses it in the React Query key, and conditionally appends &q= to the backend request when non-empty.
Unmatched items search with debouncing and server results
web/src/pages/AdminLibraries.tsx
Uses useDebounce, passes debounced search to the hook, renders data?.items directly, resets pagination on search change, and keeps the section mounted for active queries that return zero results.
Ambiguous roots pagination and navigation
web/src/pages/AdminLibraries.tsx
Adds usePagination for filtered roots, resets page on library/search change, renders current page rows via pag.rows, and adds a PaginationBar.
Candidate item image preview tooltips
web/src/components/MatchItemDialog.tsx
Wraps candidate thumbnails in Tooltip components inside TooltipProvider to show larger hover previews; keeps non-image placeholders and adjusts thumbnail sizing.
Test infrastructure and mock updates
web/src/pages/AdminLibraries.test.tsx
Adds renderPage() wrapper with QueryClientProvider, expands mocked admin-library hooks and shapes (including UNMATCHED_PAGE_SIZE), changes useUnmatchedLibraryItems mock to return { data: { items, total } }, and updates assertions for ambiguous roots and unmatched items.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped through queries, gentle and spry,
Debounced the whispers that float and fly,
Pages for roots and previews that gleam,
Tooltips that shimmer like a bright dream,
A tiny rabbit cheering the searcher's stream!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes all three main changes: unmatched search, match-candidate poster improvements with hover preview, and paginated Ambiguous Roots. It is specific, concise, and clearly conveys the primary purpose of the PR as a UX polish update.
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

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
web/src/pages/AdminLibraries.test.tsx (1)

171-201: ⚡ Quick win

Replace the skipped section test with the new ambiguous-roots contract.

This test is now the main missing coverage for the refactored area. Updating it to assert against useLibraryRoots(_, "ambiguous") will keep regressions visible instead of silent.

I can draft the updated test case (new mock shape + assertions) if you want me to open it as a follow-up issue.

🤖 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 `@web/src/pages/AdminLibraries.test.tsx` around lines 171 - 201, Replace the
skipped test that mocks useSkippedLibraryRoots with a test that mocks
mocks.useLibraryRoots to return data for the "ambiguous" root type (call
useLibraryRoots(_, "ambiguous") in the component), updating the mock shape to
match LibraryRoot (e.g., include library_id, library_name, root_path,
ambiguity_reason or similar fields used by the UI) and set isLoading:false; then
call renderPage() and change assertions to look for the ambiguous-roots UI
strings (e.g., "Troubleshooting" plus the library_name, root_path, the ambiguity
reason label, and any "First seen" / "Last seen" fields the refactored component
renders) so the test exercises the new contract rather than the old
useSkippedLibraryRoots shape.
🤖 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 `@internal/api/handlers/libraries.go`:
- Around line 2073-2086: The count query always includes the LEFT JOIN LATERAL
(aliased lib) which is unnecessary when the search/filter (q) is empty; modify
the code that builds countSQL in the handler so it conditionally omits the LEFT
JOIN LATERAL and its subselect when there is no folder_name-related filter,
i.e., construct two variants of countSQL (one with the lib lateral join and one
without) and use the appropriate one before calling h.pool.QueryRow(...). Ensure
you reference the same filterArgs ordering/parameters when switching SQL so
Scan(&total) behavior for total stays identical.

---

Nitpick comments:
In `@web/src/pages/AdminLibraries.test.tsx`:
- Around line 171-201: Replace the skipped test that mocks
useSkippedLibraryRoots with a test that mocks mocks.useLibraryRoots to return
data for the "ambiguous" root type (call useLibraryRoots(_, "ambiguous") in the
component), updating the mock shape to match LibraryRoot (e.g., include
library_id, library_name, root_path, ambiguity_reason or similar fields used by
the UI) and set isLoading:false; then call renderPage() and change assertions to
look for the ambiguous-roots UI strings (e.g., "Troubleshooting" plus the
library_name, root_path, the ambiguity reason label, and any "First seen" /
"Last seen" fields the refactored component renders) so the test exercises the
new contract rather than the old useSkippedLibraryRoots shape.
🪄 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 Plus

Run ID: e5e0ae65-009f-43cf-bd17-935a077c6b57

📥 Commits

Reviewing files that changed from the base of the PR and between 985b296 and 925328d94484d25f5f7c648262d0b92a6bcba94f.

📒 Files selected for processing (6)
  • internal/api/handlers/libraries.go
  • web/src/components/MatchItemDialog.tsx
  • web/src/hooks/queries/admin/libraries.ts
  • web/src/hooks/queries/keys.ts
  • web/src/pages/AdminLibraries.test.tsx
  • web/src/pages/AdminLibraries.tsx

Comment thread internal/api/handlers/libraries.go Resolved
fluxis and others added 3 commits May 28, 2026 17:25
…he page

The unmatched-items search filtered only the current page's rows client-side.
Push the query server-side: HandleListUnmatchedItems takes an optional 'q' param
and filters title/library/type/status with parameterized ILIKE across all rows,
paginating the filtered set. Frontend hook takes a debounced search, resets to
page 1 on change, keeps the section mounted while searching. Also fixes stale
test mocks that returned the pre-pagination array shape instead of {items,total}.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…nChange

Run prettier over the Tooltip-wrapped poster JSX, and reset the unmatched-items
page in the search input's onChange rather than a useEffect (avoids the
react-hooks/set-state-in-effect warning / cascading renders).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…te runs

The AdminLibraries test file failed all 6 tests with 'No QueryClient set' on
this branch and at the parent commit -- pre-existing infrastructure gap. With
that fixed, several hooks that the page imports (useCancelLibraryScans,
useLibraryRoots, useUpsertLibraryRootOverride, useDeleteLibraryRootOverride,
useActiveScans) and the UNMATCHED_PAGE_SIZE constant also needed mocking. One
stale assertion on the renamed 'Root path' header is updated; the deeper
troubleshooting test, which mocked useSkippedLibraryRoots but the section was
refactored to useLibraryRoots(_, 'ambiguous'), is skipped with a TODO -- a real
rewrite is needed and is out of scope for this MR.

5 of 6 tests now run and pass; the 6th is properly flagged.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@fluxis

fluxis commented May 28, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 28, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented May 28, 2026

Copy link
Copy Markdown
Contributor

Actionable comments posted: 0

@coderabbitai

coderabbitai Bot commented May 28, 2026

Copy link
Copy Markdown
Contributor

Actionable comments posted: 0

@Quick104
Quick104 merged commit 2d9a0f7 into Silo-Server:main May 28, 2026
1 check passed
@fluxis
fluxis deleted the mr/b-admin-ux branch May 28, 2026 15:46
Quick104 added a commit to thezak48/silo-server that referenced this pull request Jun 7, 2026
feat(admin): admin libraries UX polish — full-table unmatched search, larger match-candidate posters with hover preview, paginated Ambiguous Roots
Quick104 added a commit that referenced this pull request Jun 11, 2026
feat(admin): admin libraries UX polish — full-table unmatched search, larger match-candidate posters with hover preview, paginated Ambiguous Roots
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.

2 participants