-
Notifications
You must be signed in to change notification settings - Fork 986
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
Fixes #37644 - Pagination doesnt update between react pages #10241
Conversation
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's confusing to me that there's a certain overlap between this and
foreman/webpack/assets/javascripts/react_app/components/PF4/TableIndexPage/TableIndexPage.js
Lines 115 to 128 in e78bd15
const urlParams = new URLSearchParams(historySearch); | |
const urlParamsSearch = urlParams.get('search') || ''; | |
const search = urlParamsSearch || getURIsearch(); | |
const defaultParams = { search: search || '' }; | |
if (updateParamsByUrl) { | |
const urlPage = urlParams.get('page'); | |
const urlPerPage = urlParams.get('per_page'); | |
if (urlPage) { | |
defaultParams.page = parseInt(urlPage, 10); | |
} | |
if (urlPerPage) { | |
defaultParams.per_page = parseInt(urlPerPage, 10); | |
} | |
} |
It makes me question: why does the front end hardcode a per_page
default? Shouldn't it just make an API request and read the per_page
value from the result? That way it respects the default settings.
nextPage = Number(params.get('page')); | ||
nextPerPage = Number(params.get('per_page')); | ||
nextPage = Number(params.get('page') || getURIpage()); | ||
nextPerPage = Number(params.get('per_page') || getURIperPage()); |
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.
On line 34 there's perPage
. Why isn't that used?
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.
line 34 is: const [perPage, setPerPage] = useState(propsPerPage || settingsPerPage);
and then later in this useeffect theres setPerPage(current => nextPerPage || current || settingsPerPage);
I think the code snippet you gave, is the one to prepage the page param before the api request, to know which page to request based on the url, so if the url is |
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.
Awesome, now it works as it should
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.
from the menu, go to audits, then from the menu go to models
result is that the page will show page 1, per page 20 results from the api, but the pagination ui will show page 2, per page 5.
When I do this on develop, I get the behavior above.
After checking out the pr, I get behavior that is better but still not correct: It seems like the pagination shows a correct page
of 1 but an incorrect perPage
:
"1-5 of 10" but it still shows all 10. (My default per page setting is unchanged from the default of 20.)
Thanks @jeremylenz added another condition to make sure the value is correct |
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.
Works well now 👍
thanks @MariaAga!
Ruby Katello failures unrelated; merging. |
To recreate the bug: navigate to
models?search=&page=2&per_page=5
from the menu, go to audits, then from the menu go to models
result is that the page will show page 1, per page 20 results from the api, but the pagination ui will show page 2, per page 5.
if the search is not empty, params.get('page') won't always be there, so the code sets the default value