[WIP]: Initial wip refactor nav tree without kendo#2
Draft
Alex-Swann wants to merge 1 commit intomasterfrom
Draft
[WIP]: Initial wip refactor nav tree without kendo#2Alex-Swann wants to merge 1 commit intomasterfrom
Alex-Swann wants to merge 1 commit intomasterfrom
Conversation
Contributor
|
Looks good, however whomever will be contributing to the development of this - some things might be worth considering to implement also.
This is some draft (untested) code that should be feasible to allow child pages - however this is with Kendo. convertTreeToKendoTree(item, parentAncestors = [], actions = []) {
const { expandedItems } = this.state;
const opened = !!expandedItems.find(
({ directory }) => directory === item.directory
);
const childAncestors = !!item.directory
? [...parentAncestors, item.directory]
: parentAncestors;
const node = {
text: item.directory ? item.directory : item.title,
opened,
items: Array.isArray(item.links)
? item.links.map(childItem =>
this.convertTreeToKendoTree(childItem, childAncestors, actions)
)
: [],
ancestors: parentAncestors,
...item,
};
node.items = this.sortByItems(node.items);
return actions.reduce((mutatedNode, fn) => fn(mutatedNode), node);
}With the Nav component tree to then be updated to reflect: const NavItem = ({ item }) => {
if (!item.directory) {
return (
<Link className="nav nav-link" to={item.path}>
{item.title}
</Link>
);
}
// If the item has child pages, render them recursively
if (Array.isArray(item.links) && item.links.length > 0) {
return (
<div className="nav nav-directory">
<p>{item.directory}</p>
<ul>
{item.links.map(childItem => (
<li key={childItem.path}>
<NavItem item={childItem} />
</li>
))}
</ul>
</div>
);
}
// If the item is an empty directory, render it without child pages
return <p className="nav nav-directory">{item.directory}</p>;
}; |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Initial WIP on replacing nav tree with something not reliant on Kendo