From 1f1ca37fd761b3fdd6d9b22650d5cc4dbb77973a Mon Sep 17 00:00:00 2001 From: Julius Volz Date: Sun, 8 Sep 2024 20:53:59 +0200 Subject: [PATCH] Select root of tree by default in tree view Signed-off-by: Julius Volz --- .../mantine-ui/src/pages/query/TreeNode.tsx | 45 +++++++++++-------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/web/ui/mantine-ui/src/pages/query/TreeNode.tsx b/web/ui/mantine-ui/src/pages/query/TreeNode.tsx index 8ac176e58..95d51f0de 100644 --- a/web/ui/mantine-ui/src/pages/query/TreeNode.tsx +++ b/web/ui/mantine-ui/src/pages/query/TreeNode.tsx @@ -92,6 +92,13 @@ const TreeNode: FC<{ sortedLabelCards: [], }); + // Select the node when it is mounted and it is the root of the tree. + useEffect(() => { + if (parentRef === undefined) { + setSelectedNode({ id: nodeID, node: node }); + } + }, [parentRef, setSelectedNode, nodeID, node]); + // Deselect node when node is unmounted. useEffect(() => { return () => { @@ -400,26 +407,26 @@ const TreeNode: FC<{ ); - } else { - return ( -
- {innerNode} - {children.map((child, idx) => ( - - - - ))} -
- ); } + + return ( +
+ {innerNode} + {children.map((child, idx) => ( + + + + ))} +
+ ); }; export default TreeNode;