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

Page reset762 #763

Merged
merged 7 commits into from
Aug 9, 2019
Merged

Page reset762 #763

merged 7 commits into from
Aug 9, 2019

Conversation

Avd6977
Copy link
Contributor

@Avd6977 Avd6977 commented Jul 10, 2019

Fix for #762

@coveralls
Copy link

coveralls commented Jul 10, 2019

Coverage Status

Coverage increased (+0.0001%) to 74.963% when pulling 37266ad on Avd6977:PageReset762 into 6740f71 on gregnb:master.

@gabrielliwerant
Copy link
Collaborator

Seems to me like this PR would cause a regression with this: #647.

If the page is set, and we don't reset it on searches (and filters and probably some other things), then the results may not show and we may get errors. The page has to be reset on searching.

@gabrielliwerant
Copy link
Collaborator

gabrielliwerant commented Jul 10, 2019

What we need to know here is two things:

  1. Whenever the searchText goes from empty to something, we need to reset page to 0
  2. If the previous searchText is not empty, then we need to make sure the page number does not exceed the list of results (something like RoundUp(results / rowsPerPage) = max page number.

@Avd6977
Copy link
Contributor Author

Avd6977 commented Jul 11, 2019

Why don't we just not reset it and have that be the responsibility of the consumer? If they're passing in page and search text, then they know that the page should be reset and can simply add page = 0 when search text is changed (that's what we're doing and how we caught this). So if the consumer is managing the page state, then there shouldn't be a need to reset it.

@gabrielliwerant
Copy link
Collaborator

I understand your point, but it would be unclear to me that I would need to reset the page after a search. I would expect searching to handle this for me. In particular, there are definitely issues with out of bounds pages after searching that should at least be checked against occurring, and then handled appropriately.

I'd also rather not go back on fixes that existed previously if at all possible (there are exceptions, but I don't think this should be one). People are relying on the fixes that were put in place previously, so I don't want to break it again. I think with additional logic, we should be able to achieve both aims here. If you like, I can help out here when I get a chance.

@Avd6977
Copy link
Contributor Author

Avd6977 commented Jul 15, 2019

Yeah, I understand not wanting to revert back a bug. My thought was that the whole project was moving away from managing the internal state and moving toward putting more onus on the consumer of the table. Some documentation to reset page when searching or filtering may just be needed? Does the paging update when the filter is changed, as well?

Could be documented as a breaking change, as well. But if you'd rather put it in the code to fix this, that's fine. What would be your ideas to do that and not break the old bug? I'm not sure exactly what you're wanting to fix it with so some help would be great.

Copy link
Collaborator

@gabrielliwerant gabrielliwerant left a comment

Choose a reason for hiding this comment

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

Sorry, it's been a while, but if you're up for it, I have a suggestion now that I think will satisfy both use cases.

@@ -202,7 +201,7 @@ class MUIDataTable extends React.Component {
this.setHeadResizeable(this.headCellRefs, this.tableRef);

// When we have a search, we must reset page to view it
if (this.props.options.searchText) this.setState({ page: 0 });
if (this.props.options.searchText && !this.props.options.page) this.setState({ page: 0 });
Copy link
Collaborator

@gabrielliwerant gabrielliwerant Aug 1, 2019

Choose a reason for hiding this comment

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

Ok, how about !this.props.options.serverside instead of !this.props.options.page? Same for below. That way, we keep the old bugfix for people that are using custom pages, but we prevent serverside behavior from changing. @Avd6977

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That should work for us and keep the serverside behavior the same, but would it be confusing for anyone using it? I made the change so if we're good with it you can just accept it.

Copy link
Collaborator

@gabrielliwerant gabrielliwerant left a comment

Choose a reason for hiding this comment

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

Yep, this should work just fine, as it looks like searches on the client are disabled id serverSide === true, meaning that no one using serverSide === true should experience a regression. Thanks for making the change and for bearing with me!

@gabrielliwerant gabrielliwerant merged commit 6a3432c into gregnb:master Aug 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants