Skip to content

fix(filters): don't auto-open the filter panel when only sorting a column#15082

Open
skywalke34 wants to merge 2 commits into
DefectDojo:bugfixfrom
skywalke34:bugfix-asset-list-sort-opens-filter-panel
Open

fix(filters): don't auto-open the filter panel when only sorting a column#15082
skywalke34 wants to merge 2 commits into
DefectDojo:bugfixfrom
skywalke34:bugfix-asset-list-sort-opens-filter-panel

Conversation

@skywalke34

@skywalke34 skywalke34 commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Description

List pages share a single django-filter form for both filtering and column sorting (the OrderingFilter o parameter). The filter panel's initial expanded state is driven by {% if ...form.has_changed %}, so sorting a column — which only adds ?o=... to the URL — flips has_changed() to True and auto-opens the filter panel even though no filter was applied.

This is most visible on the Asset (Product) list: clicking the Organization or Active (Verified) Findings column header reloads the page and the filter panel springs open. (Originally reported in #1811 and since regressed.)

Fix: add a small has_active_filters template filter that mirrors form.has_changed() but ignores the ordering field (o), and use it for the panel-expand condition on all list pages, in both UI trees:

  • dojo/templates/ — new (Tailwind) UI — 17 templates.
  • dojo/templates_classic/ — classic (default) UI — 18 templates (the same list pages, plus both filter panels on action_history.html).

Sorting is no longer treated as filtering, so the panel stays closed unless a real filter value is set.

This is intentionally narrow and low-risk:

  • form.has_changed() itself is not modified, so nothing relying on Django's has_changed() semantics is affected.
  • django-filter does not use has_changed() for filtering (it uses cleaned_data), so query/sort results are unchanged.
  • The only observable effect is the filter panel's initial open/closed state.

view_finding.html uses a separate, hand-managed has_changed flag for similar-findings, and the condition in view_notification_webhooks.html is commented out — both intentionally left unchanged in both trees.

Test results

Added unittests/test_filter_tags.py covering has_active_filters:

  • no params / sort-only (o=prod_type__name, o=-name) → not active (panel stays closed)
  • a real filter (name=…) / filter + sort → active (panel opens)
Ran 6 tests in 0.017s
OK
  • Verified end-to-end through the template engine that {% if form|has_active_filters %} renders the panel CLOSED for sort-only requests and OPEN when a filter value is present.
  • Verified live on the new (Tailwind) UI: sorting the Asset list by Organization no longer opens the panel.
  • Compile-checked all 18 modified classic templates parse correctly with the new {% load filter_tags %} + |has_active_filters.

Documentation

No documentation changes needed — UI behavior fix, no settings or model changes.

Known related issue (out of scope here): on tables enhanced by DataTables, clicking a sortable header briefly client-sorts the visible rows before the server-side ?o= reload replaces them (a momentary "flash"). That is the long-standing client-vs-server sort conflict also noted in #1811 and is intentionally not addressed in this PR.

Checklist

  • Bugfix submitted against the bugfix branch.
  • Meaningful PR name (may be used in release notes).
  • Code is Ruff compliant (see ruff.toml).
  • Code is Python 3.13 compliant.
  • No model changes / migrations required.
  • Added applicable unit tests.
  • Fix applied to both the new and classic UI template trees.
  • Add the bugfix label.

List pages share a single django-filter form for both filtering and
column sorting (the OrderingFilter `o` param). The filter panel's
initial expanded state was driven by `form.has_changed()`, so sorting
a column — which only sets `?o=...` — flipped `has_changed` to true and
popped the filter panel open even though no filter was applied.

Add a `has_active_filters` template filter that mirrors `has_changed()`
but ignores the ordering field, and use it for the panel-expand
condition on all list pages. Filtering and sorting behavior are
unchanged; only the panel's initial open/closed state is affected.

Refs DefectDojo#1811

Authored by T. Walker - DefectDojo
The previous commit fixed the Tailwind (new) UI templates. The classic
(default) UI in templates_classic/ had the identical bug: sorting a
column only sets ?o=... but flipped form.has_changed() to true and
auto-opened the filter panel.

Apply the same has_active_filters template filter to all classic list
pages (and to both filter panels on action_history.html). view_finding
(hand-managed has_changed) and the commented-out condition in
view_notification_webhooks are intentionally left unchanged.

Authored by T. Walker - DefectDojo
@skywalke34 skywalke34 marked this pull request as ready for review June 24, 2026 19:17
@skywalke34

Copy link
Copy Markdown
Contributor Author

I was not able to set the bugfix label.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant