Repository navigation
Conversation
…s the whole collection
The admin collection list (`/_emdash/admin/content/{collection}`) had three
compounding UX failures that made it functionally broken past the first
API page.
1. Search was client-side, title-only, and scoped to already-fetched
pages. Typing "Bleeding" on a collection with 100+ entries showed
zero results because the matching item was on API page 2. The
handler now accepts `q`; `ContentRepository.findMany` introspects
the table's columns and builds a case-insensitive `LIKE` against
whichever of `title`, `name`, `slug` actually exist. LIKE wildcards
are escaped; inputs are trimmed and capped at 200 chars.
2. Column headers were static labels. They're now buttons that call
`onSortChange` and surface direction via `aria-sort`. The repo's
order whitelist picks up `status`, `locale`, and `name` in addition
to the existing date fields.
3. The pagination denominator grew in increments of 5 as the user
paged forward (API limit 100, client page size 20). The list
response now includes `total`; the admin uses it as the stable
denominator and clamps the current page if filters collapse the
count.
The MCP `content_list` tool also accepts `q`, so agents don't have to
post-filter either.
Tests: adds regression coverage for all three bugs in both the repo
and the handler, plus controlled-search and sortable-header cases in
the `ContentList` component test. The existing pagination tests still
pass with the legacy unconditional behavior, proving backward compat.
- a11y: drop the redundant aria-label on sort buttons; screen readers announce sort state via aria-sort on the <th> already. The visible "Title" span is now the button's accessible name, matching the WAI-ARIA APG sortable-table pattern and removing verbose re-reads on every focus. - a11y: add an explicit focus-visible outline to the sort button so the focus ring doesn't rely on browser defaults (kumo resets them). - docs: comment the auto-fetch effect in ContentList to document its reliance on the caller's onLoadMore being deduped (the router wires it to react-query's fetchNextPage, which is). - ContentPickerModal: pass `placeholderData: keepPreviousData` to react-query so the list doesn't flash to empty between keystrokes while the debounced search refetches. - tests: add aria-sort assertions on both the active and inactive headers, a slug-only-collection search case (collections with no title/name column), and a multi-page search that proves `total` stays consistent across cursor pages.
🦋 Changeset detectedLatest commit: f5bbbf8 The changes in this PR will be included in the next version bump. This PR includes changesets to release 12 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Scope checkThis PR changes 2,716 lines across 31 files. Large PRs are harder to review and more likely to be closed without review. If this scope is intentional, no action needed. A maintainer will review it. If not, please consider splitting this into smaller PRs. See CONTRIBUTING.md for contribution guidelines. |
Lunaria Status Overview🌕 This pull request will trigger status changes. Learn moreBy default, every PR changing files present in the Lunaria configuration's You can change this by adding one of the keywords present in the Tracked Files
Warnings reference
|
@emdash-cms/admin
@emdash-cms/auth
@emdash-cms/blocks
@emdash-cms/cloudflare
emdash
create-emdash
@emdash-cms/gutenberg-to-portable-text
@emdash-cms/x402
@emdash-cms/plugin-ai-moderation
@emdash-cms/plugin-atproto
@emdash-cms/plugin-audit-log
@emdash-cms/plugin-color
@emdash-cms/plugin-embeds
@emdash-cms/plugin-forms
@emdash-cms/plugin-webhook-notifier
commit: |
|
Closing at my own request — this PR bundles three distinct fixes and is too large to review as one unit. Splitting into three independent PRs, each with its own changeset, tests, and scope so they can be reviewed/merged on their own cadence:
Each will link to the others for context. All three share the same branch root and tests; no one depends on another being merged first, though the UX benefits compound. Thanks — and sorry for the noise. |
What does this PR do?
Fixes three compounding UX failures in the admin collection list view (
/_emdash/admin/content/{collection}). Each one looks like a separate paper-cut in isolation, but together they make the admin functionally broken for any collection larger than the first API page.1. Search didn't find existing content
Typing
Bleedingin the search box on a collection with 100+ entries returned zero results even though a published entry titled exactlyBleedingexisted. The admin filtered client-side againstitemsalready in memory, and the API accepted neither asearchnor aqparam. For entries past the first fetch, the user saw "No results" and had no way to know the item was there.Fix:
GET /_emdash/api/content/{collection}now acceptsq— case-insensitive substring match against whichever oftitle,name, andslugactually exist on the collection's table (introspected viapragma_table_info/information_schema.columns). LIKE wildcards are escaped (%,_,\), inputs are trimmed + capped at 200 chars, and the MCPcontent_listtool acceptsqtoo.2. Column headers weren't sort controls
Title,Status,Locale,Datewere plain<th>labels with no click handler, noaria-sort, no indication they could do anything. The repository'sFindManyOptionsalready supportedorderBy, but nothing in the admin sent it.Fix: headers are now real
<button>s wrapped in<th aria-sort>. Click cycles direction; screen readers get the sort state viaaria-sorton the header (which they announce automatically), so the button's accessible name stays clean. Extended the server'smapOrderFieldwhitelist to includestatus,locale, andnamealongside the existing date fields.3. Pagination denominator grew as you paged forward
Pages 1–4 showed
1/5,2/5, …; page 5 showed5/10; page 10 showed10/15; and so on.PAGE_SIZE = 20paginates over what's been fetched;limit = 100per API call means 5 client pages per fetch. The auto-fetch effect fired when you reached the last client page, another 100 arrived,totalPagesjumped, and the denominator lurched forward.Fix: list response now returns
totalalongsideitems+nextCursor. Admin uses it as the stable denominator (a 143-entry collection reads1/8on page 1). When a server doesn't returntotal, the admin falls back to the pre-change behavior, so old servers keep working.While I was there
ContentPickerModalhad the same client-side search bug — it now passesqto the API too. AddedplaceholderData: keepPreviousDataso the picker list doesn't flash to empty between keystrokes while the debounced query refetches.clampedPagelogic inContentListhandles the edge case where filters collapse the result count below the current page (previously rendered an empty table until the next refetch).Type of change
The symptoms are user-facing (search doesn't find existing content; pagination denominator is non-monotonic) and the fixes are scoped to the list endpoint + admin list component + picker. Happy to split into three separate PRs if preferred, but I think the change is easier to review together since the three symptoms share the same root cause (admin treating the list as a thin client over a cursor-only API with no server-side query support).
Checklist
pnpm typecheckpasses (admin + core)pnpm lintpasses (no new findings; pre-existing workspace-wide warnings unchanged)pnpm testpasses for touched areas:packages/corerepo + handler suites (92 tests),packages/admincomponent suite (39 tests including 5 new ones)pnpm formathas been runpnpm locale:extractwas run; the diff simplifies the a11y strings (net -3 new messages across all locales)patchforemdashand@emdash-cms/admin)AI-generated code disclosure
Produced in a single Claude Code session. Ran Code Reviewer, Security Engineer, and Accessibility Auditor sub-agents against the committed-but-unpushed branch and applied their findings in commit 2 before pushing — specifically:
aria-labelin favor ofaria-sort(which screen readers announce automatically) and added an explicitfocus-visibleoutline since kumo resets browser defaults.pragma_table_info(?)is parameterized by better-sqlite3 andvalidateIdentifieris belt-and-braces, not load-bearing; LIKE escape order is correct; addedESCAPE '\\'pairing verified.title/name) and for multi-page search preservingtotalacross cursor pages; documented the auto-fetch effect's reliance on the caller dedupingonLoadMore.Testing
From a fresh
pnpm install+pnpm build:New regression tests (all fail on
main, pass on this branch):ContentRepository > findMany > search > finds items by a title substring matchContentRepository > findMany > search > is case-insensitiveContentRepository > findMany > search > searches slug-only collections that have no title/name columnsContentRepository > findMany > search > keeps list items and total consistent across paginationContentRepository > findMany > search > escapes LIKE wildcards so they don't act as patternsContentRepository > findMany > total > reports total rows regardless of limitContentRepository > findMany > orderBy > accepts status as an order fieldContent Handlers — list search and total > filters items by q (case-insensitive substring)Content Handlers — list search and total > returns total independent of limitContentList > pagination > uses \total` as a stable denominator instead of items.length`ContentList > sortable headers > calls onSortChange when a header is clickedContentList > sortable headers > exposes sort state via aria-sort on the active headerContentList > controlled search > forwards the typed query to onSearchChange without local filtering