mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 10:31:15 +00:00
⚡ Integrate number suffix fix
This commit is contained in:
@@ -597,69 +597,6 @@ export const getZoomToFit = (nodes: INodeUi[]): {offset: XYPosition, zoomLevel:
|
||||
};
|
||||
};
|
||||
|
||||
export const getUniqueNodeName = ({
|
||||
nodes,
|
||||
originalName,
|
||||
additionalUsedNames,
|
||||
nativelyNumberSuffixed,
|
||||
} : {
|
||||
nodes: INodeUi[],
|
||||
originalName: string,
|
||||
additionalUsedNames?: string[],
|
||||
nativelyNumberSuffixed: string[],
|
||||
}) => {
|
||||
// Check if node-name is unique else find one that is
|
||||
additionalUsedNames = additionalUsedNames || [];
|
||||
|
||||
// Get all the names of the current nodes
|
||||
const nodeNames = nodes.map((node: INodeUi) => {
|
||||
return node.name;
|
||||
});
|
||||
|
||||
// Check first if the current name is already unique
|
||||
if (!nodeNames.includes(originalName) && !additionalUsedNames.includes(originalName)) {
|
||||
return originalName;
|
||||
}
|
||||
|
||||
const found = nativelyNumberSuffixed.find((n) => originalName.startsWith(n));
|
||||
|
||||
let ignore, baseName, nameIndex, uniqueName;
|
||||
let index = 1;
|
||||
|
||||
if (found) {
|
||||
nameIndex = originalName.split(found).pop();
|
||||
if (nameIndex) {
|
||||
index = parseInt(nameIndex, 10);
|
||||
}
|
||||
baseName = uniqueName = found;
|
||||
} else {
|
||||
const nameMatch = originalName.match(/(.*\D+)(\d*)/);
|
||||
|
||||
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 (
|
||||
nodeNames.includes(uniqueName) ||
|
||||
additionalUsedNames.includes(uniqueName)
|
||||
) {
|
||||
uniqueName = baseName + (index++);
|
||||
}
|
||||
|
||||
return uniqueName;
|
||||
};
|
||||
|
||||
export const showDropConnectionState = (connection: Connection, targetEndpoint?: Endpoint) => {
|
||||
if (connection && connection.connector) {
|
||||
if (targetEndpoint) {
|
||||
|
||||
Reference in New Issue
Block a user