mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Fix updating the subflow name during a copy
This commit is contained in:
parent
1b5b3f7f88
commit
7950ee1241
@ -1032,23 +1032,31 @@ 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 || "";
|
||||
}).sort();
|
||||
|
||||
subflowNames.sort();
|
||||
var copyNumber = 1;
|
||||
var subflowName = sf.name;
|
||||
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] = [];
|
||||
@ -2023,6 +2031,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();
|
||||
@ -2050,7 +2060,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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user