Skip to content

Commit 38b10b1

Browse files
author
Fabian Nickel
committed
add node jd
1 parent 1d6ac39 commit 38b10b1

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

src/components/MuiTreeView/index.jsx

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Component } from 'react';
2+
<<<<<<< 1d6ac39c2109b8271f6e20f4ad9e6d87ade3a5ef
23
import {
34
arrayOf,
45
shape,
@@ -8,6 +9,9 @@ import {
89
oneOfType,
910
object,
1011
} from 'prop-types';
12+
=======
13+
import { arrayOf, shape, number, string, func, oneOfType, object } from 'prop-types';
14+
>>>>>>> add node jd
1115
import classNames from 'classnames';
1216
import { prop } from 'ramda';
1317
import memoize from 'fast-memoize';
@@ -23,8 +27,12 @@ const pickClassName = prop('className');
2327
const tree = {
2428
// The node value.
2529
value: string.isRequired,
30+
<<<<<<< 1d6ac39c2109b8271f6e20f4ad9e6d87ade3a5ef
2631
// Optional node ID. Useful for when the node value is not unique.
2732
id: oneOfType([string, number]),
33+
=======
34+
id: oneOfType[string, number],
35+
>>>>>>> add node jd
2836
};
2937

3038
Object.assign(tree, {
@@ -85,8 +93,8 @@ class MuiTreeView extends Component {
8593
expansionPanelDetailsProps: object,
8694
/** Properties applied to the ListItem element. */
8795
listItemProps: object,
88-
/** Value path for some leaf to highlight */
89-
highlightItem: arrayOf(string),
96+
/** Id of a leaf which will be highlighted by adding the class */
97+
highlightId: oneOfType[string, number],
9098
};
9199

92100
static defaultProps = {
@@ -95,7 +103,7 @@ class MuiTreeView extends Component {
95103
expansionPanelSummaryProps: null,
96104
expansionPanelDetailsProps: null,
97105
listItemProps: null,
98-
highlightItem: null,
106+
highlightId: null,
99107
};
100108

101109
createFilteredTree = memoize(
@@ -106,13 +114,17 @@ class MuiTreeView extends Component {
106114
}
107115
);
108116

117+
<<<<<<< 1d6ac39c2109b8271f6e20f4ad9e6d87ade3a5ef
109118
handleLeafClick = leaf => {
119+
=======
120+
handleLeafClick = (leaf) => {
121+
>>>>>>> add node jd
110122
if (this.props.onLeafClick) {
111123
this.props.onLeafClick(leaf);
112124
}
113125
};
114126

115-
renderNode = (node, parent, depth = 0, fullPath = []) => {
127+
renderNode = (node, parent, depth = 0) => {
116128
const {
117129
theme: {
118130
spacing: { unit },
@@ -123,7 +135,7 @@ class MuiTreeView extends Component {
123135
expansionPanelSummaryProps,
124136
expansionPanelDetailsProps,
125137
listItemProps,
126-
highlightItem,
138+
highlightId,
127139
...props
128140
} = this.props;
129141
const value = this.getNodeValue(node);
@@ -138,14 +150,6 @@ class MuiTreeView extends Component {
138150
}
139151

140152
if (isLeaf) {
141-
let isHighlighted = false;
142-
143-
if (highlightItem) {
144-
if (JSON.stringify(currentPath) === JSON.stringify(highlightItem)) {
145-
isHighlighted = true;
146-
}
147-
}
148-
149153
return (
150154
<ListItem
151155
disableGutters
@@ -155,7 +159,7 @@ class MuiTreeView extends Component {
155159
value={value}
156160
onClick={() => this.handleLeafClick({ value, parent, id })}
157161
button
158-
classes={isHighlighted ? { root: classes.highlightItem } : {}}
162+
classes={highlightId === id ? { root: classes.highlightItem } : {}}
159163
{...listItemProps}>
160164
<div className={classes.text}>{value}</div>
161165
</ListItem>
@@ -190,7 +194,7 @@ class MuiTreeView extends Component {
190194
classes={{ root: classes.panelDetails }}
191195
className={classNames(pickClassName(expansionPanelDetailsProps))}>
192196
{node.nodes.map(l =>
193-
this.renderNode(l, node, depth + 1, currentPath)
197+
this.renderNode(l, node, depth + 1)
194198
)}
195199
</ExpansionPanelDetails>
196200
</ExpansionPanel>

0 commit comments

Comments
 (0)