mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Handle replacing unknown node inside group or subflow
This commit is contained in:
parent
32999ffa84
commit
b40551a8fa
@ -1768,6 +1768,7 @@ RED.nodes = (function() {
|
|||||||
unknownTypes.push(n.type);
|
unknownTypes.push(n.type);
|
||||||
}
|
}
|
||||||
if (n.z) {
|
if (n.z) {
|
||||||
|
if (n.id === '42051f44c151e5d7') console.log('importing',n.z)
|
||||||
nodeZmap[n.z] = nodeZmap[n.z] || [];
|
nodeZmap[n.z] = nodeZmap[n.z] || [];
|
||||||
nodeZmap[n.z].push(n);
|
nodeZmap[n.z].push(n);
|
||||||
} else if (isInitialLoad && n.hasOwnProperty('x') && n.hasOwnProperty('y') && !n.z) {
|
} else if (isInitialLoad && n.hasOwnProperty('x') && n.hasOwnProperty('y') && !n.z) {
|
||||||
@ -1965,7 +1966,7 @@ RED.nodes = (function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const keepNodesCurrentZ = reimport && n.z && RED.workspaces.contains(n.z)
|
const keepNodesCurrentZ = reimport && n.z && (RED.workspaces.contains(n.z) || RED.nodes.subflow(n.z))
|
||||||
if (!keepNodesCurrentZ && n.z && !workspace_map[n.z] && !subflow_map[n.z]) {
|
if (!keepNodesCurrentZ && n.z && !workspace_map[n.z] && !subflow_map[n.z]) {
|
||||||
n.z = activeWorkspace;
|
n.z = activeWorkspace;
|
||||||
}
|
}
|
||||||
@ -2067,7 +2068,7 @@ RED.nodes = (function() {
|
|||||||
node.id = getID();
|
node.id = getID();
|
||||||
} else {
|
} else {
|
||||||
node.id = n.id;
|
node.id = n.id;
|
||||||
const keepNodesCurrentZ = reimport && node.z && RED.workspaces.contains(node.z)
|
const keepNodesCurrentZ = reimport && node.z && (RED.workspaces.contains(node.z) || RED.nodes.subflow(node.z))
|
||||||
if (!keepNodesCurrentZ && (node.z == null || (!workspace_map[node.z] && !subflow_map[node.z]))) {
|
if (!keepNodesCurrentZ && (node.z == null || (!workspace_map[node.z] && !subflow_map[node.z]))) {
|
||||||
if (createMissingWorkspace) {
|
if (createMissingWorkspace) {
|
||||||
if (missingWorkspace === null) {
|
if (missingWorkspace === null) {
|
||||||
@ -2740,6 +2741,7 @@ RED.nodes = (function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var nodeGroupMap = {}
|
||||||
var replaceNodeIds = Object.keys(replaceNodes);
|
var replaceNodeIds = Object.keys(replaceNodes);
|
||||||
if (replaceNodeIds.length > 0) {
|
if (replaceNodeIds.length > 0) {
|
||||||
var reimportList = [];
|
var reimportList = [];
|
||||||
@ -2750,6 +2752,12 @@ RED.nodes = (function() {
|
|||||||
} else {
|
} else {
|
||||||
allNodes.removeNode(n);
|
allNodes.removeNode(n);
|
||||||
}
|
}
|
||||||
|
if (n.g) {
|
||||||
|
// reimporting a node *without* including its group object
|
||||||
|
// will cause the g property to be cleared. Cache it
|
||||||
|
// here so we can restore it
|
||||||
|
nodeGroupMap[n.id] = n.g
|
||||||
|
}
|
||||||
reimportList.push(convertNode(n));
|
reimportList.push(convertNode(n));
|
||||||
RED.events.emit('nodes:remove',n);
|
RED.events.emit('nodes:remove',n);
|
||||||
});
|
});
|
||||||
@ -2771,6 +2779,18 @@ RED.nodes = (function() {
|
|||||||
var newNodeMap = {};
|
var newNodeMap = {};
|
||||||
result.nodes.forEach(function(n) {
|
result.nodes.forEach(function(n) {
|
||||||
newNodeMap[n.id] = n;
|
newNodeMap[n.id] = n;
|
||||||
|
if (nodeGroupMap[n.id]) {
|
||||||
|
// This node is in a group - need to substitute the
|
||||||
|
// node reference inside the group
|
||||||
|
n.g = nodeGroupMap[n.id]
|
||||||
|
const group = RED.nodes.group(n.g)
|
||||||
|
if (group) {
|
||||||
|
var index = group.nodes.findIndex(gn => gn.id === n.id)
|
||||||
|
if (index > -1) {
|
||||||
|
group.nodes[index] = n
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
RED.nodes.eachLink(function(l) {
|
RED.nodes.eachLink(function(l) {
|
||||||
if (newNodeMap.hasOwnProperty(l.source.id)) {
|
if (newNodeMap.hasOwnProperty(l.source.id)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user