-
Notifications
You must be signed in to change notification settings - Fork 349
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
PF4 Table: 'Select All' checkbox updates #1368
PF4 Table: 'Select All' checkbox updates #1368
Conversation
} | ||
|
||
areAllRowsSelected(rows) { | ||
return rows.every(this.isSelected); |
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.
Should we skip expanded row children?
It's odd that both parent and child have a selected property because they could be initialized differently and/or be out of sync. In addition, setting the selected property on a child has no affect on its parent.
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.
I think that fix maybe on your onSelected
method, similar to the doc example here -you'll need to weed out the child rows w/o checkboxes in your method, and not set them to row.selected = true
.
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.
If I weed them out myself, will rows.every(this.selected)
still work?
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.
I don't think it's good idea to skip expanded children. There is option to show checkbox for expanded children as well, that might be handy in future once we figure out tree tables.
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.
Sounds reasonable. Thanks for the explanation
39bdd0f
to
e62b7d7
Compare
Pull Request Test Coverage Report for Build 4449
💛 - Coveralls |
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.
Good PR and good catch! I wouldn't personally use setState in componentDidUpdate
this triggers re-render and that is unwanted. Please calculate allRowsSelected
in render function directly that way we will not trigger multiple renders.
} | ||
|
||
componentDidUpdate(prevProps) { |
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.
I don't really like componentDidUpdate
function, it could lead to infinite loop (because of calling set state in it's body). Might be better to use static-getderivedstatefromprops.
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.
After further investigation, I don't think we need to store allRowsSelected
in state. Rather send
const headerData = calculateColumns(cells, {
// ...
allRowsSelected: this.props.onSelect ? this.areAllRowsSelected(this.props.rows) : false
})
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.
I don't really like
componentDidUpdate
function, it could lead to infinite loop
It does have a conditional check, but that might be a better way to go -thanks :-)
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.
Fixed
function selectClick(event) { | ||
const selected = rowIndex === undefined ? event.target.checked : rowData && !rowData.selected; | ||
onSelect && onSelect(selected, selected, rowId); | ||
onSelect && onSelect(event, selected, rowId); |
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.
Good catch!
This PR calls for new UX design as tri-state checkbo patternfly/patternfly#1411 |
PatternFly-React preview: https://1368-pr-patternfly-react-patternfly.surge.sh |
I think that should be handled in a follow on PR |
e62b7d7
to
fdbd17f
Compare
fdbd17f
to
60c89e1
Compare
@karelhala and @dlabrecq, I believe this PR is ready, pls review when u get a moment -thanks |
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.
Looks really good!
When all rows of the table are selected, the select-all checkbox is now selected automatically. Likewise, when the select-all checkbox is selected, and I deselect one or more rows, the select-all check box is deselected automatically.
Fixes #1352