Skip to content

Commit 991d2ca

Browse files
committed
Clean up code and appease the linter
1 parent f41023a commit 991d2ca

File tree

6 files changed

+20
-22
lines changed

6 files changed

+20
-22
lines changed

src/examples/basicExample/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ class App extends Component {
197197
treeData={this.state.treeData}
198198
updateTreeData={this.updateTreeData}
199199
maxDepth={5}
200-
generateNodeProps={(rowInfo) => ({
200+
generateNodeProps={rowInfo => ({
201201
buttons: [
202202
<button
203203
style={{

src/node-renderer-default.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ NodeRendererDefault.propTypes = {
139139
node: PropTypes.object.isRequired,
140140
path: PropTypes.arrayOf(PropTypes.oneOfType([ PropTypes.string, PropTypes.number ])).isRequired,
141141
treeIndex: PropTypes.number.isRequired,
142-
lowerSiblingCounts: PropTypes.arrayOf(PropTypes.number).isRequired,
143142

144143
scaffoldBlockPxWidth: PropTypes.number.isRequired,
145144
toggleChildrenVisibility: PropTypes.func,

src/react-sortable-tree.js

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ import {
1616
insertNode,
1717
getDescendantCount,
1818
} from './utils/tree-data-utils';
19+
import {
20+
swapRows,
21+
} from './utils/generic-utils';
1922
import {
2023
defaultGetNodeKey,
2124
defaultToggleChildrenVisibility,
@@ -89,19 +92,6 @@ class ReactSortableTree extends Component {
8992
});
9093
}
9194

92-
swapRows(rows, fromIndex, toIndex, count = 1) {
93-
const rowsWithoutMoved = [
94-
...rows.slice(0, fromIndex),
95-
...rows.slice(fromIndex + count),
96-
];
97-
98-
return [
99-
...rowsWithoutMoved.slice(0, toIndex),
100-
...rows.slice(fromIndex, fromIndex + count),
101-
...rowsWithoutMoved.slice(toIndex),
102-
];
103-
}
104-
10595
startDrag({ path }) {
10696
const draggingTreeData = removeNodeAtPath({
10797
treeData: this.props.treeData,
@@ -126,7 +116,7 @@ class ReactSortableTree extends Component {
126116
const rows = this.getRows(addedResult.treeData);
127117
const expandedParentPath = rows[addedResult.treeIndex].path;
128118
this.setState({
129-
rows: this.swapRows(
119+
rows: swapRows(
130120
rows,
131121
addedResult.treeIndex,
132122
minimumTreeIndex,
@@ -254,7 +244,6 @@ class ReactSortableTree extends Component {
254244
<NodeContentRenderer
255245
node={node}
256246
path={path}
257-
lowerSiblingCounts={lowerSiblingCounts}
258247
treeIndex={treeIndex}
259248
startDrag={this.startDrag}
260249
endDrag={this.endDrag}
@@ -268,8 +257,7 @@ class ReactSortableTree extends Component {
268257
}
269258

270259
ReactSortableTree.propTypes = {
271-
treeData: PropTypes.arrayOf(PropTypes.object).isRequired,
272-
changeData: PropTypes.func,
260+
treeData: PropTypes.arrayOf(PropTypes.object).isRequired,
273261

274262
// Callback for move operation.
275263
// Called as moveNode({ node, path, parentPath, minimumTreeIndex })
@@ -295,7 +283,6 @@ ReactSortableTree.propTypes = {
295283
getNodeKey: PropTypes.func,
296284
updateTreeData: PropTypes.func,
297285
toggleChildrenVisibility: PropTypes.func,
298-
loadCollapsedLazyChildren: PropTypes.bool,
299286
};
300287

301288
ReactSortableTree.defaultProps = {

src/utils/generic-utils.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export function swapRows(rows, fromIndex, toIndex, count = 1) {
2+
const rowsWithoutMoved = [
3+
...rows.slice(0, fromIndex),
4+
...rows.slice(fromIndex + count),
5+
];
6+
7+
return [
8+
...rowsWithoutMoved.slice(0, toIndex),
9+
...rows.slice(fromIndex, fromIndex + count),
10+
...rowsWithoutMoved.slice(toIndex),
11+
];
12+
}

src/utils/tree-data-utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ export function getTreeFromFlatData({
760760
}
761761

762762
const childrenToParents = {};
763-
flatData.forEach(child => {
763+
flatData.forEach((child) => {
764764
const parentKey = getParentKey(child);
765765

766766
if (parentKey in childrenToParents) {

src/utils/tree-data-utils.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1317,7 +1317,7 @@ describe('insertNode', () => {
13171317

13181318
describe('walk', () => {
13191319
it('should handle empty data', () => {
1320-
[[], null, undefined].forEach(treeData => {
1320+
[[], null, undefined].forEach((treeData) => {
13211321
expect(() => walk({
13221322
treeData,
13231323
getNodeKey: keyFromTreeIndex,

0 commit comments

Comments
 (0)