Skip to content

Fix tag filtering and share one tag filter across index pages - #1520

Open
drusepth wants to merge 2 commits into
masterfrom
ccr-797cadb1-b46nmq
Open

drusepth wants to merge 2 commits into
masterfrom
ccr-797cadb1-b46nmq

Conversation

@drusepth

Copy link
Copy Markdown
Member

User-facing changes

  • The Tags menu on the timelines page lists each tag once. It used to repeat a tag once per timeline using it, e.g. "Season" twelve times.
  • Filtering timelines by tag works. Before, "Apply filters" just reloaded the page with nothing filtered.
  • Filtering characters, locations and other pages by a tag shows every page with that tag. It used to show only the first one.
  • Documents can be filtered by tag and status at the same time. That combination used to show an error page.
  • The Sort menu on the timelines page sorts: recently edited, alphabetical, date created or most events, with favourites first. It used to do nothing.
  • Changing the sort order, moving between pages of results, or clicking "See all" keeps the tags you picked.
  • Creating a page works when no tags are sent with it. It used to fail.
  • Saving a timeline only changes its tags when the tags are sent with the save. Before, a save without them would have removed all of its tags.
  • The Tags and Sort menus no longer flash open while the page loads.
  • On character and other content pages, the Tags menu now matches the timelines page: the label is hidden on small screens, it has dark-mode colours, and a long tag list scrolls.

Implementation notes

  • Root cause: content pages, timelines, documents and folders each had their own copy of the tag filter, and the copies had drifted. They used different param names (the timelines form sent slug[] while its controller read tag), de-duplicated differently, and documents/folders called pluck inside the per-document loop, so one query per document.
  • PageTagFilter (app/services/page_tag_filter.rb) holds the filtering logic. It lists each tag once by slug and keeps pages with any chosen tag (the existing behaviour). A relation stays a relation and is filtered with a SQL subquery; an array is filtered in Ruby. Keeping documents as a relation is what fixes the tag + status error, which came from calling .where on an Array.
  • FiltersByPageTags (controller concern) gives each controller a one-line filter_by_page_tags(pages, page_type:) and sets @page_tags / @filtered_page_tags for the views.
  • PageTagsHelper#selected_tag_slugs / #tag_filter_params are view helpers, so partials rendered by controllers without the concern (e.g. books/index renders the universe reminder) still work. The canonical param is ?tag[]=…. A single ?tag=… and the older ?slug[]=… are still accepted.
  • HasPageTags#update_tags replaces three copies of update_page_tags (content, timelines, documents), which resolves the old TODO. It takes an array or the delimited string tag fields submit, and removes with one destroy_all.
  • Timelines index builds its list as one relation (where(user:).or(where(universe_id: contributable))) instead of adding two arrays together. It filters, then sorts in sort_timelines. The unused pagination ivars are gone.
  • Content index no longer mutates the shared @linkables_raw array with select! when filtering by tag or favourites.
  • Views: the copied Tags dropdown and "Filtered by" chips are now the shared partials page_tags/_filter_menu and page_tags/_selected_filters. The chip's remove control was a <button> inside an <a>, which isn't valid HTML; it's now just the link.
  • Removed three partials nothing rendered: content/components/_list_filter_bar, content/list/_dense_cards and content/list/_document_table. Their paths, update_page_tags and page_tag_params are added to RetiredCodeTest::RETIRED.
  • Left as is:
    • The documents page still allows only one tag at a time; that's its existing design.
    • Picking several tags still shows pages with any of them, not pages with all of them.
    • Tags are still stored as one row per page rather than in a shared tags table. Changing that would be a much larger migration.

Testing

  • New tests:
    • test/services/page_tag_filter_test.rb: de-duplication, matching any tag, relation vs array input, ordered relations.
    • test/models/has_page_tags_test.rb: adding, removing, the delimited-string input, blanks and repeats.
    • test/controllers/timeline_index_tag_filter_test.rb: tags listed once, filtering, chip links, old URL forms, sorting, and saving a timeline without tags.
    • test/controllers/index_tag_filter_test.rb: characters (filtering and pagination links), documents (tag + status, tag menu), folders, and creating a page with no tag field.
  • Checked against the old code:
    • The first version of the timelines test failed on the old code and passes with the fix.
    • On the old code, "creating a page without a tag field" fails with ParameterMissing.
    • The tag + status error is from reading the old code, not from a test run on it.
  • Full suite: CI=true bin/rails test gave 898 tests, 0 failures, 1 skip. That includes test/smoke; the smoke, lint and tag tests were re-run after the last view tweak. bundle exec rspec spec: 14 examples, 0 failures.
  • Not checked by hand: I haven't clicked through these pages in a browser.

Generated by Claude Code

The timelines tag dropdown listed a tag once per timeline using it, and
its form submits slug[] while the controller only read tag=, so applying
a filter just reloaded the unfiltered page. List each tag once and read
slug[] (still accepting tag=).

ContentController de-duplicated matching tags before collecting page ids,
so filtering by a tag shared by several pages only kept the first page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RVaA9WvxUAj4b89GA9DRb4
Content pages, timelines, documents and folders each had their own copy
of the tag filter, and the copies had drifted: different param names,
different de-duplication, and per-document queries on documents and
folders. They now all use PageTagFilter through FiltersByPageTags, and
the tags menu and "Filtered by" chips are shared partials.

- One param, ?tag[]=…; single ?tag= and older ?slug[]= links still work.
  Sorting, paging and "see all" links keep the selection.
- Filtering a relation stays in SQL, so documents can be filtered by tag
  and status together (that combination used to raise).
- Saving tags is HasPageTags#update_tags instead of three controller
  copies. Creating a page no longer needs an empty field[value], and
  saving a timeline without tags no longer clears them.
- The timelines sort menu now sorts.
- Removed three partials nothing rendered.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RVaA9WvxUAj4b89GA9DRb4
@railway-app

railway-app Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

🚅 Deployed to the notebook-pr-1520 environment in Notebook.ai Feature Review

Service Status Web Updated
notebook 😴 Sleeping (View Logs) Web Nov 30, 2026 at 4:18 pm UTC

This branch was successfully deployed

1 active deployment
Notebook.ai Feature Review / notebook-pr-1520 — 2c62ce39 Deployed Nov 29, 2026 by railway-app[bot]
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