Skip to content

Commit

Permalink
PF4 Table: Check All updates
Browse files Browse the repository at this point in the history
  • Loading branch information
dtaylor113 committed Feb 11, 2019
1 parent 02ffb73 commit 39bdd0f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
25 changes: 24 additions & 1 deletion packages/patternfly-4/react-table/src/components/Table/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,29 @@ class Table extends React.Component {
constructor(props) {
super(props);
this.state = {
headerData: []
headerData: [],
allRowsSelected: props.onSelect ? this.areAllRowsSelected(props.rows) : false
};
this.isSelected = this.isSelected.bind(this);
this.areAllRowsSelected = this.areAllRowsSelected.bind(this);
}

componentDidUpdate(prevProps) {
if (this.props.rows !== prevProps.rows) {
this.setState({
allRowsSelected: this.props.onSelect ? this.areAllRowsSelected(this.props.rows) : false
});
}
}

isSelected(row) {
return row.selected === true;
}

areAllRowsSelected(rows) {
return rows.every(this.isSelected);
}

render() {
const {
caption,
Expand All @@ -165,10 +185,13 @@ class Table extends React.Component {
...props
} = this.props;

const { allRowsSelected } = this.state;

const headerData = calculateColumns(cells, {
sortBy,
onSort,
onSelect,
allRowsSelected,
actions,
onCollapse,
rowLabeledBy,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from 'react';
import { Table, TableHeader, TableBody, headerCol } from '@patternfly/react-table';
import { Table, TableHeader, TableBody } from '@patternfly/react-table';

class SelectableTable extends React.Component {
constructor(props) {
super(props)
this.state = {
columns: [
{ title: 'Repositories', cellTransforms: [headerCol()] },
{ title: 'Repositories' },
'Branches',
{ title: 'Pull requests' },
'Workspaces',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default (
label,
{
column: {
extraParams: { onSelect, rowLabeledBy = 'simple-node' }
extraParams: { onSelect, allRowsSelected, rowLabeledBy = 'simple-node' }
},
rowIndex,
rowData
Expand All @@ -21,9 +21,10 @@ export default (
};
}
const rowId = rowIndex !== undefined ? rowIndex : -1;

function selectClick(event) {
const selected = rowIndex === undefined ? event.target.checked : rowData && !rowData.selected;
onSelect && onSelect(selected, selected, rowId);
onSelect && onSelect(event, selected, rowId);
}
const customProps = {
...(rowId !== -1
Expand All @@ -32,6 +33,7 @@ export default (
'aria-labelledby': rowLabeledBy + rowIndex
}
: {
checked: allRowsSelected,
'aria-label': 'Select all rows'
})
};
Expand Down

0 comments on commit 39bdd0f

Please sign in to comment.