Skip to content

Commit

Permalink
add metadata to INode and shallow copy when flattening tree
Browse files Browse the repository at this point in the history
  • Loading branch information
megbailey authored and kpustakhod committed Jun 12, 2023
1 parent b305a8d commit 7d5b74a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/TreeView/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export type EventCallback = <T, E>(
parent: NodeId | null;
/** Used to indicated whether a node is branch to be able load async data onExpand*/
isBranch?: boolean;
/** User-defined metadata */
metadata?: any;
}

export interface INodeRendererProps {
Expand Down
2 changes: 2 additions & 0 deletions src/TreeView/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ interface ITreeNode {
id?: NodeId;
name: string;
children?: ITreeNode[];
metadata?: any;
}

export const flattenTree = function(tree: ITreeNode): INode[] {
Expand All @@ -300,6 +301,7 @@ export const flattenTree = function(tree: ITreeNode): INode[] {
name: tree.name,
children: [],
parent,
...tree.metadata && { metadata: {...tree.metadata }}
};

if (flattenedTree.find((x) => x.id === node.id)) {
Expand Down

0 comments on commit 7d5b74a

Please sign in to comment.