Skip to content

Commit df3ec94

Browse files
committed
reformatted tree with labels and added props validation
1 parent 14dc3ca commit df3ec94

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

src/app/components/Tree.jsx

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
import React from 'react';
22
import JSONTree from 'react-json-tree';
3+
import PropTypes from 'prop-types';
34

45
const getItemString = (type, data, itemType, itemString) => (
56
<span>
6-
{/* //
7-
{type} */}
7+
{data.name}
88
</span>
99
);
1010

1111
const Tree = (props) => {
1212
const { snapshot } = props;
13-
console.log('TREE COMPONENT IS PRINTED');
14-
console.log(snapshot);
1513
return (
1614
<React.Fragment>
1715
{snapshot && (
@@ -20,11 +18,26 @@ const Tree = (props) => {
2018
theme={{ tree: () => ({ className: 'json-tree' }) }}
2119
shouldExpandNode={() => true}
2220
getItemString={getItemString}
23-
// labelRenderer={raw => <strong>{raw}</strong>}
24-
// valueRenderer={raw => <em>{raw}</em>}
21+
labelRenderer={(raw) => {
22+
if (typeof raw[0] !== 'number') return <span>{raw[0]}</span>;
23+
}}
2524
/>
2625
)}
2726
</React.Fragment>
2827
);
2928
};
29+
30+
Tree.propTypes = {
31+
snapshot: PropTypes.shape({
32+
state: PropTypes.oneOfType([
33+
PropTypes.string,
34+
PropTypes.object,
35+
]),
36+
children: PropTypes.arrayOf(
37+
PropTypes.object,
38+
),
39+
name: PropTypes.string,
40+
}).isRequired,
41+
};
42+
3043
export default Tree;

src/app/containers/TravelContainer.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const TravelContainer = ({
1515
}) => (
1616
<div className="travel-container">
1717
<div className="play-button" onClick={play}>
18-
{ playing ? 'Pause': 'Play' }
18+
{playing ? 'Pause' : 'Play'}
1919
</div>
2020
<MainSlider
2121
snapshotLength={snapshotsLength}
@@ -34,13 +34,14 @@ const TravelContainer = ({
3434
);
3535

3636
TravelContainer.propTypes = {
37-
pause: PropTypes.func.isRequried,
37+
pause: PropTypes.func.isRequired,
3838
play: PropTypes.func.isRequired,
3939
moveBackward: PropTypes.func.isRequired,
4040
moveForward: PropTypes.func.isRequired,
4141
snapshotsLength: PropTypes.number.isRequired,
4242
handleChangeSnapshot: PropTypes.func.isRequired,
4343
handleJumpSnapshot: PropTypes.func.isRequired,
4444
snapshotIndex: PropTypes.number.isRequired,
45+
playing: PropTypes.bool.isRequired,
4546
};
4647
export default TravelContainer;

0 commit comments

Comments
 (0)