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

Merge pull request #3921 from node-red/fix-group-unknown

Handle replacing unknown node inside group or subflow
This commit is contained in:
Nick O'Leary 2022-11-30 22:09:35 +00:00 committed by GitHub
commit 3cb84222f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1965,7 +1965,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 +2067,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 +2740,7 @@ RED.nodes = (function() {
} }
}); });
const 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 +2751,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 +2778,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)) {