1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Avoid duplicate links when missing node type installed

Fixes #2032
This commit is contained in:
Nick O'Leary 2019-01-17 22:35:58 +00:00
parent 1359545e13
commit 0e035e47df
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9

View File

@ -1306,21 +1306,23 @@ RED.nodes = (function() {
RED.events.on("registry:node-type-added",function(type) { RED.events.on("registry:node-type-added",function(type) {
var def = registry.getNodeType(type); var def = registry.getNodeType(type);
var replaced = false; var replaced = false;
var replaceNodes = []; var replaceNodes = {};
RED.nodes.eachNode(function(n) { RED.nodes.eachNode(function(n) {
if (n.type === "unknown" && n.name === type) { if (n.type === "unknown" && n.name === type) {
replaceNodes.push(n); replaceNodes[n.id] = n;
} }
}); });
RED.nodes.eachConfig(function(n) { RED.nodes.eachConfig(function(n) {
if (n.type === "unknown" && n.name === type) { if (n.type === "unknown" && n.name === type) {
replaceNodes.push(n); replaceNodes[n.id] = n;
} }
}); });
if (replaceNodes.length > 0) { var replaceNodeIds = Object.keys(replaceNodes);
if (replaceNodeIds.length > 0) {
var reimportList = []; var reimportList = [];
replaceNodes.forEach(function(n) { replaceNodeIds.forEach(function(id) {
var n = replaceNodes[id];
if (configNodes.hasOwnProperty(n.id)) { if (configNodes.hasOwnProperty(n.id)) {
delete configNodes[n.id]; delete configNodes[n.id];
} else { } else {
@ -1328,6 +1330,18 @@ RED.nodes = (function() {
} }
reimportList.push(convertNode(n)); reimportList.push(convertNode(n));
}); });
// Remove any links between nodes that are going to be reimported.
// This prevents a duplicate link from being added.
var removeLinks = [];
RED.nodes.eachLink(function(l) {
if (replaceNodes.hasOwnProperty(l.source.id) && replaceNodes.hasOwnProperty(l.target.id)) {
removeLinks.push(l);
}
});
removeLinks.forEach(removeLink);
RED.view.redraw(true); RED.view.redraw(true);
var result = importNodes(reimportList,false); var result = importNodes(reimportList,false);
var newNodeMap = {}; var newNodeMap = {};