Skip to content

feat: allow selecting multiple categories in demographic filters#609

Open
Joe-Heffer-Shef wants to merge 2 commits into
mainfrom
605-data-filters-multiple-selected-categories
Open

feat: allow selecting multiple categories in demographic filters#609
Joe-Heffer-Shef wants to merge 2 commits into
mainfrom
605-data-filters-multiple-selected-categories

Conversation

@Joe-Heffer-Shef

@Joe-Heffer-Shef Joe-Heffer-Shef commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

The survey report's demographic data filters used single-value dropdowns, so users could only filter to one category at a time. This converts categorical filters to checkbox lists, so multiple categories can be selected at once (e.g. several hospital sites within a Trust).

Screenshots

Each demographics field has a multi-checkbox option like this:

image

The selected categories are shown below the filter panel

image image

The charts are all filtered based on the selected categories

image image

Changes — SurveyDemographicFilters.svelte

  • State: Categorical filters now hold a string[] of selected options (empty = "All") instead of a single value. Types and onMount initialisation updated accordingly.
  • Filter logic: A response is kept if its value is in the selected set (includes); an empty selection applies no filtering. Numeric range filters are unchanged.
  • Active filters display: Multiple selections render comma-joined (e.g. Royal Hallamshire, Northern General). FilterAlert.svelte already renders this as free text, so it needed no change.
  • Clear filters: Resets categorical filters to a fresh empty array.
  • Markup: Replaced the <select> with an accessible checkbox group — <fieldset>/<legend> for grouping and for/id-linked labels (per the repo's WCAG focus), using Bootstrap form-check classes. Added a toggleOption helper that reassigns the array so Svelte 5 runes reactivity fires.

Tests

Added three tests: checkboxes render (no <select>), ticking two options keeps the union and shows both in the active filter, and an empty selection passes all responses through. The existing disabled-field regression test still passes.

Verification

  • npx vitest run on the suite: 4 passed.
  • npx eslint on both changed files: clean.

The backend (survey/views.py, survey/models.py) needed no changes since all filtering is client-side, and exports operate on the filtered set already passed through these components.

Closes #605

🤖 Generated with Claude Code

The survey report's demographic data filters used single-value dropdowns,
so users could only filter to one category at a time. Convert categorical
filters to checkbox lists so multiple categories can be selected at once
(e.g. several hospital sites within a Trust).

Categorical filter state now holds a string[] of selected options (empty
= "All") instead of a single value. A response is kept if its value is in
the selected set; an empty selection applies no filtering. Multiple
selections render comma-joined in the active filters display. Numeric
range filters are unchanged.

Replace the <select> with an accessible checkbox group using
<fieldset>/<legend> and for/id-linked labels per the repo's WCAG focus.

Adds tests covering checkbox rendering, multi-select union, and the
empty-selection pass-through. Filtering remains client-side, so no
backend changes are needed.

Closes #605

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Joe-Heffer-Shef Joe-Heffer-Shef linked an issue Jun 9, 2026 that may be closed by this pull request
@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 21.33% 584 / 2737
🔵 Statements 21.33% 584 / 2737
🔵 Functions 28.72% 27 / 94
🔵 Branches 63.93% 117 / 183
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
ui_components/src/lib/components/SurveyDemographicFilters.svelte 90.1% 76.78% 83.33% 90.1% 130-132, 165-169, 193-194, 220-230
Generated in workflow #327 for commit ba2b868 by the Vitest Coverage Report Action

@Joe-Heffer-Shef Joe-Heffer-Shef self-assigned this Jun 9, 2026
@Joe-Heffer-Shef

This comment was marked as resolved.

@Joe-Heffer-Shef Joe-Heffer-Shef added the enhancement New feature or request label Jun 9, 2026
…rendering

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Joe-Heffer-Shef Joe-Heffer-Shef requested a review from twinkarma June 9, 2026 12:12
@Joe-Heffer-Shef

Copy link
Copy Markdown
Collaborator Author

Closes #605

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Data filters: Multiple selected categories

1 participant