Skip to content

Listing pages filtering - #451

Open
jhancock532 wants to merge 31 commits into
migration-2026from
feature/listing-filters
Open

jhancock532 wants to merge 31 commits into
migration-2026from
feature/listing-filters

Conversation

@jhancock532

@jhancock532 jhancock532 commented Aug 24, 2026

Copy link
Copy Markdown

Description of Changes Made

Adds sector / service filtering to the news and work listing pages, as well as timing / event type for the event listing page.

  • Shared listing-filter form and context helpers (tbx/core/listing/)
  • Shared filter UI: dropdowns, active-filter pills, clear-all, JS component and styles
  • slug field added on the EventType snippet, used in event-filter URLs

How to Test

Test locally by confirming news, work and event listing pages filter correctly. By default, the event listing page should only show upcoming events.

Confirm that the user can select multiple filter options from the drop-down checkboxes, and apply their filter choices with the filter button.

Confirm that when the page loads with filters applied, these filters are shown in the active filters session. Dismissing one of the active filters causes the page to reload with that filter no longer applied.

Confirm that with active filters applied, pressing the "Clear all filters" button then removes all the active filters from the page.

Check out the listing filters component in the pattern library: http://localhost:8000/pattern-library/pattern/patterns/molecules/listing-filters/listing-filters.html

Screenshots

Expand to see more

Event page, dark mode with event type filters.

image

New page, light mode with multiple filters

image

Work page, light mode with multiple filters, mobile

image

Pattern library component

image

MR Checklist

  • Add a description of your pull request and instructions for the reviewer to verify your work.
  • If your pull request is for a specific ticket, link to it in the description.
  • Stay on point and keep it small so the merge request can be easily reviewed.
  • Tests and linting passes.

Unit tests

  • Added
  • Not required

Documentation

Browser testing

  • I have tested in the following browsers and environments (edit the list as required)
    • Latest version of Chrome on mac
    • Latest version of Firefox on mac
    • Latest version of Safari on mac
    • Safari on last two versions of iOS
    • Chrome on last two versions of Android
  • Not required

Data protection

  • Not relevant
  • This adds new sources of PII and documents it and modifies Birdbath processors accordingly

Light and dark mode

  • I have tested the changes in both light and dark mode
  • The change is not relevant to dark and light mode

Accessibility

  • Automated WCAG 2.1 tests pass
  • HTML validation passes
  • Manual WCAG 2.1 tests completed
  • I have tested in a screen reader
  • I have tested in high-contrast mode
  • Any animations removed for prefers-reduced-motion
  • Not required

Sustainability

  • Images are optimised and lazy-loading used where appropriate
  • SVGs have been optimised
  • Performance and transfer of data considered
  • If JavaScript is needed alternatives have been considered
  • Not required

Pattern library

  • The pattern library component for this template displays correctly, and does not break parent templates
  • The styleguide is updated if relevant
  • Changes are not relevant the pattern library

jhancock532 and others added 14 commits August 24, 2026 09:27
Reusable backend core for validating listing query params and building
the shared filter UI context, used by the blog, work and events listings.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Filter dropdowns, active-filter pills and the clear-all control shared by
the listing pages, plus the JS component and styles that drive them.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The slug is used as the value in event-filter URLs. Includes a factory
for test data.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Filters match both WorkPage and HistoricalWorkPage subtypes.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- Improve high contrast mode accessibility for submit button
- Remove excess comments
- Standardise use of SCSS styles for listing filters component
@jhancock532 jhancock532 changed the title Draft: Listing pages filtering Listing pages filtering Aug 24, 2026
@jhancock532
jhancock532 marked this pull request as ready for review August 24, 2026 10:21
@jhancock532
jhancock532 requested a review from helenb August 24, 2026 10:21
@jhancock532 jhancock532 self-assigned this Aug 24, 2026
@jhancock532
jhancock532 requested a review from tm-kn August 24, 2026 10:21

@helenb helenb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jhancock532 this is looking really good. Most of my comments are pretty minor. Note I think my comments may come in two reviews as I had another tab open to look a the CSS and markup changes in tandem.

Comment thread tbx/static_src/sass/components/_listing-filters.scss Outdated
Comment thread tbx/static_src/sass/components/_listing-filters.scss Outdated
Comment thread tbx/project_styleguide/templates/patterns/pages/events/events_listing.html Outdated
Comment thread tbx/static_src/javascript/components/listing-filters.js
Comment thread tbx/static_src/javascript/components/listing-filters.js Outdated

@helenb helenb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remaining review comments.

@zerolab

zerolab commented Aug 26, 2026

Copy link
Copy Markdown
Member

Q: does this supersede #438 ?

- Make focus styles for buttons consistent.
- Use data attribute instead of matching on details element
- Add comment reminder to update Jest markup
- Revert change moving minor duplicate code to shared component
@helenb helenb mentioned this pull request Aug 28, 2026

@helenb helenb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for all the fixes - this is looking great now - approving from a front-end perspective. It would be good if you can fix the one small remaining issue but it is non-blocking.

Comment thread tbx/blog/models.py Outdated
sector_choices=[(s.slug, s.name) for s in related_sectors],
service_choices=[(s.slug, s.name) for s in related_services],
)
form.is_valid()

@tm-kn tm-kn Sep 10, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue: I don't think you can access cleaned_data below if this is False. If the form is invalid, we should not apply filters. I can see the form is dropping incorrect values. Reading the calling code at this abstraction level I'd rather make it exhaustive based on values that is_valid may return.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated this to the behaviour you describe, see ccb1b34

Comment thread tbx/work/models.py Outdated
extra_url_params = {}
# Only offer Sectors and Services that are actually used on this listing.
related_sectors = Sector.objects.filter(
Q(pk__in=models.Subquery(self.works.values("workpage__related_sectors")))

@tm-kn tm-kn Sep 10, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Just a quick double check, does the related models here return PKs of the sectors or PKs of the through model instances?

Should the code explicitly use values_list with the PK field only to make the query behaviour easier to understand just by reading it?

Does values() do some form of implicit behaviour here to join those tables up?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This returns the primary keys of the sectors, as Django resolves the query all the way to the target model. I've made this more readable by using values_list like you've suggested in this commit here - 60ea32d

@jhancock532

Copy link
Copy Markdown
Author

I've confirmed Lily's extra requirement that it's possible to create multiple listing pages that show distinct content. Two pages of type BlogIndexPage can be created with different page titles, and then child pages can be added to them that only show in the filtered content of these pages.

@jhancock532

jhancock532 commented Sep 14, 2026

Copy link
Copy Markdown
Author

Hello @helenb & @tm-kn, we overlooked updating the links that navigate to the filter pages. I've addressed this in the above commits, ae7f65f...c41ba8a and deleted some unused code that had been left behind in the recent work.

To test the above, please confirm the following:

Expand to see more

Tags should filter correctly across the site

Within listing item cards in BlogIndex pages

image

Under the title of a Blog page

image

Beside the title of a Work page

image

There should be no regression on the people page

The main filter works as normal

image

The tag on the Person page filters according to team

image

Links in the primary navigation should filter correctly, for both service and sector

image

@jhancock532
jhancock532 force-pushed the feature/listing-filters branch from e4508a7 to c41ba8a Compare September 14, 2026 14:32

@helenb helenb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jhancock532 I had one small comment and a query. I am not 100% confident I understand the ways the menu links are generated but I have tested the scenarios you've laid out in your most recent comments and they seem to behave as expected.

Comment thread tbx/project_styleguide/templates/patterns/pages/blog/blog_listing.html Outdated
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.

4 participants