Merge pull request #4809 from GogoVega/fix-subflow-name

Fix updating the Subflow name during a copy
This commit is contained in:
Nick O'Leary 2024-11-25 16:22:31 +00:00 committed by GitHub
commit 3e0b5f2fe8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1038,23 +1038,32 @@ 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 update the name.
*/
function addSubflow(sf, createNewIds) {
if (createNewIds) {
var subflowNames = Object.keys(subflows).map(function(sfid) {
return subflows[sfid].name;
});
// Update the Subflow name to highlight that this is a copy
const subflowNames = Object.keys(subflows).map(function (sfid) {
return subflows[sfid].name || "";
})
subflowNames.sort()
subflowNames.sort();
var copyNumber = 1;
var subflowName = sf.name;
let copyNumber = 1;
let subflowName = sf.name;
subflowNames.forEach(function(name) {
if (subflowName == name) {
copyNumber++;
subflowName = sf.name + " (" + copyNumber + ")";
copyNumber++;
}
});
sf.name = subflowName;
}
subflows[sf.id] = sf;
allNodes.addTab(sf.id);
linkTabMap[sf.id] = [];
@ -2029,6 +2038,8 @@ RED.nodes = (function() {
if (matchingSubflow) {
subflow_denylist[n.id] = matchingSubflow;
} else {
const oldId = n.id;
subflow_map[n.id] = n;
if (createNewIds || options.importMap[n.id] === "copy") {
nid = getID();
@ -2056,7 +2067,7 @@ RED.nodes = (function() {
n.status.id = getID();
}
new_subflows.push(n);
addSubflow(n,createNewIds || options.importMap[n.id] === "copy");
addSubflow(n,createNewIds || options.importMap[oldId] === "copy");
}
}
}