mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-12 13:27:31 -08:00
⚡ Improve naming of created names
This commit is contained in:
parent
5054c7054d
commit
6fc02a5024
|
@ -850,20 +850,37 @@ export default mixins(
|
||||||
return newPosition!;
|
return newPosition!;
|
||||||
},
|
},
|
||||||
getUniqueNodeName (originalName: string, additinalUsedNames?: string[]) {
|
getUniqueNodeName (originalName: string, additinalUsedNames?: string[]) {
|
||||||
|
// Check if node-name is unique else find one that is
|
||||||
additinalUsedNames = additinalUsedNames || [];
|
additinalUsedNames = additinalUsedNames || [];
|
||||||
|
|
||||||
// Check if node-name is unique else find one that is
|
// Get all the names of the current nodes
|
||||||
const nodeNames = this.$store.getters.allNodes.map((node: INodeUi) => {
|
const nodeNames = this.$store.getters.allNodes.map((node: INodeUi) => {
|
||||||
return node.name;
|
return node.name;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const nameMatch = originalName.match(/(.*[a-zA-Z])(\d*)/);
|
||||||
|
let ignore, baseName, nameIndex, uniqueName;
|
||||||
let index = 1;
|
let index = 1;
|
||||||
let uniqueName = originalName;
|
|
||||||
|
if (nameMatch === null) {
|
||||||
|
// Name is only a number
|
||||||
|
index = parseInt(originalName, 10);
|
||||||
|
baseName = '';
|
||||||
|
uniqueName = baseName + index;
|
||||||
|
} else {
|
||||||
|
// Name is string or string/number combination
|
||||||
|
[ignore, baseName, nameIndex] = nameMatch;
|
||||||
|
if (nameIndex !== '') {
|
||||||
|
index = parseInt(nameIndex, 10);
|
||||||
|
}
|
||||||
|
uniqueName = baseName;
|
||||||
|
}
|
||||||
|
|
||||||
while (
|
while (
|
||||||
nodeNames.indexOf(uniqueName) !== -1 ||
|
nodeNames.includes(uniqueName) ||
|
||||||
additinalUsedNames.indexOf(uniqueName) !== -1
|
additinalUsedNames.includes(uniqueName)
|
||||||
) {
|
) {
|
||||||
uniqueName = originalName + index++;
|
uniqueName = baseName + (index++);
|
||||||
}
|
}
|
||||||
|
|
||||||
return uniqueName;
|
return uniqueName;
|
||||||
|
|
Loading…
Reference in a new issue