Skip to content

refactor(web): add the collection scope adapter and one set of type labels - #1914

Merged
Quick104 merged 4 commits into
feat/collections-revampfrom
refactor/collection-scope-adapter
Oct 4, 2026
Merged

Quick104 merged 4 commits into
feat/collections-revampfrom
refactor/collection-scope-adapter

Conversation

@Quick104

@Quick104 Quick104 commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: #192
Validation tasks: changes #195 W1, #194 A3

Server collections and personal collections are read, saved and refreshed through two separate sets of web helpers. Each editor branches on "admin or personal", and the eight requests that read a collection with its ETag are each written by hand. The collections redesign replaces these editors with one editor page for both, and that page needs one interface to call. This PR adds that interface and moves today's editors and hooks onto it. Nothing should look different to users: every collection golden from #1912 passes without edits.

Stacked on #1912 (test(web): pin what the collection pages and editors save today).

Approach

  • web/src/api/v2/etag.ts adds withETag, which returns a v2 response body with its ETag and throws when the ETag is missing, and takes over requiredETag. The eight hand-written ETag reads in api/adminCollections.ts and api/personalCollections.ts now use it.
  • web/src/lib/collections/scope.ts defines SERVER_SCOPE and PERSONAL_SCOPE. Each holds the query keys, page paths, conversion to a shared view and draft, isReadOnly, the read, create, update, delete, sync and preview calls, invalidation and error messages. Keys and invalidation are exactly today's; making library Collections tabs refresh after a personal change is the next PR in the stack. create and update cover Manual and Smart collections and send the bodies today's forms send. Synced lists, staged items and artwork removal arrive with the PRs that first use them.
  • useScopeEditor (hooks/queries/collectionScope.ts) replaces the two editors' copies of the snapshot logic. It keeps the first snapshot for an id, so a background refetch never replaces what someone is editing, takes artwork from the list, and lets a 404 replace the kept copy. The admin editor still waits for the admin list, because the admin read carries no artwork. The personal editor still opens as soon as its own read returns.
  • lib/collectionTypes.ts moves to lib/collections/types.ts and gains the Manual / Smart / Synced list kinds, the synced source labels, and helpers that map a stored collection_type to them.
  • ManualCollectionItemsEditor takes a scope instead of a source string.
  • isCollectionReadOnly is replaced by PERSONAL_SCOPE.isReadOnly, built on isOwnCollection. It fails closed: while the acting profile is unknown, a personal collection counts as read-only. The old helper failed open.

scope.create, scope.update, paths.browse and the new type labels have no caller in the app yet. Tests cover them, and the one-editor PR is their first user.

No API change. jellycompat reads stored collection items and needs no change. No manual or client follow-up.

Validation

  • Web: lint (no errors; the changed files have fewer warnings than before), format:check, build, budget:check, tsc -b and make test-web pass.
  • The test(web): pin what the collection pages and editors save today #1912 goldens pass unchanged.
  • New tests cover withETag, the type labels, both scopes (keys, paths, view and draft conversion over the contract fixtures, isReadOnly, create and update bodies against the goldens, 412 handling, delete, sync, preview and invalidation) and useScopeEditor.
  • Go: the only change is a comment in internal/catalog that names the moved file. Build, gofmt, vet, make lint-changed and the package tests pass.
  • make verify-local-paths passes. No contract or migration files changed, so the contract checks were not run. make verify-case-collisions does not exist on this base and was not run.

Risks

  • Because PERSONAL_SCOPE.isReadOnly fails closed, a profile's own collection would show as read-only until the acting profile loads. The app restores the profile when it starts and the collection routes require one, so this should not show in practice.
  • The personal editor now hides a collection whose background read returns 404, as the admin editor already did; before, it kept showing the copy it had opened. This is intentional: after a profile switch or lost access the editor no longer offers edits that would fail. Collections — Web #195 W1 should be walked after merge.
  • The admin editor now reads list artwork with the app's default 2-minute stale time instead of the admin list's 30 seconds. A poster another admin changed in the last 2 minutes can show its old image when the editor reopens from cache.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.

AI Disclosure

  • Harness: Claude Code (in T3 Code)
  • Tool(s): Claude Code subagents (implementer, independent reviewer)
  • Model(s): claude-opus-5-5[1m]
  • Involvement: Fully AI-generated, human review pending
  • Adversarial review: An independent reviewer subagent checked the diff against the redesign plan, ran the type check, lint and the collection tests, and confirmed the preview, sync and delete requests are byte-identical to before. In a throwaway copy it made personal isReadOnly fail open, let withETag accept a missing ETag, and made useScopeEditor ignore list artwork; each change failed tests. It found one minor problem: the personal editor had started waiting for the collections list as well as its own read, so a slow list kept it on the loading screen. The fix lets each scope say whether its editor waits for the list, with a test per scope that fails if its setting flips.

🤖 Generated with Claude Code

Note

Add collection scope adapter and shared collection type labels for web

  • Introduces SERVER_SCOPE and PERSONAL_SCOPE descriptors in scope.ts behind one typed CollectionScope interface, covering paths, cache keys, view/draft conversion, mutations, sync, preview, invalidation, and error formatting for both server (admin) and personal collections.
  • Adds the shared collection kind, synced-source, and label model in types.ts; unknown stored types now map to the synced kind, and the old web/src/lib/collectionTypes.ts helper file is removed.
  • Adds useScopeEditor in collectionScope.ts: it freezes the first snapshot per collection id during background refetches, merges artwork from the collection list, and clears the snapshot on a 404 detail response.
  • Adds withETag and moves requiredETag into etag.ts; personal and admin snapshot fetchers now use it to return body plus validated ETag.
  • Refactors editors, mutations, and pages (AdminCollectionEditor, CollectionEditor, ManualCollectionItemsEditor, collections hooks) to route through the scopes, deleting the standalone route builders and read-only helpers they replaced.
  • Behavioral Change: ManualCollectionItemsEditor now takes a required CollectionScope prop instead of a source string; personal editors wait for list artwork per scope config and server editor snapshots stay gated until the list supplies artwork.

Macroscope summarized 90e42e3.

Quick104 and others added 2 commits October 4, 2026 09:36
…abels

Server and personal collections were read, saved and refreshed through two
parallel sets of helpers, so every editor branched on "admin or personal"
and the ETag reads were copied by hand eight times. The upcoming single
collection editor needs one surface for both.

- api/v2/etag.ts: withETag and requiredETag; the hand-written ETag
  fetchers in adminCollections.ts and personalCollections.ts use them.
- lib/collections/scope.ts: SERVER_SCOPE and PERSONAL_SCOPE with today's
  query keys, page paths, toView/toDraft, isReadOnly, and the network
  calls. create/update send the bodies the current forms send (pinned
  against the editor goldens). The delete, sync, preview and invalidation
  hooks now call the scope.
- hooks/queries/collectionScope.ts: useScopeEditor keeps the first
  snapshot for an id, takes artwork from the list, and lets a 404 win;
  both editor pages use it instead of their own copies.
- lib/collectionTypes.ts moves to lib/collections/types.ts and gains the
  Manual / Smart / Synced list kinds, source labels and helpers.
- ManualCollectionItemsEditor takes a scope instead of a source string.
- isCollectionReadOnly is replaced by PERSONAL_SCOPE.isReadOnly, which
  fails closed while the acting profile is unknown.

No visible change: the collection goldens pass unchanged.

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

The scope adapter made the personal editor wait for GET /api/v2/collections
as well as the collection read, so a slow or timed-out list held it on
"Loading collection editor..." even after the collection had loaded. Before
the refactor the personal editor opened as soon as its own read arrived.

Each scope now says whether its editor waits for the list. The admin editor
still does, because its read carries no artwork; the personal editor opens at
once and takes the list's poster only when the list is already there.

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

coderabbitai Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 13f3eefb-efde-43bb-b3f2-985ae7535936

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autopilot · 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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-04T19:43:58.502487Z 90e42e3 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@macroscopeapp

macroscopeapp Bot commented Oct 4, 2026

Copy link
Copy Markdown

Major change — #195 W1: The personal editor previously kept its frozen collection after a background read returned 404; useScopeEditor now hides it. This changes what remains visible after a profile switch or access revocation. Please identify this as an intentional behavior change and track W1 for validation after merge; W1 is currently Not run, so there is no prior result to carry forward.

Minor change — #194 A3: The admin editor now observes artwork through a list query with the app’s two-minute default stale time rather than the previous 30-second setting. Another admin’s recent artwork change may therefore appear stale on reopen. Track A3 for validation after merge.

W2, W3, W5, W6, and A1/A2 retain equivalent routes and request behavior. W7 remains blocked by #1615/#1616; this PR does not implement that sharing/order model.

Replace the Validation tasks line with:
Validation tasks: changes #195 W1, #194 A3

Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed.

Posted via Macroscope — v1 validation impact

Base automatically changed from test/collections-editor-goldens to feat/collections-revamp October 4, 2026 19:37
@Quick104

Quick104 commented Oct 4, 2026

Copy link
Copy Markdown
Contributor Author

Updated the Validation tasks line to changes #195 W1, #194 A3 and noted under Risks that the personal editor now drops a collection after a 404, as the admin editor already did.

@Quick104
Quick104 merged commit aa318a5 into feat/collections-revamp Oct 4, 2026
15 checks passed
@Quick104
Quick104 deleted the refactor/collection-scope-adapter branch October 4, 2026 19:52
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