-
Notifications
You must be signed in to change notification settings - Fork 217
refactor for v2 #147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor for v2 #147
Changes from 6 commits
a658267
7d16e88
bd7cfdf
a49f9f0
3dba178
e4d7084
460af8c
e41fab8
a5e7b4b
53f0876
c6340fb
7695036
e108df5
da8fcf2
90e5125
ab48b5d
4f6ed9f
8deb130
1e146e7
d3138f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,25 @@ | ||
| import React from 'react'; | ||
| import CheckboxTree from 'react-checkbox-tree'; | ||
|
|
||
| const nodes = [ | ||
| const initialNodes = [ | ||
| { | ||
| value: '/app', | ||
| label: 'app', | ||
| expanded: true, | ||
| children: [ | ||
| { | ||
| value: '/app/Http', | ||
| label: 'Http', | ||
| expanded: true, | ||
| children: [ | ||
| { | ||
| value: '/app/Http/Controllers', | ||
| label: 'Controllers', | ||
| expanded: true, | ||
| children: [{ | ||
| value: '/app/Http/Controllers/WelcomeController.js', | ||
| label: 'WelcomeController.js', | ||
| checked: true, | ||
| }], | ||
| }, | ||
| { | ||
|
|
@@ -34,6 +38,55 @@ const nodes = [ | |
| }, | ||
| ], | ||
| }, | ||
| { | ||
| value: '/radioGroup', | ||
| label: 'RadioTest', | ||
| expanded: true, | ||
| radioGroup: true, | ||
| children: [ | ||
| { | ||
| value: 'radio1', | ||
| label: 'radio1', | ||
| }, | ||
| { | ||
| value: 'radio2', | ||
| label: 'radio2', | ||
| children: [ | ||
| { | ||
| value: 'radio2-1', | ||
| label: 'radio2', | ||
| }, | ||
| { | ||
| value: 'radio2-2', | ||
| label: 'radio2-2', | ||
| }, | ||
| { | ||
| value: 'radio2-3', | ||
| label: 'radio2-3', | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| value: 'radio3', | ||
| label: 'radio3', | ||
| radioGroup: true, | ||
| children: [ | ||
| { | ||
| value: 'radio3-1', | ||
| label: 'radio3', | ||
| }, | ||
| { | ||
| value: 'radio3-2', | ||
| label: 'radio3-2', | ||
| }, | ||
| { | ||
| value: 'radio3-3', | ||
| label: 'radio3-3', | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| value: '/config', | ||
| label: 'config', | ||
|
|
@@ -82,40 +135,24 @@ const nodes = [ | |
|
|
||
| class BasicExample extends React.Component { | ||
| state = { | ||
| checked: [ | ||
| '/app/Http/Controllers/WelcomeController.js', | ||
| '/app/Http/routes.js', | ||
| '/public/assets/style.css', | ||
| '/public/index.html', | ||
| '/.gitignore', | ||
| ], | ||
| expanded: [ | ||
| '/app', | ||
| ], | ||
| nodes: initialNodes, | ||
| }; | ||
|
|
||
| constructor(props) { | ||
| super(props); | ||
|
|
||
| this.onCheck = this.onCheck.bind(this); | ||
| this.onExpand = this.onExpand.bind(this); | ||
| } | ||
|
|
||
| onCheck(checked) { | ||
| this.setState({ checked }); | ||
| onCheck = (node, nodes) => { | ||
| this.setState({ nodes }); | ||
| } | ||
|
|
||
| onExpand(expanded) { | ||
| this.setState({ expanded }); | ||
| onExpand = (node, nodes) => { | ||
| this.setState({ nodes }); | ||
| } | ||
|
|
||
| render() { | ||
| const { checked, expanded } = this.state; | ||
| const { nodes } = this.state; | ||
|
|
||
| return ( | ||
| <CheckboxTree | ||
| checked={checked} | ||
| expanded={expanded} | ||
| style={{ flex: '1' }} | ||
|
||
| checkModel="all" | ||
| iconsClass="fa5" | ||
| nodes={nodes} | ||
| onCheck={this.onCheck} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,170 @@ | ||
| import React from 'react'; | ||
| import CheckboxTree from 'react-checkbox-tree'; | ||
|
|
||
| const initialNodes = { | ||
| label: 'Root', | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not see the point in supporting a base object file. It makes the internals slightly more complicated and it is not too much to ask for the user just to have a top-level array. Also, it does not seem like this is actually doing much?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is something I put in based upon my use and something I read in one of the issues somewhere. I will state my reasoning here and you can decide the path forward as this is your component. In my use I may have several JSON configuration files which are used for input to the CheckTree. Each has a root node with a description of that tree. The User logs in and can choose from the configurations available to them. My current proposal allows passing this root node object in as the I have also allowed the One advantage of having the root object is that you can then add a prop, By defaulting The That is my case for adding the capability to input a root node. I have kept the ability to input an array of nodes for compatibility with previous versions. I can set it up with only the root node option, only the array of nodes option or both. You choose. |
||
| value: '*root*', | ||
| expanded: true, | ||
| children: [ | ||
| { | ||
| value: '/app', | ||
| label: 'app', | ||
| expanded: true, | ||
| children: [ | ||
| { | ||
| value: '/app/Http', | ||
| label: 'Http', | ||
| expanded: true, | ||
| children: [ | ||
| { | ||
| value: '/app/Http/Controllers', | ||
| label: 'Controllers', | ||
| expanded: true, | ||
| children: [{ | ||
| value: '/app/Http/Controllers/WelcomeController.js', | ||
| label: 'WelcomeController.js', | ||
| checked: true, | ||
| }], | ||
| }, | ||
| { | ||
| value: '/app/Http/routes.js', | ||
| label: 'routes.js', | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| value: '/app/Providers', | ||
| label: 'Providers', | ||
| children: [{ | ||
| value: '/app/Providers/EventServiceProvider.js', | ||
| label: 'EventServiceProvider.js', | ||
| }], | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| value: '/radioGroup', | ||
| label: 'RadioTest', | ||
| expanded: true, | ||
| radioGroup: true, | ||
| children: [ | ||
| { | ||
| value: 'radio1', | ||
| label: 'radio1', | ||
| }, | ||
| { | ||
| value: 'radio2', | ||
| label: 'radio2', | ||
| children: [ | ||
| { | ||
| value: 'radio2-1', | ||
| label: 'radio2', | ||
| }, | ||
| { | ||
| value: 'radio2-2', | ||
| label: 'radio2-2', | ||
| }, | ||
| { | ||
| value: 'radio2-3', | ||
| label: 'radio2-3', | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| value: 'radio3', | ||
| label: 'radio3', | ||
| radioGroup: true, | ||
| children: [ | ||
| { | ||
| value: 'radio3-1', | ||
| label: 'radio3', | ||
| }, | ||
| { | ||
| value: 'radio3-2', | ||
| label: 'radio3-2', | ||
| }, | ||
| { | ||
| value: 'radio3-3', | ||
| label: 'radio3-3', | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| value: '/config', | ||
| label: 'config', | ||
| children: [ | ||
| { | ||
| value: '/config/app.js', | ||
| label: 'app.js', | ||
| }, | ||
| { | ||
| value: '/config/database.js', | ||
| label: 'database.js', | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| value: '/public', | ||
| label: 'public', | ||
| children: [ | ||
| { | ||
| value: '/public/assets/', | ||
| label: 'assets', | ||
| children: [{ | ||
| value: '/public/assets/style.css', | ||
| label: 'style.css', | ||
| }], | ||
| }, | ||
| { | ||
| value: '/public/index.html', | ||
| label: 'index.html', | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| value: '/.env', | ||
| label: '.env', | ||
| }, | ||
| { | ||
| value: '/.gitignore', | ||
| label: '.gitignore', | ||
| }, | ||
| { | ||
| value: '/README.md', | ||
| label: 'README.md', | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| class BasicExampleObject extends React.Component { | ||
| state = { | ||
| nodes: initialNodes, | ||
| }; | ||
|
|
||
| onCheck = (node, nodes) => { | ||
| this.setState({ nodes }); | ||
| } | ||
|
|
||
| onExpand = (node, nodes) => { | ||
| this.setState({ nodes }); | ||
| } | ||
|
|
||
| render() { | ||
| const { nodes } = this.state; | ||
|
|
||
| return ( | ||
| <CheckboxTree | ||
| style={{ flex: '1' }} | ||
| checkModel="all" | ||
| iconsClass="fa5" | ||
| nodes={nodes} | ||
| onCheck={this.onCheck} | ||
| onExpand={this.onExpand} | ||
| /> | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| export default BasicExampleObject; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any assignment operator should be terminated by a semicolon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will fix these. They are not caught by eslint.