NavigationTree

Last modified by Pierre Jeanjean on 2024/10/02 15:19

Description

The NavigationTree API provides components that can be used to generate a navigation tree, which is then used to display, e.g., the navigation tree on the left sidebar of Cristal pages, and the space selector during page creation.

Details

NavigationTreeSource is a component that offers two methods:

  /**
   * Returns the direct child nodes for a given page id in the navigation tree.
   * If the page id is omitted, returns the root nodes instead.
   *
   * @param id the page id
   * @returns the descendants in the navigation tree
   */

  getChildNodes(id?: string): Promise<Array<NavigationTreeNode>>;

 /**
   * Returns the ids of the parents nodes for a given page.
   *
   * @param page the data of the page
   * @returns the parents nodes ids
   **/

  getParentNodesId(page?: PageData): Array<string>;

A NavigationTreeNode is a simple data structure that stores all the information required render a node and to navigate the tree:

/**
 * Description of a navigation tree node.
 */

type NavigationTreeNode = {
 /** the id of a node, used by the NavigationTreeSource to access children */
  id: string;
  label: string;
 /** the location of the corresponding page on Cristal */
  location: string;
  url: string;
  has_children: boolean;
};

Even though there is a default implementation in DefaultNavigationTreeSource, it is expected that any backend should implement their own NavigationTreeSource with logic specific to the backend. E.g.,

/**
 * Implementation of NavigationTreeSource for the XWiki backend.
 **/

@injectable()
class XWikiNavigationTreeSource implements NavigationTreeSource {
 // XWiki specific implementation.
}

Each backend-specific implementation should be registered with the name of the backend that they support, and will then be available through DefaultNavigationTreeSourceProvider.get() whenever the backend is in use.

France 2030 Logo

This project is being financed by the French State as part of the France 2030 program

Ce projet est financé par l’État Français dans le cadre de France 2030

  • Powered by XWiki 16.4.4-node2. Hosted and managed by XWiki SAS

Get Connected