Skip to content
This repository was archived by the owner on Oct 18, 2018. It is now read-only.

Commit 0e0a492

Browse files
authored
Merge pull request #22 from hckhanh/core
Upgrade to v1.0.0-0
2 parents 3d67086 + 126b660 commit 0e0a492

File tree

7 files changed

+158
-66
lines changed

7 files changed

+158
-66
lines changed

.npmignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ npm-debug.log*
99
coverage
1010

1111
# tests
12-
__tests__
12+
test
1313

1414
# settings
1515
.vscode

CHANGELOG.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Change Log
2+
3+
## [v1.0.0](https://github.com/hckhanh/react-tree-es6/tree/v1.0.0)
4+
5+
[Full Changelog](https://github.com/hckhanh/react-tree-es6/compare/v0.1.2...v1.0.0)
6+
7+
**Implemented enhancements:**
8+
9+
- Add core property [\#20](https://github.com/hckhanh/react-tree-es6/issues/20)
10+
- Add Codecov service [\#15](https://github.com/hckhanh/react-tree-es6/issues/15)
11+
- Add test coverage \(\#15\) [\#19](https://github.com/hckhanh/react-tree-es6/pull/19) ([hckhanh](https://github.com/hckhanh))
12+
13+
## [v0.1.2](https://github.com/hckhanh/react-tree-es6/tree/v0.1.2) (2016-08-14)
14+
[Full Changelog](https://github.com/hckhanh/react-tree-es6/compare/v0.1.1...v0.1.2)
15+
16+
**Implemented enhancements:**
17+
18+
- Setup NPM for publishing [\#13](https://github.com/hckhanh/react-tree-es6/issues/13)
19+
- Remove css from ReactTree [\#12](https://github.com/hckhanh/react-tree-es6/issues/12)
20+
- Backward compatible to ES5 [\#11](https://github.com/hckhanh/react-tree-es6/issues/11)
21+
- Write tests for component [\#10](https://github.com/hckhanh/react-tree-es6/issues/10)
22+
- Create README file [\#5](https://github.com/hckhanh/react-tree-es6/issues/5)
23+
- Create onChanged event [\#3](https://github.com/hckhanh/react-tree-es6/issues/3)
24+
- Add JSON data to ReactTree [\#2](https://github.com/hckhanh/react-tree-es6/issues/2)
25+
- Add jstree plugin [\#1](https://github.com/hckhanh/react-tree-es6/issues/1)
26+
- Add README and update version to v0.1.0 [\#16](https://github.com/hckhanh/react-tree-es6/pull/16) ([hckhanh](https://github.com/hckhanh))
27+
- Add JsTree plugin [\#14](https://github.com/hckhanh/react-tree-es6/pull/14) ([hckhanh](https://github.com/hckhanh))
28+
29+
**Fixed bugs:**
30+
31+
- Fix Travis script to publish to NPM [\#18](https://github.com/hckhanh/react-tree-es6/pull/18) ([hckhanh](https://github.com/hckhanh))
32+
- Add email to Travis script [\#17](https://github.com/hckhanh/react-tree-es6/pull/17) ([hckhanh](https://github.com/hckhanh))
33+
34+
## [v0.1.1](https://github.com/hckhanh/react-tree-es6/tree/v0.1.1) (2016-08-14)
35+
[Full Changelog](https://github.com/hckhanh/react-tree-es6/compare/v0.1.0...v0.1.1)
36+
37+
## [v0.1.0](https://github.com/hckhanh/react-tree-es6/tree/v0.1.0) (2016-08-14)

README.md

Lines changed: 85 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ The wrapper of jsTree (jstree.com) for React
1010
## Getting Started
1111

1212
If you want to find a **tree view** component for React, this module is what you need.
13-
It supports **ES6** and backward compatible with **ES5**.
13+
**It supports ES6 and backward compatible with ES5.**
1414

1515
## Installation
1616

@@ -26,27 +26,33 @@ import/require `ReactTree` to your React source code:
2626
import ReactTree from 'react-tree-es6';
2727
```
2828

29-
### tree
29+
### core
3030

31-
**tree** is the node object or and array of node object. This is an example of data of a node:
31+
`core` is the jsTree object contains basic data and configurations of the tree.
32+
This is an example of `core` object:
3233

3334
```js
3435
{
35-
text: 'Root node 2',
36-
state: {
37-
opened: true,
38-
selected: true
39-
},
40-
children: [
36+
data: [ // data can be an array or object.
37+
'Simple root node',
4138
{
42-
text: 'Child 1'
43-
},
44-
'Child 2'
39+
text: 'Root node 2',
40+
state: {
41+
opened: true,
42+
selected: true
43+
},
44+
children: [
45+
{
46+
text: 'Child 1'
47+
},
48+
'Child 2'
49+
]
50+
}
4551
]
4652
}
4753
```
4854

49-
Here is the full structure of a node:
55+
As you know, a tree has one or many nodes, here is the full structure of a node:
5056

5157
```js
5258
// Alternative format of the node (id & parent are required)
@@ -65,54 +71,60 @@ Here is the full structure of a node:
6571
}
6672
```
6773

68-
You can define a tree and then parse it to `tree` property:
74+
You can define a `core` object and then parse it to `core` property:
6975

7076
```js
71-
const TREE = [
72-
'Simple root node',
73-
{
74-
text: 'Root node 2',
75-
state: {
76-
opened: true,
77-
selected: true
78-
},
79-
children: [
80-
{
81-
text: 'Child 1'
77+
const CORE = {
78+
data: [
79+
'Simple root node',
80+
{
81+
text: 'Root node 2',
82+
state: {
83+
opened: true,
84+
selected: true
8285
},
83-
'Child 2'
84-
]
85-
}
86-
];
86+
children: [
87+
{
88+
text: 'Child 1'
89+
},
90+
'Child 2'
91+
]
92+
}
93+
]
94+
};
8795

8896
class ExampleApp extends React.Component {
8997
render() {
90-
return (<ReactTree tree={TREE} />);
98+
return (<ReactTree core={CORE} />);
9199
}
92100
}
93101
```
94102

103+
> To make sure you can find what you need, go to [jsTree API](https://www.jstree.com/api) for more details.
104+
95105
### onChanged
96106

97107
This is an event to handle when a node is clicked:
98108

99109
```js
100-
const TREE = [
101-
'Simple root node',
102-
{
103-
text: 'Root node 2',
104-
state: {
105-
opened: true,
106-
selected: true
107-
},
108-
children: [
109-
{
110-
text: 'Child 1'
110+
const CORE = {
111+
data: [
112+
'Simple root node',
113+
{
114+
text: 'Root node 2',
115+
state: {
116+
opened: true,
117+
selected: true
111118
},
112-
'Child 2'
113-
]
114-
}
115-
];
119+
children: [
120+
{
121+
text: 'Child 1'
122+
},
123+
'Child 2'
124+
]
125+
}
126+
]
127+
};
116128

117129
class ExampleApp extends React.Component {
118130
constructor(props) {
@@ -132,7 +144,7 @@ class ExampleApp extends React.Component {
132144
render() {
133145
return (
134146
<div>
135-
<ReactTree tree={TREE} onChanged={this.handleOnChanged} />
147+
<ReactTree core={CORE} onChanged={this.handleOnChanged} />
136148
<div>Selected items: {this.state.items}</div>
137149
</div>
138150
);
@@ -144,11 +156,37 @@ If you need detailed example, go to [example](example) folder.
144156

145157
### Themes
146158

147-
If user want to apply css for **ReactTree**, consider to include these files:
159+
If user want to apply css for **ReactTree**, consider to include these files to your web app:
148160

149161
* node_modules/jstree/dist/themes/default/style.min.css
150162
* node_modules/jstree/dist/themes/default-dark/style.min.css
151163

164+
with additional options in `core` object, for instance with **default-dark** theme:
165+
166+
```js
167+
const CORE = {
168+
data: [
169+
'Simple root node',
170+
{
171+
text: 'Root node 2',
172+
state: {
173+
opened: true,
174+
selected: true
175+
},
176+
children: [
177+
{
178+
text: 'Child 1'
179+
},
180+
'Child 2'
181+
]
182+
}
183+
],
184+
themes: {
185+
name: 'default-dark'
186+
}
187+
};
188+
```
189+
152190
## License
153191

154192
MIT (<http://www.opensource.org/licenses/mit-license.php>)

example/app.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import ReactDOM from 'react-dom';
55
import ReactTree from '../src/react-tree';
66
import { PROJECT_TREE } from './project-tree';
77

8+
const CORE_DATA = {
9+
data: PROJECT_TREE
10+
};
11+
812
class ExampleApp extends React.Component {
913
constructor(props) {
1014
super(props);
@@ -23,7 +27,7 @@ class ExampleApp extends React.Component {
2327
render() {
2428
return (
2529
<div>
26-
<ReactTree tree={PROJECT_TREE} onChanged={this.handleOnChanged} />
30+
<ReactTree core={CORE_DATA} onChanged={this.handleOnChanged} />
2731
<div>Selected items: {this.state.items}</div>
2832
</div>
2933
);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-tree-es6",
3-
"version": "0.1.2",
3+
"version": "1.0.0-0",
44
"description": "The wrapper of jsTree (jstree.com) for React",
55
"main": "./lib/react-tree.js",
66
"scripts": {

src/react-tree.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ export default class ReactTree extends React.Component {
1414
}
1515
})
1616
.jstree({
17-
core: {
18-
data: this.props.tree
19-
}
17+
core: this.props.core
2018
});
2119
}
2220

@@ -26,9 +24,13 @@ export default class ReactTree extends React.Component {
2624
}
2725

2826
ReactTree.propTypes = {
29-
tree: function (props, propName, componentName) {
30-
const prop = props[propName];
31-
if (!Array.isArray(prop) && typeof (prop) !== 'object')
32-
return new TypeError(`Invalid prop \`tree\`: tree must be an object or array`)
27+
core: function (props, propName, componentName) {
28+
const core = props[propName];
29+
if (!core || typeof (core) !== 'object')
30+
return new TypeError(`Invalid prop \`core\`: must follow jsTree API, read more https://www.jstree.com/api/#/?q=core`);
31+
32+
const data = core.data;
33+
if (!Array.isArray(data) && typeof (data) !== 'object')
34+
throw new TypeError(`Invalid object \`core.data\`: must be array of object of jsTree JSON data, read more https://www.jstree.com/docs/json`);
3335
}
3436
};

test/react-tree-test.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,46 @@ import React from 'react';
22
import ReactDOM from 'react-dom';
33
import TestUtils from 'react-addons-test-utils';
44
import ReactTree from '../src/react-tree';
5-
import { PROJECT_TREE } from '../example/project-tree'
5+
import { PROJECT_TREE } from '../example/project-tree';
6+
7+
const CORE_DATA = {
8+
data: PROJECT_TREE
9+
};
610

711
describe('ReactTree', () => {
812
it('should run be rendered', () => {
913
const reactTree = TestUtils.renderIntoDocument(
10-
<ReactTree tree={PROJECT_TREE} />
14+
<ReactTree core={CORE_DATA} />
1115
);
1216

1317
const reactTreeNode = ReactDOM.findDOMNode(reactTree);
1418

1519
expect(reactTreeNode.textContent).not.toBeNull();
16-
1720
});
1821

1922
it('should run the handle function of onChanged event', () => {
2023
const handleOnChanged = jest.fn();
2124

2225
const reactTree = TestUtils.renderIntoDocument(
23-
<ReactTree tree={PROJECT_TREE} onChanged={handleOnChanged} />
26+
<ReactTree core={CORE_DATA} onChanged={handleOnChanged} />
2427
);
2528

2629
expect(handleOnChanged).toBeCalled();
2730
});
2831

29-
it('should show error when tree is not object or array', () => {
30-
const reactTree = TestUtils.renderIntoDocument(
31-
<ReactTree tree={1} />
32-
);
32+
it('should throw TypeError when "core" prop is not valid', () => {
33+
const renderReactTree = () => {
34+
TestUtils.renderIntoDocument(<ReactTree core={1} />);
35+
};
36+
37+
expect(renderReactTree).toThrowError(TypeError);
38+
});
39+
40+
it('should validation of "core" prop is defined', () => {
41+
const ERROR_CORE = { data: 1 };
42+
43+
TestUtils.renderIntoDocument(<ReactTree core={ERROR_CORE} />);
3344

34-
expect(ReactTree.propTypes.tree).toBeDefined();
45+
expect(ReactTree.propTypes.core).toBeDefined();
3546
});
3647
});

0 commit comments

Comments
 (0)