Skip to content

Commit b60cce8

Browse files
committed
refactor(table): use array.includes instead of indexOf
affects: @crave/farmblocks-table
1 parent d968410 commit b60cce8

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

packages/table/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ See the stories source code for more usage examples.
4343
This package assumes that the application using it uses a font icon that have a
4444
checkmark symbol, and that the class name to include that icon is `.wg-check`.
4545

46+
### Required Polyfills
47+
48+
This package assumes it will run on an enviroment that has support for Array.includes and Object.keys, if you need to support IE and other older browsers, make sure you have those polyfills in place.
49+
4650
## Properties
4751

4852
The Table component can be used for showing data grids using text cells in like the simple example above, but it also supports

packages/table/src/Table.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class Table extends React.Component {
7171
borderless
7272
};
7373
const selectedData = Object.keys(this.state.rowsMap)
74-
.filter(key => this.state.selectedRows.indexOf(key) !== -1)
74+
.filter(key => this.state.selectedRows.includes(key))
7575
.map(key => this.state.rowsMap[key]);
7676
const clearFunction = () =>
7777
this.selectAllToggle(false, this.state.selectedRows.length);
@@ -125,7 +125,7 @@ class Table extends React.Component {
125125
) => {
126126
const { selectableRows, collapsed, children } = this.props;
127127
const rowKey = `${index},${subIndex}`;
128-
const selected = this.state.selectedRows.indexOf(rowKey) !== -1;
128+
const selected = this.state.selectedRows.includes(rowKey);
129129
const grouped = typeof subIndex === "number" && !flattened;
130130
const rowProps = { selected, grouped };
131131
return (
@@ -157,7 +157,7 @@ class Table extends React.Component {
157157
const expanded =
158158
shouldUngroup ||
159159
!this.props.collapsed ||
160-
this.state.expandedRows.indexOf(index) !== -1;
160+
this.state.expandedRows.includes(index);
161161
return (
162162
<tbody className={`body ${!expanded ? "collapsed" : ""}`} key={index}>
163163
{!shouldUngroup && this._renderRow(parentRow, index, "", true)}
@@ -169,10 +169,9 @@ class Table extends React.Component {
169169
};
170170

171171
_renderExpandToggle = index => {
172-
const icon =
173-
this.state.expandedRows.indexOf(index) !== -1
174-
? "wg-small-arrow-top"
175-
: "wg-small-arrow-bottom";
172+
const icon = this.state.expandedRows.includes(index)
173+
? "wg-small-arrow-top"
174+
: "wg-small-arrow-bottom";
176175
return (
177176
<Button icon={icon} onClick={() => this.expandToggleClicked(index)} />
178177
);

0 commit comments

Comments
 (0)