-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#765 Results Page: Persist the column filters in the results table in the url #778
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for mozilla-perfcompare ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some comments.
src/__tests__/CompareResults/__snapshots__/OverTimeResultsView.test.tsx.snap
Outdated
Show resolved
Hide resolved
src/__tests__/CompareResults/__snapshots__/ResultsTable.test.tsx.snap
Outdated
Show resolved
Hide resolved
src/__tests__/CompareResults/__snapshots__/ResultsView.test.tsx.snap
Outdated
Show resolved
Hide resolved
b618a8d
to
2ae22b0
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #778 +/- ##
==========================================
+ Coverage 91.53% 91.55% +0.02%
==========================================
Files 88 88
Lines 2350 2369 +19
Branches 443 449 +6
==========================================
+ Hits 2151 2169 +18
- Misses 176 177 +1
Partials 23 23 ☔ View full report in Codecov by Sentry. |
cdb7795
to
3b37a51
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this looks pretty good! The implementation is a bit complex though, so I left some comments about it, tell me what you think!
useEffect(() => { | ||
accessURlParams(); | ||
}, []); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using an effect, it would be better to use the 3rd version of useState (as described in the react documentation: https://react.dev/reference/react/useState#usestate).
This would set the initial value of tableFilters
by using the URL Params directly.
By using an effect, instead, this impairs the performance. Indeed this works like this:
- React renders the component (and the rest of the tree)
- React runs the effect.
- If the effect changes the state, React renders the component again... and the rest of the tree as well!
We want to avoid 2 and 3. By setting the right state right away at the first render time, only the first step is run, so this is much faster.
I'd like to stress that you need to use the 3rd version of useState
, not the first or second. Why? Because we want the computation to happen just once. This is explained in this part of their documentation: https://react.dev/reference/react/useState#avoiding-recreating-the-initial-state
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@julienw Thank you for the detailed explanation!
I’ve updated the code to use lazy initialization for tableFilters based on the URL Params as suggested. This way, the computation only happens once, and React renders the component only once during the initial render.
Thanks again for pointing this out, and for the useful documentation links!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @julienw I have implemented these changes and waiting for a re-review
f12d5fe
to
64fd51e
Compare
- If URL is empty, then all table filters are checked, otherwise set the table filters based off that. This helps results table to persist upon reload and url copying - Created a function that sets the filter to the url params on toggle
64fd51e
to
01d28de
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this looks pretty good!
I just noticed a few small things that could be improved, and also a test for the functionality is missing.
That's OK to not fix this PR, please focus on your new task, but I still wanted to give you this last feedback.
}; | ||
|
||
useEffect(() => { | ||
if (tableFilters.size > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This if
condition shouldn't be necessary: indeed you also want to update the URL when the value changes and is empty :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I see what you mean. I'll update this
rawSearchParams.delete(`filter-${columnId}`); | ||
updateRawSearchParams(rawSearchParams); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be unnecessary with the effect above especially if you remove the if.
cellsConfiguration.forEach(({ key, possibleValues }) => { | ||
if (!possibleValues) return; | ||
const paramValue = rawSearchParams.get(`filter-${key}`); | ||
initialFilters.set(key, new Set(paramValue?.split(','))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would be good to not set anything if paramValue is not present
@Netacci Hi I'd like to let you know you've been selected to go on the next round! Congrats! |
Thanks @Carla-Moz this is great news 🥲 I appreciate this opportunity 🙏 |
Okay thanks for this. |
Description
This PR addresses the issue where the results table resets during a page reload after a user applies column filters (e.g., platform, status, confidence). The filtered values do not persist, causing the results table to revert to its default state.
Before
perf.mp4
The problem occurred because the filters were not stored in the URL, leading to their loss upon page reload or when the URL is shared. As a result, the filtered state is not retained, and users have to reapply their filters each time a page reloads.
Test cases
By default, all filter values are checked, and as a result, all filter values are appended to the URL parameters.
To achieve this, I used
useEffect
to set an initial filter state. ThisuseEffect
sets all the checked filter values to the URL.defau-1.mp4
When specific filters are applied or modified, the relevant filter values are added or updated in the URL.
I adjusted the
onToggle
function to ensure that filter values are added to the URL when they are checked and removed whenunchecked. This helps in maintaining persistence on page reload.
add-remove-filters-1.mp4
page-reload-1.mp4
This was challenging to implement at first, because when all filter values are unchecked and the page reloads, the default behavior (from test case 1) would normally re-check all filters and set them back to checked. To resolve this, instead of removing the parameter keys entirely from the URL, I set their values to empty. I also updated the
useEffect
to run once on page load and check if there is existing checked values to be applied before setting the default. That way there's a significant difference between when a user has unchecked all filters and when the default filter settings should apply, ensuring the correct behavior on page load.all-unchecked-1.mp4
clear filter
button is clicked, filtered values are added back to the URL.I updated the
clearFilter
function to set all filter values to the URL.clear-filter-1.mp4
Steps to test