fix(filters): don't auto-open the filter panel when only sorting a column#15082
Open
skywalke34 wants to merge 2 commits into
Open
fix(filters): don't auto-open the filter panel when only sorting a column#15082skywalke34 wants to merge 2 commits into
skywalke34 wants to merge 2 commits into
Conversation
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
Contributor
Author
|
I was not able to set the bugfix label. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
List pages share a single
django-filterform for both filtering and column sorting (theOrderingFilteroparameter). 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 — flipshas_changed()toTrueand 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_filterstemplate filter that mirrorsform.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 onaction_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'shas_changed()semantics is affected.django-filterdoes not usehas_changed()for filtering (it usescleaned_data), so query/sort results are unchanged.view_finding.htmluses a separate, hand-managedhas_changedflag for similar-findings, and the condition inview_notification_webhooks.htmlis commented out — both intentionally left unchanged in both trees.Test results
Added
unittests/test_filter_tags.pycoveringhas_active_filters:o=prod_type__name,o=-name) → not active (panel stays closed)name=…) / filter + sort → active (panel opens){% if form|has_active_filters %}renders the panel CLOSED for sort-only requests and OPEN when a filter value is present.{% 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
bugfixbranch.ruff.toml).bugfixlabel.