Fix updating Subflow name when it's a copy

This commit is contained in:
GogoVega 2024-06-19 12:39:02 +02:00
parent 476e8345c5
commit 58d4c36600
No known key found for this signature in database
GPG Key ID: E1E048B63AC5AC2B

View File

@ -1006,23 +1006,34 @@ RED.nodes = (function() {
return {nodes:removedNodes,links:removedLinks, groups: removedGroups, junctions: removedJunctions};
}
/**
* Add a Subflow to the Workspace
*
* @param {object} sf The Subflow to add.
* @param {boolean|undefined} createNewIds Whether to create a new ID and update the name.
*/
function addSubflow(sf, createNewIds) {
if (createNewIds) {
var subflowNames = Object.keys(subflows).map(function(sfid) {
return subflows[sfid].name;
});
// Update the Subflow Id
sf.id = generateId();
subflowNames.sort();
var copyNumber = 1;
var subflowName = sf.name;
// Update the Subflow name to highlight that this is a copy
const subflowNames = Object.keys(subflows).map(function (sfid) {
return subflows[sfid].name || "";
}).sort();
let copyNumber = 1;
let subflowName = sf.name;
subflowNames.forEach(function(name) {
if (subflowName == name) {
subflowName = sf.name + " (" + copyNumber + ")";
copyNumber++;
subflowName = sf.name+" ("+copyNumber+")";
}
});
sf.name = subflowName;
}
subflows[sf.id] = sf;
allNodes.addTab(sf.id);
linkTabMap[sf.id] = [];
@ -2151,11 +2162,10 @@ RED.nodes = (function() {
node.status.z = node.id;
node.status.id = generateId();
}
if (createNewIds || options.importMap[node.id] === "copy") {
node.id = generateId();
}
subflowMap[oldId] = node;
newSubflows.push(node);
// NOTE: Update the id in the `addSubflow` function
addSubflow(node, (createNewIds || options.importMap[node.id] === "copy"));
}
}