Skip to content

fix(trustlab): fix list filters — repeated query params, singular keys, toolkit/playbook date filtering#1493

Merged
kilemensi merged 9 commits into
mainfrom
fix/trustlab-list-filters
Jun 26, 2026
Merged

fix(trustlab): fix list filters — repeated query params, singular keys, toolkit/playbook date filtering#1493
kilemensi merged 9 commits into
mainfrom
fix/trustlab-list-filters

Conversation

@kilemensi

@kilemensi kilemensi commented Jun 25, 2026

Copy link
Copy Markdown
Member

Description

What & why

Multi-value list filters serialised as comma-joined strings, so any value containing a comma (e.g. Nairobi, Kenya) was split and corrupted the backend query. This switches to repeated query params, consolidates date-range/query-param logic into shared, tested utilities, and standardises filter params to singular names end to end (filter.type === URL param === API param), matching the CMS filter config.

⚠️ Behavioural / contract changes

  • All four lists' filter URLs change (reports yearsyear, monthsmonth, reportsreport). Stale bookmarked / multi-select links silently reset — accepted trade-off.
  • toolkits & playbooks date filtering was completely broken (front-end sent year/month, API read years/months) and now works.
  • opportunities location filter is now exact (equals/in); search now matches title OR location.
  • pageExtensions tightened to page.* so co-located *.test.js files stop being collected as phantom API routes.
  • Adds DB indexes on title (all four) + location (opportunities) — triggers an index build on deploy.

Verified

  • 177 unit tests (Jest), lint, format all green.
  • Run against live data: comma values match exactly; equals is exact (substring → 0); toolkit/playbook year=2025→0 vs year=2026→5 (filter now honoured); repeated multi-value params; title+location search; renamed report slug filter.

Known limitations (out of scope)

  • Filter-bar UI doesn't reflect the URL, and the first-interaction anomaly remains (results restore, controls don't).
  • No search on toolkits/playbooks yet (so no search parity there).
  • Indexing covers title/location but not the date / createdAt / slug fields the range filters scan.

Test plan

  • pnpm jest --filter=trustlab (177 passing)
  • pnpm lint:check / pnpm format:check
  • pnpm build --filter=trustlab
  • Live API smoke for all four lists (filter, multi-value, search, bookmarked URL)
  • Browser confirmation of client-side URL→results restore

Type of change

  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Screenshots

N/A

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation

normalizeQueryList/singleQueryValue/setSearchParam centralise repeated-param (de)serialisation; buildDateRangeCondition builds UTC date-range where-clauses. Replaces ad-hoc comma-join/split logic that broke on comma-bearing values.
Use page.* pageExtensions instead of bare js/ts/tsx so co-located *.test.js files are not collected as (phantom) API routes.
Location/opportunity filters use exact equals/in (values come from an enumerated dropdown); search now matches title OR location; date filtering via shared buildDateRangeCondition. Fixes comma-bearing values (e.g. "Nairobi, Kenya") being split.
Drop the singular->plural keyMap; year/month/report are singular end to end (filter.type === URL param === API param), matching the CMS filter config.
…om URL

APIs now read singular year/month (front-end sent year/month while the API read years/months, so date filtering never applied). Consolidate onto buildDateRangeCondition; serialise repeated params; restore filter results from bookmarked URLs.
Add index:true to title (all four collections) and location (opportunities) to back the list filters/search. Note: triggers an index build on deploy.
@kilemensi kilemensi self-assigned this Jun 26, 2026
@kilemensi kilemensi added the bug Something isn't working label Jun 26, 2026
@github-project-automation github-project-automation Bot moved this to 🚧 In Progress in COMMONS Jun 26, 2026
@kilemensi kilemensi requested a review from kelvinkipruto June 26, 2026 06:37
@kilemensi kilemensi marked this pull request as ready for review June 26, 2026 06:37
@kilemensi

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 2937a8f433

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@kilemensi kilemensi requested a review from a team June 26, 2026 06:45
@kilemensi kilemensi added this pull request to the merge queue Jun 26, 2026
Merged via the queue into main with commit 04fcf0d Jun 26, 2026
8 checks passed
@kilemensi kilemensi deleted the fix/trustlab-list-filters branch June 26, 2026 08:34
@github-project-automation github-project-automation Bot moved this from 🚧 In Progress to ✅ Done in COMMONS Jun 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

2 participants