Skip to content
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

[WIP]: Initial wip refactor nav tree without kendo #2

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Alex-Swann
Copy link
Contributor

@Alex-Swann Alex-Swann commented Jun 20, 2022

Initial WIP on replacing nav tree with something not reliant on Kendo

@ShahSheel ShahSheel added the enhancement New feature or request label Sep 1, 2023
@ShahSheel
Copy link
Contributor

Looks good, however whomever will be contributing to the development of this - some things might be worth considering to implement also.

  • Child navigation
  • Fixation of drop downs

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>;
};

@ShahSheel ShahSheel added the improvement required Needs improvement label Sep 1, 2023
@dk4g dk4g marked this pull request as draft April 19, 2024 22:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request improvement required Needs improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants