-
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
Closed
Closed
refactor for v2 #147
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
a658267
refactor for v2
7d16e88
fix lint errors
bd7cfdf
fix noCascade and disable problem
a49f9f0
fix or temporarily disable tests to allow build
3dba178
fix scss and less to pass linter for build
e4d7084
Revert "fix scss and less ..." -broke travis, worked locally
460af8c
merge v1.6-dev
e41fab8
minor changes from review
a5e7b4b
fix radio/onlyLeafNode problem, add comments
53f0876
remove id from PropTypes to pass eslint in build
c6340fb
fix disabled status for radio nodes
7695036
fix comments
e108df5
Revert "fix comments - stuff included by mistake"
da8fcf2
fix comments
90e5125
first try
ab48b5d
remove duplicate logic
4f6ed9f
add useCheckedArray prop and fix examples
8deb130
Merge branch 'add_checkedArray' into v2.0-proposal
1e146e7
remove console statements
d3138f0
remove useCheckedArray from BasicExampleObject
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
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; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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?
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.
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
nodes
prop. In this case, the root node is the same type object as as each child node object. I can achieve the same result by passing the root node'schildren
array as you originally set it up.I have also allowed the
nodes
prop to be passed in as an array. It is then put into a generated root object so that the processing could be handled the same as when a root object is passed in as described above.One advantage of having the root object is that you can then add a prop,
showRoot
, to allow having a single node at the top of the tree. This allows you to collapse the tree to one line.By defaulting
showRoot
tofalse
you will have the same result as you originally provided. I have not yet added this prop but had intended to.The
showRoot
prop will fix some of the concerns in issue #143. WithshowRoot === true
and 'noCascade === falseyou do not need a 'checkAll
or 'unCheckAll`. Just check or uncheck the root.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.