From a3f73d8fb8dc1dc5cc6e6b4ae2f0b4b4a516cd08 Mon Sep 17 00:00:00 2001 From: masillan Date: Tue, 3 Dec 2024 17:18:41 +0200 Subject: [PATCH] CSCFC4EMSCR-585 changed fetching id by splitting path to finding parent path and search node with parent path recursively and reading id field from parent node. --- .../common/components/schema-info/index.tsx | 51 +++++++++++++++---- 1 file changed, 42 insertions(+), 9 deletions(-) diff --git a/mscr-ui/src/common/components/schema-info/index.tsx b/mscr-ui/src/common/components/schema-info/index.tsx index b6baff4ce..24b64f525 100644 --- a/mscr-ui/src/common/components/schema-info/index.tsx +++ b/mscr-ui/src/common/components/schema-info/index.tsx @@ -129,18 +129,51 @@ export default function SchemaInfo(props: { // Used by tree select and filtering function getAllNodeIdsOnPathToLeaf(nodeIds: string[]) { + let nodesWithElementPath: {[elementPath: string] : RenderTree[]} = {}; + const nodesToSelect: Set = new Set(); const elementPaths: string[] = []; + for (let key in nodeIdToNodeDictionary) { + if (nodeIdToNodeDictionary[key]) { + let renderTrees = nodeIdToNodeDictionary[key]; + if (renderTrees && renderTrees.length > 0) { + renderTrees.forEach(tree => { + if (tree && tree.elementPath) { + let treeArray = []; + treeArray = nodesWithElementPath[tree.elementPath]; + if (treeArray && treeArray.length > 0) { + treeArray.push(tree); + } else { + treeArray = []; + treeArray.push(tree); + } + nodesWithElementPath[tree.elementPath] = treeArray; + } + }); + + } + } + } nodeIds.forEach((nodeId) => { + nodesToSelect.add(nodeId); const nodes = nodeIdToNodeDictionary[nodeId]; - nodes.map((node) => elementPaths.push(node.elementPath)); - }); - - const nodesToSelect: Set = new Set(); - elementPaths.forEach((path) => { - const nodeIdsOnPath = path.split('.'); - nodeIdsOnPath.forEach((nodeId) => { - nodesToSelect.add(nodeId); - }); + if (nodes && nodes.length > 0) { + nodes.map((node) => { + if (node.parentElementPath) { + let nodeInParentElementPath: string | undefined = node.parentElementPath; + while(nodeInParentElementPath !== undefined) { + let parentNodeTrees: RenderTree[] = nodesWithElementPath[nodeInParentElementPath]; + inner: + for (let parentNodeTree of parentNodeTrees) { + if (parentNodeTree && parentNodeTree.id) { + nodesToSelect.add(parentNodeTree.id); + nodeInParentElementPath = parentNodeTree.parentElementPath + break inner; // there should be only one parent + } + } + } + } + }); + } }); return Array.from(nodesToSelect);