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

PF4 Table: 'Select All' checkbox updates #1368

Merged
merged 1 commit into from
Feb 13, 2019

Conversation

dtaylor113
Copy link
Member

@dtaylor113 dtaylor113 commented Feb 11, 2019

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

pf4-table

dlabrecq
dlabrecq previously approved these changes Feb 11, 2019
}

areAllRowsSelected(rows) {
return rows.every(this.isSelected);
Copy link
Member

@dlabrecq dlabrecq Feb 11, 2019

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.

Copy link
Member Author

@dtaylor113 dtaylor113 Feb 11, 2019

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.

Copy link
Member

@dlabrecq dlabrecq Feb 11, 2019

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?

Copy link
Contributor

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.

Copy link
Member

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

@coveralls
Copy link

coveralls commented Feb 11, 2019

Pull Request Test Coverage Report for Build 4449

  • 5 of 5 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.01%) to 80.361%

Totals Coverage Status
Change from base Build 4444: 0.01%
Covered Lines: 4704
Relevant Lines: 5498

💛 - Coveralls

Copy link
Contributor

@karelhala karelhala left a 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) {
Copy link
Contributor

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.

Copy link
Contributor

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
})

Copy link
Member Author

@dtaylor113 dtaylor113 Feb 11, 2019

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 :-)

Copy link
Member Author

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);
Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch!

@karelhala
Copy link
Contributor

This PR calls for new UX design as tri-state checkbo patternfly/patternfly#1411

@patternfly-build
Copy link
Contributor

PatternFly-React preview: https://1368-pr-patternfly-react-patternfly.surge.sh

@dtaylor113
Copy link
Member Author

This PR calls for new UX design as tri-state checkbo patternfly/patternfly-next#1411

I think that should be handled in a follow on PR

@dtaylor113
Copy link
Member Author

@karelhala and @dlabrecq, I believe this PR is ready, pls review when u get a moment -thanks

Copy link
Contributor

@karelhala karelhala left a comment

Choose a reason for hiding this comment

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

Looks really good!

@dlabrecq dlabrecq merged commit cca6dd7 into patternfly:master Feb 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants