-
Notifications
You must be signed in to change notification settings - Fork 214
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
v2 restructure using TreeModel to hold state #424
base: v2.0-dev
Are you sure you want to change the base?
Conversation
convert ClickableLabelsExample add place holder for Show Root Example update CustomIconsExample update and fix DisabledExample update NoCascadeExample update PessimisticToggleExample update HiddenCheckboxesExample update LargeDataExample update ExpandAllExample and fix errors updated FilterExample and fixed TreeModel(onCheck and onExpand) add ShowRootExample simplify TreeModel work on FilterExample replace 'newTreeModel' with 'newTree' move models into models dir change onCollapse & onExpand to use nodeKey add ExpandNodesToLevel and redo getChecked add radio buttons change to context for state add radio button for nativeCheckboxes
Utils have been moved to public methods of TreeModel. |
Custom Label Example was added in the last commit along with the changes needed for it to work. This is something I have needed in a project of mine. I think I have it working with reasonable props to make it work. |
work on tests work on docs and code to match fix tests and examples
@jakezatecky This last commit gets this pull request in pretty good shape. I've been down lots of rabbit holes and tried many options some of which turned out to be illogical. I feel good with the results so far.
I have a version of this running in production now. So far so good. :) I think the best way to start understanding the changes is to look at all of the examples. Here are a few hints:
Please let me know what questions, comments or criticisms you have when you find some time to review it. |
Thank you very much for your continued work on this. I admit and apologize that I have been sorely lacking in providing commentary over the last several weeks. I intend to give the most recent changes a good review within the next few days. |
src/js/CheckboxTree.jsx
Outdated
|
||
{name !== undefined ? ( | ||
<HiddenInput | ||
checked={treeModel.getCheckedArray()} |
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.
getCheckedArray
does not appear to be a method of TreeModel
.
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.
fixed : fix incorrect method
a27a085
|
||
toggleChecked(nodeKey) { | ||
const { noCascadeChecks, optimisticToggle } = this.options; | ||
const node = this.getNode(nodeKey); |
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.
Since we are already calling getNode
, it would be cleaner for the user if node
gets returned to their onCheck
rather than having them call newTree.getNode(nodeKey)
again. See main review comment for more details.
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.
That is a reasonable request. I think I may have been worried about a node being in a closure and returning a stale node to the event handlers.
Hello @worthlutz . Thanks for all the effort you have put into this PR! I really appreciate your work and tolerance for my less than timely responses. I finally spent some time to review many of the changes. I find your approach interesting. Although a breaking change, I love merging However, I do have some general items of discussion after reviewing many of the changes. The main discussion surrounds the context/provider.
const [tree, setTree] = useState(nodes);
// Legacy methods
const onCheck = (node, tree) => {
console.log(node, tree.getChecked());
};
const onExpand = (node, tree) => {
console.log(node, tree.getExpanded());
};
// Main state method
const onChange = (tree) => {
setTree(tree);
};
return <CheckboxTree tree={tree} onChange={onChange} onCheck={onCheck} onExpand={onExpand} />;
I really like the idea of relying more on a
|
hI @jakezatecky. I've been on vacation and had some other issues to deal with thus my slow response. Thanks for your comments. I will digest them more this week and come back with some more thoughtful answers and reasoning than I can do quickly today. I think your ideas are good and I had many of the same ideas as I tried one thing and then another. Eventually what I ended up with just evolved out of the process of trial and error. Now that it is working, changes will be easier to make. |
hi @jakezatecky. I can get rid of the context used to save state and make the component a controlled component. This will remove the unneeded complexity I somehow decided was needed. The input prop will be a All state is contained in the I have not looked at returning the node instead of the key yet. More comments to follow as I review more.
I have made the code changes and have this working in all the examples but have to do some more work on the tests to fix them. I will also need to work on the documentation to reflect these changes. |
Hi @jakezatecky. The latest commits remove the context used to save state. I'm still not sure why I ended up with that. All examples and tests work. None of your other comments have been addressed yet. |
Hi @jakezatecky, I have reviewed you comments and agree with your views. I have made the changes and have the code in a pretty good state. The documentation is not finished but it should be in a reasonable state also. I have not added the additional methods to Also here is a list of questions/comments I think need addressing:
My choice on Let me know if the above discussion is not clear. I'm looking forward hearing your comments. |
The latest commit defines one method of handling the I've changed the The
Nodes can be marked as disabled individually with the node Disabling child nodes is handled by When
It defaults to the value of
Let me know what you think of this definition of The alternative to the above definition would be to handle all cascading in the Problems occur with this definition when a the value of This seemed more difficult and confusing to me so I chose the other method. Questions:
|
This restructure moves the tree state into a
TreeModel
.CheckboxTree
and other React components display the tree.CheckboxTree
is an uncontrolled component. The state is stored in a context and supplied by theCheckboxTreeProvider
. This can be seen in the BasicExample. All the examples work including a new one displaying the additions of radio button node groups, RadioButtonExample. This is an addition I had working on a fork of v1.6.The initial tree which was input to
CheckboxTree
as thenodes
prop previously is now theinitialTreeState
prop. The state formally kept in thechecked
andexpanded
arrays is now input through theinitialTreeState
object.The
onCheck
andonExpand
handlers are passed achangedNodeKey
and an instance of TreeModel,. This allows an application to access the tree and do whatever is required based on the changed node. For example:Note that the
TreeModel
has public methods which allow access to the tree and its nodes. A good example of this is in the FilterExample where theTreeModel.filter
method is used. Excerpt below:Not all the tests are fixed yet and I'm working on the documentation now.
Questions, comments, criticisms and suggestions requested.