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

Ensure groups are removed when deleting subflows

This commit is contained in:
Nick O'Leary 2020-07-07 18:22:45 +01:00
parent dc541444ba
commit 11ac8fbf13
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
2 changed files with 27 additions and 7 deletions

View File

@ -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;

View File

@ -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<removedNodes.length;i++) {
var removedEntities = RED.nodes.remove(removedNodes[i].id);
@ -482,6 +486,18 @@ RED.subflow = (function() {
// TODO: this whole delete logic should be in RED.nodes.removeSubflow..
removedNodes = removedNodes.concat(removedConfigNodes);
removedGroups = RED.nodes.groups(id).filter(function(g) { return !g.g; });
for (i=0;i<removedGroups.length;i++) {
removedGroups[i].nodes.forEach(function(n) {
if (n.type === "group") {
removedGroups.push(n);
}
});
}
// Now remove them in the reverse order
for (i=removedGroups.length-1; 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]
}
}