mirror of
				https://github.com/node-red/node-red.git
				synced 2025-03-01 10:36:34 +00:00 
			
		
		
		
	Handle replacing unknown node inside group or subflow
This commit is contained in:
		| @@ -1768,6 +1768,7 @@ RED.nodes = (function() { | ||||
|                     unknownTypes.push(n.type); | ||||
|             } | ||||
|             if (n.z) { | ||||
| if (n.id === '42051f44c151e5d7') console.log('importing',n.z) | ||||
|                 nodeZmap[n.z] = nodeZmap[n.z] || []; | ||||
|                 nodeZmap[n.z].push(n); | ||||
|             } else if (isInitialLoad && n.hasOwnProperty('x') && n.hasOwnProperty('y') && !n.z) { | ||||
| @@ -1965,7 +1966,7 @@ RED.nodes = (function() { | ||||
|                         } | ||||
|                     } | ||||
|                 } 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]) { | ||||
|                         n.z = activeWorkspace; | ||||
|                     } | ||||
| @@ -2067,7 +2068,7 @@ RED.nodes = (function() { | ||||
|                         node.id = getID(); | ||||
|                     } else { | ||||
|                         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 (createMissingWorkspace) { | ||||
|                                 if (missingWorkspace === null) { | ||||
| @@ -2740,6 +2741,7 @@ RED.nodes = (function() { | ||||
|                     } | ||||
|                 }); | ||||
|  | ||||
|                 var nodeGroupMap = {} | ||||
|                 var replaceNodeIds = Object.keys(replaceNodes); | ||||
|                 if (replaceNodeIds.length > 0) { | ||||
|                     var reimportList = []; | ||||
| @@ -2750,6 +2752,12 @@ RED.nodes = (function() { | ||||
|                         } else { | ||||
|                             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)); | ||||
|                         RED.events.emit('nodes:remove',n); | ||||
|                     }); | ||||
| @@ -2771,6 +2779,18 @@ RED.nodes = (function() { | ||||
|                     var newNodeMap = {}; | ||||
|                     result.nodes.forEach(function(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) { | ||||
|                         if (newNodeMap.hasOwnProperty(l.source.id)) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user