Skip to content
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

Increasing the rows per page causes the offset to increase too much and makes the table disappear #412

Closed
Dagonite opened this issue Jan 8, 2025 · 0 comments · Fixed by #439
Assignees
Labels
bug Something isn't working

Comments

@Dagonite
Copy link
Collaborator

Dagonite commented Jan 8, 2025

Description

When a user changes the rows per page value, the limit parameter in the API request is set to this new value. However, this also changes the offset value. The offset value is multiplied by the index of the current page number -- which doesn't take into account the fact that the number of pages will be less in instances when the rows per page value is increased.

This is what leads to the bug. If the rows per page value is increased, in some situations this can cause the offset to be changed to a value beyond the actual number of jobs. This causes the API request to return an empty list. As there are no runs, the boolean check in the code resolves to false so renders the "No reductions to show for this instrument" message instead of the table.

How to replicate

  1. Go to LOQ reductions.
  2. Go to the last page (page 5) whilst "25 rows per page" is active.
  3. Increase the rows per page to 100 (or whatever).
  4. Table should disappear and be replaced by a message saying "No reductions to show for this instrument".

Explanation

Currently, LOQ has 123 jobs to show.

With the limit set to 25, on page 5 the API request will look like this and return a non-empty list:

api/instrument/LOQ/jobs?limit=25&offset=100

The calculation for the offset is: (5-1) * 25 = 100


But if we change the rows per page value to 100, the offset gets changed to a value well beyond 123 which results in an empty list:

api/instrument/LOQ/jobs?limit=100&offset=400

This is because the offset calculation thinks we're on page 5, when actually we should be on page 2.

So the calculation is doing: (5-1) * 100 = 400

Instead of (2-1) * 100 = 100

@Dagonite Dagonite added the bug Something isn't working label Jan 8, 2025
@Dagonite Dagonite self-assigned this Jan 8, 2025
@Dagonite Dagonite changed the title Increasing the rows per page widget when there aren't enough reductions left to show crashes the table Increasing the rows per page widget causes the offset to increase too much and makes the table disappear Feb 5, 2025
@Dagonite Dagonite changed the title Increasing the rows per page widget causes the offset to increase too much and makes the table disappear Increasing the rows per page causes the offset to increase too much and makes the table disappear Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant