From 40ff8605449350213fe4756e551bdd409f11fb05 Mon Sep 17 00:00:00 2001 From: tconfrey Date: Mon, 2 Dec 2024 17:25:07 -0500 Subject: [PATCH] fixed a long standing bug/issue causing leaf nodes to turn into topics. When saving from a TG was checking for tg-name == node.topicName, but not validating that the node was itself the topic node. --- versions/1.1/app/BTAppNode.js | 14 +++++++------- versions/1.1/app/BTNode.js | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/versions/1.1/app/BTAppNode.js b/versions/1.1/app/BTAppNode.js index 3090494..f797029 100644 --- a/versions/1.1/app/BTAppNode.js +++ b/versions/1.1/app/BTAppNode.js @@ -967,7 +967,7 @@ class BTAppNode extends BTNode { // find topic from tab group return AllNodes.find(node => node && node.isTopic() && node.tabGroupId == groupId); } - + static findOrCreateFromTopicDN(topicDN) { // Walk down tree of topics from top, finding or creating nodes & tt display nodes let components = topicDN.match(/.*?:/g); @@ -976,20 +976,20 @@ class BTAppNode extends BTNode { const topTopic = (components && components.length) ? components[0] : topic; // Find or create top node - let topNode = AllNodes.find(node => node && node.topicName() == topTopic); + let topNode = AllNodes.find(node => node && (node.topicName() == topTopic) && (node.isTopic())); if (!topNode) { topNode = new BTAppNode(topTopic, null, "", 1); topNode.createDisplayNode(); } - + if (!components) return topNode; - + // Remove, now handled first elt, Walk down rest creating as needed let currentNode = topNode; components.shift(); components.forEach((t) => { let node = currentNode; - currentNode = currentNode.findChild(t); + currentNode = currentNode.findTopicChild(t); if (!currentNode) { currentNode = new BTAppNode(t, node.id, "", node.level + 1); currentNode.createDisplayNode(); @@ -997,8 +997,8 @@ class BTAppNode extends BTNode { }); // finally find or create the leaf node - if (currentNode.findChild(topic)) - return currentNode.findChild(topic); + if (currentNode.findTopicChild(topic)) + return currentNode.findTopicChild(topic); let newLeaf = new BTAppNode(topic, currentNode.id, "", currentNode.level + 1); newLeaf.createDisplayNode(); topNode.redisplay(); // since new nodes created diff --git a/versions/1.1/app/BTNode.js b/versions/1.1/app/BTNode.js index 4f77d93..defe3f0 100644 --- a/versions/1.1/app/BTNode.js +++ b/versions/1.1/app/BTNode.js @@ -99,12 +99,12 @@ class BTNode { this._childIds.splice(index, 1); } - findChild(childTopic) { + findTopicChild(childTopic) { // does this topic node have this sub topic - const childId = this.childIds.find(id => AllNodes[id].topicName() == childTopic); + const childId = this.childIds.find(id => (AllNodes[id].isTopic () && (AllNodes[id].topicName() == childTopic))); return childId ? AllNodes[childId] : null; } - + getDescendantIds() { // return a list of all the descendant node ids let descendants = [];