From 11ac8fbf13eddac5bea7215c6005fe739120e45b Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Tue, 7 Jul 2020 18:22:45 +0100 Subject: [PATCH] Ensure groups are removed when deleting subflows --- .../@node-red/editor-client/src/js/nodes.js | 15 +++++++++------ .../editor-client/src/js/ui/subflow.js | 19 ++++++++++++++++++- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/packages/node_modules/@node-red/editor-client/src/js/nodes.js b/packages/node_modules/@node-red/editor-client/src/js/nodes.js index a27e491f8..ee7e7413f 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/nodes.js +++ b/packages/node_modules/@node-red/editor-client/src/js/nodes.js @@ -611,7 +611,9 @@ RED.nodes = (function() { node.y = n.y; node.w = n.w; node.h = n.h; - node.nodes = node.nodes.map(function(n) { return n.id }); + // In 1.1.0, we have seen an instance of this array containing `undefined` + // Until we know how that can happen, add a filter here to remove them + node.nodes = node.nodes.filter(function(n) { return !!n }).map(function(n) { return n.id }); } if (n._def.category != "config") { node.x = n.x; @@ -991,7 +993,7 @@ RED.nodes = (function() { var workspace_map = {}; var new_subflows = []; var subflow_map = {}; - var subflow_blacklist = {}; + var subflow_denylist = {}; var node_map = {}; var new_nodes = []; var new_links = []; @@ -1024,7 +1026,7 @@ RED.nodes = (function() { } else if (n.type === "subflow") { var matchingSubflow = checkForMatchingSubflow(n,nodeZmap[n.id]); if (matchingSubflow) { - subflow_blacklist[n.id] = matchingSubflow; + subflow_denylist[n.id] = matchingSubflow; } else { subflow_map[n.id] = n; if (createNewIds) { @@ -1075,7 +1077,7 @@ RED.nodes = (function() { var existingConfigNode = null; if (createNewIds) { if (n.z) { - if (subflow_blacklist[n.z]) { + if (subflow_denylist[n.z]) { continue; } else if (subflow_map[n.z]) { n.z = subflow_map[n.z].id; @@ -1182,7 +1184,7 @@ RED.nodes = (function() { node.g = n.g; } if (createNewIds) { - if (subflow_blacklist[n.z]) { + if (subflow_denylist[n.z]) { continue; } else if (subflow_map[node.z]) { node.z = subflow_map[node.z].id; @@ -1229,7 +1231,7 @@ RED.nodes = (function() { node._config.y = node.y; } else if (n.type.substring(0,7) === "subflow") { var parentId = n.type.split(":")[1]; - var subflow = subflow_blacklist[parentId]||subflow_map[parentId]||getSubflow(parentId); + var subflow = subflow_denylist[parentId]||subflow_map[parentId]||getSubflow(parentId); if (createNewIds) { parentId = subflow.id; node.type = "subflow:"+parentId; @@ -1439,6 +1441,7 @@ RED.nodes = (function() { n.nodes = n.nodes.map(function(id) { return node_map[id]; }) + // Just in case the group references a node that doesn't exist for some reason n.nodes = n.nodes.filter(function(v) { return !!v}); if (!n.g) { groupDepthMap[n.id] = 0; diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/subflow.js b/packages/node_modules/@node-red/editor-client/src/js/ui/subflow.js index 88a42063f..2909d1133 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/subflow.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/subflow.js @@ -454,8 +454,10 @@ RED.subflow = (function() { } function removeSubflow(id) { + // TODO: A lot of this logic is common with RED.nodes.removeWorkspace var removedNodes = []; var removedLinks = []; + var removedGroups = []; var activeSubflow = RED.nodes.subflow(id); @@ -472,7 +474,9 @@ RED.subflow = (function() { removedNodes.push(n); } }); - + RED.nodes.groups(id).forEach(function(n) { + removedGroups.push(n); + }) var removedConfigNodes = []; for (var i=0;i=0; i--) { + RED.nodes.removeGroup(removedGroups[i]); + } RED.nodes.removeSubflow(activeSubflow); RED.workspaces.remove(activeSubflow); RED.nodes.dirty(true); @@ -490,6 +506,7 @@ RED.subflow = (function() { return { nodes:removedNodes, links:removedLinks, + groups: removedGroups, subflows: [activeSubflow] } }