-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
[TableBody] revert willReceiveProps to respect selected property on TableRow #6295
Conversation
Apologies for all the commits... |
@jnishiyama Thanks for the PR, unfortunately it's breaking a unit test. You would have to fix it and add a new one for your use case if you want to move forward with that PR. I don't know much about the internal of the |
@jnishiyama I see what you did there. 😄 |
@oliviertassinari Hey I understand, but I was wondering if I can remove this test that you committed: the reason being that if the checkbox's If the purpose is to prevent a re-render if the default hasn't changed, then one option would be to compare the props, but I'm not sure if that defeats the purpose... e.g. componentWillReceiveProps(nextProps) {
if (this.props.allRowsSelected && !nextProps.allRowsSelected) {
this.setState({
selectedRows: [],
});
} else {
const oldRows = this.calculatePreselectedRows(this.props)
const nextRows = this.calculatePreselectedRows(nextProps)
if (!shallowEqual(oldRows, nextRows)) {
this.setState({
selectedRows: nextRows,
});
}
}
} |
The test was added in order to prevent regression on #5884. |
@oliviertassinari I added a test to prevent regression on my commit, and I never removed the test that was added for invariance on update. I did add a shallow compare in the willReceiveProps step, and I modified the test setup a bit so that I could test the change when the props were changed. Please let me know if this makes sense. |
@jnishiyama Thanks for the new test! I have tried running the added test on the master branch and that seems to be green. It looks like you are experiencing another issue. |
@oliviertassinari odd, it was failing for me with the code from master. Is the shallowCompare approach acceptable as a fix for the issue it is intended to solve? |
+1 -- any update on when this might get into master? |
]; | ||
|
||
function TableMutliSelect() { | ||
function TableMutliSelect(props) { |
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.
typo: Mutli -> Multi
@@ -52,4 +38,8 @@ function TableMutliSelect() { | |||
); | |||
} | |||
|
|||
TableMutliSelect.propTypes = { |
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.
typo: Mutli -> Multi
@oliviertassinari @yelmu any word on whether or not this implementation is sufficient? Or if there is something I should rework for a fix to be merged? |
@jnishiyama In the docs 'Complex example', enabling multi-select always selects rows 0 and 2. |
@mbrookes that's because in the docs code rows 0 and 2 have their selected property set to true:
|
@jnishiyama That would do it! 😆 I noticed a change in behaviour but didn't look any further. The |
Sorry, but the introduced tests are green on |
selectedRows: [], | ||
}); | ||
} else { | ||
const oldRows = this.calculatePreselectedRows(this.props); |
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 change makes that block run after every render, even if the allRowsSelected
property didn't change.
That's hiding something wrong. I definitely think that the correct fix isn't has that level of the code.
@oliviertassinari I am trying to fix the fact that you cannot programmatically select rows/checkboxes in the table as it stands (as of when I made this PR). What @mbrookes brought up actually highlights this issue:
Since the data provided to the table contains data with As of 0.17.0 (when I made the PR), my test will not pass with the old implementation. I cannot get the tests to run from the most up-to-date master Further, would you please explain which change specifically you are referring to that causes the re-render, because the logic of the conditional is identical, assuming that the property is boolean. in both implementations of the |
@jnishiyama Yes, sorry I was running the unit test, not the integration tests. I have spent too much time on the Thanks for the explanations! I much better understand the issue now. Actually, I have given a shot at the issue with #6638. Would you mind having a look at it? 😄 . I think that it's fully fixing the #6006 issue. |
This PR regards issue #6006. TableRow does not respect
selected
property, making it impossible to programmatically select a row. The code in this PR is the same code that was present as late as version 0.16.6, and resolves the issue.N.B.
Props
whereprops
are due: @mquandvr found the fix, but I decided to make the PR, because I am in need of this feature working.