mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Merge pull request #4809 from GogoVega/fix-subflow-name
Fix updating the Subflow name during a copy
This commit is contained in:
commit
3e0b5f2fe8
@ -1038,23 +1038,32 @@ RED.nodes = (function() {
|
|||||||
return {nodes:removedNodes,links:removedLinks, groups: removedGroups, junctions: removedJunctions};
|
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) {
|
function addSubflow(sf, createNewIds) {
|
||||||
if (createNewIds) {
|
if (createNewIds) {
|
||||||
var subflowNames = Object.keys(subflows).map(function(sfid) {
|
// Update the Subflow name to highlight that this is a copy
|
||||||
return subflows[sfid].name;
|
const subflowNames = Object.keys(subflows).map(function (sfid) {
|
||||||
});
|
return subflows[sfid].name || "";
|
||||||
|
})
|
||||||
|
subflowNames.sort()
|
||||||
|
|
||||||
subflowNames.sort();
|
let copyNumber = 1;
|
||||||
var copyNumber = 1;
|
let subflowName = sf.name;
|
||||||
var subflowName = sf.name;
|
|
||||||
subflowNames.forEach(function(name) {
|
subflowNames.forEach(function(name) {
|
||||||
if (subflowName == name) {
|
if (subflowName == name) {
|
||||||
|
subflowName = sf.name + " (" + copyNumber + ")";
|
||||||
copyNumber++;
|
copyNumber++;
|
||||||
subflowName = sf.name+" ("+copyNumber+")";
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
sf.name = subflowName;
|
sf.name = subflowName;
|
||||||
}
|
}
|
||||||
|
|
||||||
subflows[sf.id] = sf;
|
subflows[sf.id] = sf;
|
||||||
allNodes.addTab(sf.id);
|
allNodes.addTab(sf.id);
|
||||||
linkTabMap[sf.id] = [];
|
linkTabMap[sf.id] = [];
|
||||||
@ -2029,6 +2038,8 @@ RED.nodes = (function() {
|
|||||||
if (matchingSubflow) {
|
if (matchingSubflow) {
|
||||||
subflow_denylist[n.id] = matchingSubflow;
|
subflow_denylist[n.id] = matchingSubflow;
|
||||||
} else {
|
} else {
|
||||||
|
const oldId = n.id;
|
||||||
|
|
||||||
subflow_map[n.id] = n;
|
subflow_map[n.id] = n;
|
||||||
if (createNewIds || options.importMap[n.id] === "copy") {
|
if (createNewIds || options.importMap[n.id] === "copy") {
|
||||||
nid = getID();
|
nid = getID();
|
||||||
@ -2056,7 +2067,7 @@ RED.nodes = (function() {
|
|||||||
n.status.id = getID();
|
n.status.id = getID();
|
||||||
}
|
}
|
||||||
new_subflows.push(n);
|
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