fix engagements filters in 'engagements by product view' #9913
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.
sc-[5299]
Description
Engagements filters inside the "Engagements By Product" view are not working properly. Searching by the exact name in the "Engagement name" filter is returning incorrect results.
The Problem
Building relationship filters as we currently do in
EngagementFilter
generates a query that gets filtered products with all the related engagements, where at least one engagement satisfies the filter criteria. Theengagements_all
view iterates over the engagements of each product to render the table rows. As the result, we ended up showing all engagements of the products that satisfied the filter criteria. For example, if there are two engagements that satisfied the filter criteria from two different products, the rendered table will show all engagements that belong to those two products.Solution
Using an additional filter when prefetching the engament_set will filter the engagements at the query level, so only filtered engagements related to filtered products will be obtained.
Also, the paginator object had to be modified, to represent the correct amount of rows that are currently shown in the page.