Repository navigation
refactor(web): add the collection scope adapter and one set of type labels - #1914
Conversation
…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]>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Major change — #195 W1: The personal editor previously kept its frozen collection after a background read returned 404; 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: Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed. Posted via Macroscope — v1 validation impact |
…factor/collection-scope-adapter
…rows Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Updated the Validation tasks line to |
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.tsaddswithETag, which returns a v2 response body with its ETag and throws when the ETag is missing, and takes overrequiredETag. The eight hand-written ETag reads inapi/adminCollections.tsandapi/personalCollections.tsnow use it.web/src/lib/collections/scope.tsdefinesSERVER_SCOPEandPERSONAL_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.createandupdatecover 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.tsmoves tolib/collections/types.tsand gains the Manual / Smart / Synced list kinds, the synced source labels, and helpers that map a storedcollection_typeto them.ManualCollectionItemsEditortakes a scope instead of a source string.isCollectionReadOnlyis replaced byPERSONAL_SCOPE.isReadOnly, built onisOwnCollection. 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.browseand 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
tsc -bandmake test-webpass.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) anduseScopeEditor.internal/catalogthat names the moved file. Build, gofmt, vet,make lint-changedand the package tests pass.make verify-local-pathspasses. No contract or migration files changed, so the contract checks were not run.make verify-case-collisionsdoes not exist on this base and was not run.Risks
PERSONAL_SCOPE.isReadOnlyfails 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.Checklist
AI Disclosure
isReadOnlyfail open, letwithETagaccept a missing ETag, and madeuseScopeEditorignore 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
SERVER_SCOPEandPERSONAL_SCOPEdescriptors in scope.ts behind one typedCollectionScopeinterface, covering paths, cache keys, view/draft conversion, mutations, sync, preview, invalidation, and error formatting for both server (admin) and personal collections.web/src/lib/collectionTypes.tshelper file is removed.useScopeEditorin 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.withETagand movesrequiredETaginto etag.ts; personal and admin snapshot fetchers now use it to return body plus validated ETag.AdminCollectionEditor,CollectionEditor,ManualCollectionItemsEditor, collections hooks) to route through the scopes, deleting the standalone route builders and read-only helpers they replaced.ManualCollectionItemsEditornow takes a requiredCollectionScopeprop 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.