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

Fixes #33276 - Improve TableWrapper change tracking for search & pagination #9727

Merged
merged 11 commits into from
Oct 20, 2021

Conversation

jeremylenz
Copy link
Member

@jeremylenz jeremylenz commented Oct 15, 2021

The spawnFetch function within TableWrapper tracks several changes and prevents sending duplicate API requests for search and pagination. The changes tracked are

  • prevRequest - Don't send a request if it has the same metadata as the previously-sent request
  • paginationChangePending - Don't send a request with stale data if the user has clicked on a pagination button and the request is still in flight
  • prevSearch - Don't send duplicate requests with the same search query
  • additionalListeners - Send a new request if additionalListeners has changed, even if all of the above conditions would otherwise prevent it
  • Also, pagination params are supposed to reset back to page 1 whenever search or active filters change.

activeFilters was supposed to be tracking changes, but it wasn't. This caused pagination to be reset to page 1 when it shouldn't be.

Also, paginationChangePending wasn't getting reset when it should be.

What are the changes introduced in this pull request?

  • Change activeFilters from a boolean prop to an array of strings
  • Use a ref to track changes in activeFilters
  • Add variable names to spawnFetch so that logic is more readable
  • Clear paginationChangePending when resetting to page 1
  • Clear paginationChangePending before triggering a user pagination change (onPaginationChange)
  • Send the request through if additionalListeners have changed, even if stale pagination data would otherwise prevent it

What are the testing steps for this pull request?

You may want to check out the first commit, which has a lot of useful console logs added.

Load a page with filters, such as the Content Views tab of a composite content view
Change to page 2 > this should respond on the first click
Change filter from 'All' to 'Not added' > this should respond normally and not cause an infinite loop
Change filter from 'Not added' to 'Added' > this should respond normally and not cause an infinite loop
also make sure changing per_page works everywhere

@theforeman-bot
Copy link

Issues: #33276

@jeremylenz jeremylenz changed the title 33276 fix tablewrapper i hope Fixes #33276 - Improve TableWrapper change tracking for search & pagination Oct 15, 2021
@Andrewgdewar Andrewgdewar self-requested a review October 15, 2021 19:07
@jeremylenz
Copy link
Member Author

one remaining bug: Set perPage to 10 (or a non-default value) on the Filters tab, go to Histories, set a perPage, then go back to Filters. This would sometimes cause an infinite API call loop, with the per_page alternating between the default 20 and whatever you set it to.

I think this is caused by pages that store metadata in state. I removed metadata from state and it seems to fix it, so I went ahead and removed it from all other pages that store metadata in state as well.

@jeremylenz
Copy link
Member Author

Updated and rebased:

  • extracted metadata from response (properly this time, using omit from lodash)
  • for simpler cases, also stopped using results in the effect, so that both results and metadata are not stored in state
  • added defaultFilters prop so that isFiltering is still accurate in MainTable

In the future, we should also think about if we still need to store filters in additionalListeners. We might not need this any more.

@sjha4
Copy link
Member

sjha4 commented Oct 18, 2021

Noticed one remaining issue..
Screencast from 10-18-2021 05_19_38 PM

@jeremylenz
Copy link
Member Author

@sjha4 It was because that page wasn't passing activeFilters to TableWrapper, so the check that reset it to page 1 wasn't happening. We should probably figure out a way to conditionally require that prop..

I also found another bug where if you have an active search (type = security), and try to advance the page, it would go into an infinite loop. I think that was because the pagination override logic was clearing paginationChangePending even when the page wasn't being updated. Take it for another spin and see if it's better..

Copy link
Contributor

@Andrewgdewar Andrewgdewar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Phlegmless ACK!

@sjha4
Copy link
Member

sjha4 commented Oct 19, 2021

TableWrapper

The issue I saw yesterday is reproducible still..I think it's only happening on filter detail pages so we may have something going on there..

Sorry I don't know how to record a single screen..

@jeremylenz
Copy link
Member Author

@sjha4 That component also doesn't pass activeFilters. I'm going to make it a required prop; stand by...

@Andrewgdewar
Copy link
Contributor

do we have to make it a required prop for tableWrapper? won't that just mean that a ton of tables will pass in an empty array

@jeremylenz
Copy link
Member Author

Ended up not changing the required props. We probably should think about a solution though, as we now have 2 unenforced requirements:

  1. Any filters must be passed as activeFilters and defaultFilters props
  2. Filters must also be passed as additionalListeners

anyway, it's ready for review again :)

@jeremylenz
Copy link
Member Author

Filters must also be passed as additionalListeners

I'm thinking maybe it's safer to have activeFilters always treated as if they are additionalListeners, and not require you to add them explicitly. thoughts? (Could be a follow-up PR.)

@sjha4
Copy link
Member

sjha4 commented Oct 20, 2021

Filters must also be passed as additionalListeners

I'm thinking maybe it's safer to have activeFilters always treated as if they are additionalListeners, and not require you to add them explicitly. thoughts? (Could be a follow-up PR.)

Like the idea to avoid duplicating putting filters in 2 props..
In the context of this PR, I think all issues are resolved.. 🥳 Ack 👍🏽

@jeremylenz jeremylenz merged commit fbdd242 into Katello:master Oct 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants