Skip to content

Commit fb5dcdc

Browse files
committed
Issue #8 : Fix deep for objects and arrays
1 parent 034db00 commit fb5dcdc

File tree

5 files changed

+7465
-15
lines changed

5 files changed

+7465
-15
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"html-loader": "^0.4.4",
4848
"html-webpack-plugin": "^2.24.1",
4949
"lodash": "^4.17.2",
50-
"node-sass": "^4.6.0",
50+
"node-sass": "^4.9.3",
5151
"postcss-loader": "^1.1.1",
5252
"prop-types": "^15.6.0",
5353
"react": "^16.0.0",

src/JsonTree.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const propTypes = {
5353
// Default props
5454
const defaultProps = {
5555
rootName: 'root',
56-
isCollapsed: (keyPath, deep) => (deep !== 0),
56+
isCollapsed: (keyPath, deep) => (deep !== -1),
5757
getStyle: (keyName, data, keyPath, deep, dataType) => {
5858
switch (dataType) {
5959
case 'Object':

src/components/JsonArray.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,12 @@ class JsonArray extends Component {
6060
...props.keyPath,
6161
props.name,
6262
];
63-
const deep = props.deep + 1;
6463
this.state = {
6564
data: props.data,
6665
name: props.name,
6766
keyPath,
68-
deep,
69-
collapsed: props.isCollapsed(keyPath, deep, props.data),
67+
deep: props.deep,
68+
collapsed: props.isCollapsed(keyPath, props.deep, props.data),
7069
addFormVisible: false,
7170
};
7271

@@ -234,7 +233,7 @@ class JsonArray extends Component {
234233
className: 'rejt-minus-menu',
235234
style: minus,
236235
});
237-
minusElement = (deep !== 0) ? minusMenuLayout : null;
236+
minusElement = (deep !== -1) ? minusMenuLayout : null;
238237
}
239238

240239
const itemName = (numberOfItems > 1) ? 'items' : 'item';
@@ -282,7 +281,7 @@ class JsonArray extends Component {
282281
className: 'rejt-minus-menu',
283282
style: minus,
284283
});
285-
minusElement = (deep !== 0) ? minusMenuLayout : null;
284+
minusElement = (deep !== -1) ? minusMenuLayout : null;
286285
}
287286

288287
const list = data
@@ -291,7 +290,7 @@ class JsonArray extends Component {
291290
name={`${index}`}
292291
data={item}
293292
keyPath={keyPath}
294-
deep={deep}
293+
deep={deep + 1}
295294
isCollapsed={isCollapsed}
296295
handleRemove={this.handleRemoveItem(index)}
297296
handleUpdateValue={this.handleEditValue}

src/components/JsonObject.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,16 @@ const defaultProps = {
5656
class JsonObject extends Component {
5757
constructor(props) {
5858
super(props);
59-
const deep = props.deep + 1;
60-
const keyPath = (deep === 0) ? [] : [
59+
const keyPath = (props.deep === -1) ? [] : [
6160
...props.keyPath,
6261
props.name,
6362
];
6463
this.state = {
6564
name: props.name,
6665
data: props.data,
6766
keyPath,
68-
deep,
69-
collapsed: props.isCollapsed(keyPath, deep, props.data),
67+
deep: props.deep,
68+
collapsed: props.isCollapsed(keyPath, props.deep, props.data),
7069
addFormVisible: false,
7170
};
7271

@@ -232,7 +231,7 @@ class JsonObject extends Component {
232231
className: 'rejt-minus-menu',
233232
style: minus,
234233
});
235-
minusElement = (deep !== 0) ? minusMenuLayout : null;
234+
minusElement = (deep !== -1) ? minusMenuLayout : null;
236235
}
237236

238237
/* eslint-disable jsx-a11y/no-static-element-interactions */
@@ -279,7 +278,7 @@ class JsonObject extends Component {
279278
className: 'rejt-minus-menu',
280279
style: minus,
281280
});
282-
minusElement = (deep !== 0) ? minusMenuLayout : null;
281+
minusElement = (deep !== -1) ? minusMenuLayout : null;
283282
}
284283

285284
const list = keyList
@@ -288,7 +287,7 @@ class JsonObject extends Component {
288287
name={key}
289288
data={data[key]}
290289
keyPath={keyPath}
291-
deep={deep}
290+
deep={deep + 1}
292291
isCollapsed={isCollapsed}
293292
handleRemove={this.handleRemoveValue(key)}
294293
handleUpdateValue={this.handleEditValue}

0 commit comments

Comments
 (0)