Repository navigation
feat: filter the content list by taxonomy term - #3046
eisenbruch wants to merge 13 commits into
Conversation
🦋 Changeset detectedLatest commit: 71c5231 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 506 lines across 11 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. |
Overlapping PRsThis PR modifies files that are also changed by other open PRs:
This may cause merge conflicts or duplicated work. A maintainer will coordinate. |
@emdash-cms/admin
@emdash-cms/auth
@emdash-cms/auth-atproto
@emdash-cms/blocks
@emdash-cms/cloudflare
@emdash-cms/contentful-to-portable-text
emdash
create-emdash
@emdash-cms/gutenberg-to-portable-text
@emdash-cms/plugin-cli
@emdash-cms/plugin-test
@emdash-cms/plugin-types
@emdash-cms/registry-client
@emdash-cms/registry-lexicons
@emdash-cms/registry-loader
@emdash-cms/registry-moderation
@emdash-cms/registry-verification
upgrade-emdash
@emdash-cms/sandbox-workerd
@emdash-cms/x402
@emdash-cms/plugin-ai-moderation
@emdash-cms/plugin-ai-search
@emdash-cms/plugin-atproto
@emdash-cms/plugin-audit-log
@emdash-cms/plugin-color
@emdash-cms/plugin-embeds
@emdash-cms/plugin-field-kit
@emdash-cms/plugin-forms
@emdash-cms/plugin-webhook-notifier
commit: |
Visual regression: 10 screens changedThese admin screens render differently on this PR. Confirm every change below is intended before accepting.
Maintainers: if every change above is intended, comment Measured head: |
|
Two notes on the CI run, to save a reviewer the digging:
|
There was a problem hiding this comment.
This PR adds termFilters to the content list API and admin UI, aligned with the shape approved in Discussion #3055. The approach is sound: termFilters is a sibling to fieldFilters (avoiding name collisions), applies OR within a taxonomy and AND across taxonomies via correlated EXISTS subqueries, and is mirrored in countWithResolvedFilters so cursor totals stay stable. The handler correctly rejects taxonomies not attached to the collection instead of silently ignoring them, and the changeset documents the new parameter and failure behavior well.
I checked the diff, AGENTS.md, and related code. The core implementation is clean and the new tests cover the junction semantics. Two admin issues need fixing before merge: FilterBar does not treat term filters as active filters, so the clear button can be hidden and won't clear term filters; and TermFilters lowercases taxonomy labels before passing them to Lingui, which is English-specific and harms other locales. TermFilters also indents hierarchical terms with literal non-breaking spaces, which is not RTL-safe per AGENTS.md. The verbose justifying comment in the handler can be trimmed once the changeset/PR cover it.
Conclusion: approach LGTM, but fix the admin filter-state handling and i18n/RTL issues.
Findings
-
[needs fixing]
packages/admin/src/components/ContentList.tsx:888-904hasActiveFilterignorestermFilterandhandleClearnever resets it. As a result, when only a term filter is selected theClear filtersbutton (rendered fromhasActiveFilterat line 986) is hidden, and when other filters are present the button leaves the term filter applied after clearing everything else.Add a helper to check for active term selections and reset them in
handleClear:const isTermFilterActive = (filter: TermFilterState) => Object.values(filter).some((slugs) => slugs.length > 0); const hasActiveFilter = statusFilter !== "all" || authorFilter !== "" || !!dateFilter.from || !!dateFilter.to || isBylineFilterActive(bylineFilter) || isTermFilterActive(termFilter ?? {}); const handleClear = () => { onStatusFilterChange("all"); onAuthorFilterChange?.(""); onDateFilterChange?.(EMPTY_DATE_FILTER); // Clearing drops the selection but keeps the inferred-byline // preference, which is a display choice rather than an active filter. onBylineFilterChange?.({ ...EMPTY_BYLINE_FILTER, includeInferred: bylineFilter.includeInferred, }); onTermFilterChange?.({}); }; -
[needs fixing]
packages/admin/src/components/TermFilters.tsx:74-75Lowercasing taxonomy labels before passing them into Lingui placeholders is English-specific and makes the message wrong for locales where taxonomy names keep capitals (or follow other casing rules). The translators only see the already-lowercased placeholder value.
Drop the
.toLowerCase()calls and let the original label be the placeholder:allLabel={t`All ${def.label}`} ariaLabel={t`Filter by ${def.label}`} -
[needs fixing]
packages/admin/src/components/TermFilters.tsx:123Hierarchical indentation is done with literal non-breaking-space characters inside the option text. That is physical indentation and breaks RTL layout expectations: AGENTS.md requires RTL-safe logical Tailwind (
ps-*,padding-inline-start, etc.) in admin UI.Use an element with logical start padding instead, for example:
{options.map(({ term, depth }) => ( <Select.Option key={term.id} value={term.slug}> <span className={depth > 0 ? `ps-${Math.min(depth * 4, 12)}` : undefined} style={depth > 0 ? { paddingInlineStart: `${depth * 1}rem` } : undefined} > {term.label} </span> </Select.Option> ))} -
[suggestion]
packages/core/src/api/handlers/content.ts:553-556This comment is justification addressed to the reviewer rather than a future reader of the code. The same rationale and failure choice already appear in the PR description and the changeset, which are the right places for it. Once this block is merged, the behavior is clear from the validation code itself; trim the comment to the single line that states the invariant, or remove it.
e13a7f6 to
dca23a1
Compare
|
Rebased onto
The rebase conflicted only on the imports in |
There was a problem hiding this comment.
The approach remains appropriate and consistent with the accepted design. The follow-up addresses the earlier findings: term matches are deduplicated, collection navigation clears term selections before requests are formed, the joined column no longer collides with custom fields, canonical documentation covers the feature, and the picker shares the editor’s query key.
I reviewed the follow-up diff, surrounding query and state handling, the new regression tests, and the documentation against the implementation. I found no new issues requiring changes. Review was static; I did not run tests, builds, or lint checks.
Follow-up review by openai/gpt-6.1-sol, scoped to the changes since the last review.
…m-filters Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RktNvhjty22ohh1GSHXGMq
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RktNvhjty22ohh1GSHXGMq
There was a problem hiding this comment.
The approach fits the accepted design (OR within a taxonomy, AND across taxonomies, with total and cursor pages following the filter). The earlier findings stay fixed: matches are deduplicated, term selections clear on collection navigation, the joined column avoids custom-field collisions, canonical docs cover the feature, and the picker shares the editor's cache key. The reviewers disagree on whether the change is ready. One (anthropic/claude-opus-5-5) found no new issues and approved. The other (openai/gpt-6.1-sol) found two D1 limits that remain unhandled. Six taxonomy filters exceed the compound-SELECT ceiling, and valid combinations of term, field and inferred-byline filters exceed the bind-parameter ceiling. The existing D1 tests cover only one taxonomy, so they miss both cases. Both reviews were static; neither ran tests, builds or lint.
Reviewed by anthropic/claude-opus-5-5 and openai/gpt-6.1-sol. The change since the last review (2109 lines) was too large for a scoped follow-up, so this is a full review.
| WHERE ${collection} = ${type} | ||
| AND ${sql.ref("taxonomy_id")} IN (${jsonTextValues(this.db, groups)})`, | ||
| ); | ||
| return sql<{ _term_entry: string }>`(${sql.join(sets, sql` INTERSECT `)})`; |
There was a problem hiding this comment.
[needs fixing] This emits one flat compound SELECT containing every taxonomy's set. The schema permits 10 taxonomies, but production D1 permits only 5 compound-SELECT terms, as recorded by D1_COMPOUND_SELECT_LIMIT in packages/cloudflare/src/db/d1-dialect.ts. A valid filter on six applied taxonomies, each resolving to a term, therefore fails with too many terms in compound SELECT instead of returning the filtered page. Respect the adapter's compoundSelectLimit by nesting or otherwise restructuring the intersection while preserving the accepted 10-taxonomy contract. Add coverage for six or more taxonomies; the current D1 tests exercise only one. (Raised by openai/gpt-6.1-sol; anthropic/claude-opus-5-5 did not mention it.)
There was a problem hiding this comment.
Confirmed on D1: six taxonomies failed with too many terms in compound SELECT. Fixed in 71c52317e. With more than one taxonomy, every picked term is now bound in one JSON value as a [set, group] pair, and an entry matches when its pivot rows cover every set (GROUP BY entry_id HAVING COUNT(DISTINCT set) = n). That is one SELECT whatever the number of taxonomies. The page query and the count use it.
One taxonomy keeps the DISTINCT read. On the D1 test's 400 entries the grouped form read 2,001 rows per statement for a broad term against 1,602, and 17 against 15 for a narrow one.
New D1 test: six taxonomies applied, three entries carry all six picked terms and one carries five; total 3, and the second cursor page holds the third entry. It fails on the previous commit.
🤖 Generated with Claude Code
| WHERE ${collection} = ${type} | ||
| AND ${sql.ref("taxonomy_id")} IN (${jsonTextValues(this.db, groups)})`, |
There was a problem hiding this comment.
[needs fixing] Binding each taxonomy as JSON bounds its slug cost, but these clauses still add two parameters per taxonomy to an already parameter-heavy list query. A schema-valid request with five taxonomy filters, 40 indexed-field operands, and 25 bylines with includeInferredBylines=true binds 102 parameters before pagination: 10 for terms, 40 for fields, and 52 for the byline predicates (the IDs occur in both explicit-credit and inferred-author branches). That exceeds D1's 100-parameter limit even though the same field/byline request without term filters fits. Both page and count fail. Preserve the existing filter budgets by reducing bindings in the combined query, and extend the D1 combination test to multiple taxonomies rather than only one. (Raised by openai/gpt-6.1-sol; anthropic/claude-opus-5-5 did not mention it.)
There was a problem hiding this comment.
Confirmed: five taxonomies with 40 indexed-field values and 25 bylines with includeInferredBylines failed on D1 with too many SQL variables. Fixed by the same change in 71c52317e: term filters now cost two parameters in the page query and two in the count, however many taxonomies are named, so a term filter adds the same as with one taxonomy, which the existing D1 test already covered at those field and byline maximums. New D1 test with that five-taxonomy combination; it fails on the previous commit. A PostgreSQL and SQLite integration test now covers OR within plus AND across taxonomies, with an entry carrying two picked terms listed once.
🤖 Generated with Claude Code
…r limits An INTERSECT per taxonomy failed on D1 past five taxonomies (too many terms in compound SELECT) and added two bound parameters per taxonomy, so five taxonomies with the largest field and byline filters went over 100. Several taxonomies now bind every picked term as one JSON list of [set, group] pairs and match entries whose rows cover every set (GROUP BY ... HAVING). One taxonomy keeps the DISTINCT read, which reads fewer rows on D1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RktNvhjty22ohh1GSHXGMq
There was a problem hiding this comment.
The revised approach fits the accepted design: grouping matching pivot rows preserves OR within each taxonomy and AND across taxonomies while avoiding D1’s compound-SELECT and parameter limits.
I reviewed the follow-up diff, traced the shared page/count filtering and both SQL dialect branches, and checked the added integration and D1 regressions. The two outstanding findings are addressed: multiple taxonomies now use one SELECT with two bindings, with coverage for six taxonomies, cursor pagination, and the maximum field/byline combination. Earlier resolved findings remain settled.
No new issues found in the changed code. This was a static review; I did not run tests, builds, or lint.
Follow-up review by openai/gpt-6.1-sol, scoped to the changes since the last review.
|
CI on
🤖 Generated with Claude Code |
|
This PR is waiting on its author because it has merge conflicts with |










What does this PR do?
Implements the accepted feature plan proposals/content-list-term-filters.md (#4087): the content list can be filtered by taxonomy term, in the admin and over the API.
OR within a taxonomy, AND across taxonomies.
totaland cursor pages follow the filter.Documented in the REST API reference ("Filter a content list by term") and the taxonomy guide.
Core
VALIDATION_ERROR, reading the applied collections from the taxonomy group structure.taxonomies.locale. If a taxonomy matches no term, it returns an empty list without running the list or count query.jsonTextValues, so there is no slug budget. The schema caps taxonomies at 10 and the raw parameter at 8,192 characters.CROSS JOINso SQLite keeps that order, and seeks each entry bytranslation_group. Filtered withINalone, the planner walked thecreated_atindex and tested every row. In the D1 test (400 entries, a term on 3), that page query read 405 rows. Now it reads 15. The count uses the same set in anIN.SELECT DISTINCT entry_idover its terms' rows, so an entry carrying two picked terms appears once. Several taxonomies bind every picked term in one JSON value as[set, group]pairs and keep the entries whose rows cover every set (GROUP BY entry_id HAVING COUNT(DISTINCT set) = n). Either way the filter is one SELECT with two parameters, so it stays inside D1's five compound-SELECT terms and 100 bound parameters at any number of taxonomies. The grouped form reads about a fifth more rows on D1, which is why one taxonomy keepsDISTINCT.DISTINCTfree. A unary+oncollection, SQLite only as in fix(core): seek an id-pinned collection read on the primary key #3916, keeps it on thetaxonomy_idindex._term_entry, which no field slug can match, so field filters and ordering on a field namedentry_idstay unambiguous.Admin
One picker per taxonomy applied to the collection, beside the byline filter. It is the entry editor's
TaxonomyTermPickerwith a newtoolbarmode: a filter-bar button instead of the labeled field with chips. The search, option list and keyboard handling are unchanged. Creation is off. Several terms can be picked. The selection is cleared when the list switches to another collection. Terms load as the editor loads them (includeCounts=false,resolveFallback=truefor the list's locale). "Clear filters" removes the term keys, and a taxonomy with nothing picked is never sent.Cost to know about: a term carried by nearly every entry reads about four rows per entry for the page and again for the count (1,602 each for 400 entries on D1), because both start from the pivot. For an admin list I chose that over the plan's failure case, a narrow term reading the whole collection.
Type of change
Your connection to this change
Checklist
pnpm typecheckpasses:tsgo --noEmitclean for core and adminpnpm lintpasses:oxlint --type-aware --deny-warningson every changed filepnpm testpasses (or targeted tests for my change): core repository, schema and integration tests 155 passed on SQLite and PostgreSQL 14; D1 tests 4 passed; adminTermFilters,TaxonomySidebar,ContentListand router tests 215 passedpnpm formathas been run:oxfmt --checkrepo-wide cleanmessages.pochanges except in translation PRs — a workflow extracts catalogs on merge tomain.AI assistance disclosure
Screenshots / test output
Before (
main): the posts list has no taxonomy filter.After: a picker per taxonomy beside the byline filter. Here the Categories picker is open with Tutorials and Opinion checked, and the list shows the 2 posts carrying either.
Tests, as the plan's Verification section lists them:
tests/database/repositories/content.test.ts, seedingcontent_taxonomiesby hand): OR within, an entry carrying two picked terms listed once (full page and one-per-page cursors), a field namedentry_idcombined with a term filter, AND across, unknown slug, empty slug list,totalacross cursor pages, with an indexed field filter, adelist matching through anen-only term, a parent not matching an entry that carries only its child, and one term lookup with no list query when a taxonomy matches no term.tests/unit/api/schemas.test.ts): malformed JSON, empty array, name pattern and length, slug length, 10 taxonomies, 300 slugs accepted, raw length.tests/integration/content/content-list-term-filters.test.ts), on SQLite and PostgreSQL 14: items and total, OR within plus AND across two taxonomies with an entry carrying two picked terms listed once, 152 slugs with 25 bylines,VALIDATION_ERRORfor an unapplied and for an unknown taxonomy.tests/workerd/content-list-term-filters-d1.test.ts): a narrow term's list plus count reads fewer rows than the collection's 400 entries; 151 slugs with 40 field-filter values and 25 bylines loads; six taxonomies (more than D1's five compound-SELECT terms) match only the entries carrying all six, across cursor pages; five taxonomies with 40 field-filter values and 25 inferred bylines stay under D1's 100 parameters.tests/components/TermFilters.test.tsx): nothing for a collection without taxonomies, several terms sent as slugs and the key removed when cleared, child terms listed, no create control, terms requested with fallback and without counts.ContentList.test.tsxcovers "Clear filters" for a term selection alone.router.test.tsx: a term picked on posts is not sent for pages, and is gone on returning to posts.Manual, on
pnpm ux:site:start(editorial-small), after assigning categories to the three posts:🤖 Generated with Claude Code
https://claude.ai/code/session_01RktNvhjty22ohh1GSHXGMq