Fix filter count badge on Orders/Vouchers lists - #4834
Conversation
Reviewer's GuideThis PR fixes incorrect and non-live filter count badges on the Orders list and adds working filter badges to Vouchers by excluding technical fields from the count, wiring voucher views to compute the count, updating templates to render badge state, and syncing the badge client-side after AJAX updates. Sequence diagram for AJAX filter badge sync on Orders/Vouchers listssequenceDiagram
actor Admin
participant Browser
participant ajax_filter_js as ajax_filter_js
participant Server
participant VoucherListView
Admin->>Browser: Submit filter form
Browser->>ajax_filter_js: fetchAndReplace(url, replaceUrlParams, form)
ajax_filter_js->>Server: HTTP GET with filter params
Server->>VoucherListView: dispatch request
VoucherListView->>VoucherFilterForm: clean()
VoucherListView->>advanced_filter_count: advanced_filter_count(filter_form)
VoucherListView-->>Server: context with advanced_filter_count
Server-->>ajax_filter_js: HTML response (updated results region)
ajax_filter_js->>ajax_filter_js: getResultsContainer(tabContext.context)
ajax_filter_js->>ajax_filter_js: replace resultsContainer with newContext
ajax_filter_js->>ajax_filter_js: syncFilterBadge(tabContext.context, newContext)
ajax_filter_js-->>Browser: Updated DOM (badge created/updated/removed)
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Thank you for contributingPlease complete the checklist. Screenshots in the PR description and completed AI reviews are checked automatically.
🤖 AI reviews❌ 1 failed or rate-limited AI reviewer
ℹ️ Does not count toward the checklist
📎 Attached media (3)Thank you for your contribution feel free to reach out if you have any questions. |
There was a problem hiding this comment.
Hey - I've found 2 issues, and left some high level feedback:
- In
syncFilterBadge, the logic relies on adata-filter-countattribute, but the vouchers filter toggle template doesn’t set this attribute, so AJAX responses for vouchers will always yield a count of 0 and remove the badge; consider addingdata-filter-count="{{ advanced_filter_count|default:0 }}" to the vouchers filter button as you did for orders. - To avoid divergence between server-rendered state and
syncFilterBadge, you might want to derive the initialdata-filter-countfrom the presence/value of[data-advanced-filter-count]when the attribute is missing, so the JS remains robust if a template forgets to set it.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `syncFilterBadge`, the logic relies on a `data-filter-count` attribute, but the vouchers filter toggle template doesn’t set this attribute, so AJAX responses for vouchers will always yield a count of 0 and remove the badge; consider adding `data-filter-count="{{ advanced_filter_count|default:0 }}`" to the vouchers filter button as you did for orders.
- To avoid divergence between server-rendered state and `syncFilterBadge`, you might want to derive the initial `data-filter-count` from the presence/value of `[data-advanced-filter-count]` when the attribute is missing, so the JS remains robust if a template forgets to set it.
## Individual Comments
### Comment 1
<location path="app/eventyay/static/eventyay-common/js/ajax-filter.js" line_range="108-117" />
<code_context>
+const syncFilterBadge = function(oldContext, newContext) {
</code_context>
<issue_to_address>
**issue (bug_risk):** Hidden state of the badge is not synchronized, which can leave an existing badge permanently hidden.
In the vouchers template, the badge is initially rendered with `hidden` when `advanced_filter_count` is falsy. `syncFilterBadge` only updates `textContent` and never updates `hidden`, so a badge that starts hidden will remain hidden even when `newCount > 0`. Please also toggle the `hidden` attribute based on `newCount` (remove it when `newCount > 0`, add it when `newCount === 0`) to keep server-rendered and client-updated states aligned.
</issue_to_address>
### Comment 2
<location path="app/eventyay/control/templates/pretixcontrol/vouchers/index.html" line_range="66-69" />
<code_context>
data-advanced-filter-toggle
+ data-filter-count="{{ advanced_filter_count|default:0 }}"
aria-controls="advanced-filter-advanced"
aria-expanded="{% if advanced_filters_open %}true{% else %}false{% endif %}">
<span class="fa fa-sliders" aria-hidden="true"></span>
</code_context>
<issue_to_address>
**issue (bug_risk):** Vouchers filter toggle does not expose `data-filter-count`, which `syncFilterBadge` relies on.
`syncFilterBadge` reads `data-filter-count` from the toggle element, but in the vouchers template only the inner badge span has a count (`data-advanced-filter-count`). This means the vouchers toggle always yields `NaN` and falls back to `0`, potentially desynchronizing badge counts between tabs. Adding `data-filter-count="{{ advanced_filter_count|default:0 }}"` to the vouchers button, matching the orders template, keeps the behavior consistent and prevents this desync.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
@sourcery-ai review |
|
Sorry @codesbyjit, you have reached your weekly rate limit of 500000 diff characters. Please try again later or upgrade to continue using Sourcery |
Aqil-Ahmad
left a comment
There was a problem hiding this comment.
you need to add recording so it can be confirmed it works without reload



Fixes #4832
This PR fixes the filter count badge on the All Orders list not updating live and showing an incorrect count, and adds the missing badge to the Vouchers list.
Root Cause
advanced_filter_count()incontrol/forms/filter.pycounted the hiddenbrowser_timezonefield (always populated by JS) as an active filter, causing the badge to shown+1instead ofn.[data-ajax-results-region]element thatajax-filter.jsreplaces on every AJAX filter request, so the badge was never updated until a full page reload.control/views/vouchers.pynever computed or passedadvanced_filter_countto the template, andvouchers/index.htmlhad no badge markup at all — so the Vouchers list showed no filter count, unlike Orders.Changes
control/forms/filter.py: excluded technical/non-user-facing fields (browser_timezone,search,query,ordering) fromadvanced_filter_count()andadvanced_filters_open_from_get(), fixing the incorrect count.control/views/vouchers.py: addedctx['advanced_filter_count'] = advanced_filter_count(self.filter_form)so the Vouchers list can render a count.control/templates/pretixcontrol/orders/index.html&.../vouchers/index.html: added adata-filter-countattribute on the Filters toggle button, and added the badge<span>to the Vouchers template (it was missing entirely).static/eventyay-common/js/ajax-filter.js: addedsyncFilterBadge(), called after every AJAX filter/pagination/sort response, so the badge updates (create/update/remove) immediately instead of requiring a reload.Testing
n+1), and disappears on Clear filters — all without a page reload.Screenshot
Summary by Sourcery
Fix filter count badges for orders and vouchers so they display and update the correct number of active filters, including during AJAX-based updates.
Bug Fixes:
Enhancements: