packages/components/eui-tree/eui-tree-helper.ts
Utility class for navigating and querying hierarchical tree data structures. Provides methods to locate nodes by value, retrieve paths, and extract items from tree data. Supports custom identifier keys for flexible node matching across different tree schemas. Commonly used with eui-tree component for programmatic tree manipulation and node lookup.
const treeData: TreeDataModel = [
{
node: { treeContentBlock: { id: '1', label: 'Root' } },
children: [
{ node: { treeContentBlock: { id: '1.1', label: 'Child' } } }
]
}
];
const helper = new EuiTreeHelper(treeData);
// Get path to a node by ID
const path = helper.getPath('1.1', 'node.treeContentBlock.id');
// Returns: '0.0'
// Get multiple paths
const paths = helper.getPaths(['1', '1.1'], 'node.treeContentBlock.id');
// Returns: ['0', '0.0']
// Get actual tree items
const items = helper.getItems(['1.1'], 'node.treeContentBlock.id');
// Returns: [TreeItemModel]// Tree with custom structure
const customTree = [
{ node: { customId: 'abc', label: 'Item' } }
];
const helper = new EuiTreeHelper(customTree);
const path = helper.getPath('abc', 'node.customId');
Methods |
constructor(treeData: TreeDataModel)
|
||||||
|
Parameters :
|
| Public getItems | ||||||||||||
getItems(values: Array
|
||||||||||||
|
Retrieves the actual TreeItemModel objects for nodes matching the provided values. Returns full node data including children and metadata.
Parameters :
Returns :
Array<TreeItemModel>
Array of TreeItemModel objects for matched nodes |
| Public getPath | |||||||||||||||
getPath(value: any, identifierKey: string)
|
|||||||||||||||
|
Retrieves the path string for a single node matching the provided value. Path format uses dot notation with indices (e.g., '0.2.1' for first child, third grandchild, second great-grandchild).
Parameters :
Returns :
string
Path string to the matched node, or null if not found |
| Public getPaths | ||||||||||||
getPaths(values: Array
|
||||||||||||
|
Retrieves path strings for multiple nodes matching the provided values. Returns paths in the order nodes are found during tree traversal.
Parameters :
Returns :
Array<string>
Array of path strings to matched nodes |