mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-11 12:57:29 -08:00
🔀 Merge suffix fix
This commit is contained in:
commit
e1ac523797
|
@ -825,13 +825,15 @@ export const store = new Vuex.Store({
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Getter for node display names ending with a number: `'S3'`, `'MSG91'`, etc.
|
* Getter for node default names ending with a number: `'S3'`, `'Magento 2'`, etc.
|
||||||
*/
|
*/
|
||||||
nativelyNumberSuffixedNodeNames: (_, getters): string[] => {
|
nativelyNumberSuffixedDefaults: (_, getters): string[] => {
|
||||||
const allNodeTypes: INodeTypeDescription[] = getters.allNodeTypes;
|
const { allNodeTypes } = getters as {
|
||||||
|
allNodeTypes: Array<INodeTypeDescription & { defaults: { name: string } }>;
|
||||||
|
};
|
||||||
|
|
||||||
return allNodeTypes.reduce<string[]>((acc, cur) => {
|
return allNodeTypes.reduce<string[]>((acc, cur) => {
|
||||||
if (/\d$/.test(cur.displayName)) acc.push(cur.displayName);
|
if (/\d$/.test(cur.defaults.name)) acc.push(cur.defaults.name);
|
||||||
return acc;
|
return acc;
|
||||||
}, []);
|
}, []);
|
||||||
},
|
},
|
||||||
|
|
|
@ -270,6 +270,7 @@ export default mixins(
|
||||||
defaultLocale (): string {
|
defaultLocale (): string {
|
||||||
return this.$store.getters.defaultLocale;
|
return this.$store.getters.defaultLocale;
|
||||||
},
|
},
|
||||||
|
...mapGetters(['nativelyNumberSuffixedDefaults']),
|
||||||
activeNode (): INodeUi | null {
|
activeNode (): INodeUi | null {
|
||||||
return this.$store.getters.activeNode;
|
return this.$store.getters.activeNode;
|
||||||
},
|
},
|
||||||
|
@ -1265,7 +1266,11 @@ export default mixins(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if node-name is unique else find one that is
|
// Check if node-name is unique else find one that is
|
||||||
newNodeData.name = CanvasHelpers.getUniqueNodeName(this.$store.getters.allNodes, newNodeData.name);
|
newNodeData.name = CanvasHelpers.getUniqueNodeName({
|
||||||
|
nodes: this.$store.getters.allNodes,
|
||||||
|
originalName: newNodeData.name,
|
||||||
|
nativelyNumberSuffixed: this.nativelyNumberSuffixedDefaults,
|
||||||
|
});
|
||||||
|
|
||||||
if (nodeTypeData.webhooks && nodeTypeData.webhooks.length) {
|
if (nodeTypeData.webhooks && nodeTypeData.webhooks.length) {
|
||||||
newNodeData.webhookId = uuidv4();
|
newNodeData.webhookId = uuidv4();
|
||||||
|
@ -1857,7 +1862,11 @@ export default mixins(
|
||||||
const newNodeData = JSON.parse(JSON.stringify(this.getNodeDataToSave(node)));
|
const newNodeData = JSON.parse(JSON.stringify(this.getNodeDataToSave(node)));
|
||||||
|
|
||||||
// Check if node-name is unique else find one that is
|
// Check if node-name is unique else find one that is
|
||||||
newNodeData.name = CanvasHelpers.getUniqueNodeName(this.$store.getters.allNodes, newNodeData.name);
|
newNodeData.name = CanvasHelpers.getUniqueNodeName({
|
||||||
|
nodes: this.$store.getters.allNodes,
|
||||||
|
originalName: newNodeData.name,
|
||||||
|
nativelyNumberSuffixed: this.nativelyNumberSuffixedDefaults,
|
||||||
|
});
|
||||||
|
|
||||||
newNodeData.position = CanvasHelpers.getNewNodePosition(
|
newNodeData.position = CanvasHelpers.getNewNodePosition(
|
||||||
this.nodes,
|
this.nodes,
|
||||||
|
@ -2101,7 +2110,11 @@ export default mixins(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Check if node-name is unique else find one that is
|
// Check if node-name is unique else find one that is
|
||||||
newName = CanvasHelpers.getUniqueNodeName(this.$store.getters.allNodes, newName);
|
newName = CanvasHelpers.getUniqueNodeName({
|
||||||
|
nodes: this.$store.getters.allNodes,
|
||||||
|
originalName: newName,
|
||||||
|
nativelyNumberSuffixed: this.nativelyNumberSuffixedDefaults,
|
||||||
|
});
|
||||||
|
|
||||||
// Rename the node and update the connections
|
// Rename the node and update the connections
|
||||||
const workflow = this.getWorkflow(undefined, undefined, true);
|
const workflow = this.getWorkflow(undefined, undefined, true);
|
||||||
|
@ -2320,7 +2333,12 @@ export default mixins(
|
||||||
}
|
}
|
||||||
|
|
||||||
oldName = node.name;
|
oldName = node.name;
|
||||||
newName = CanvasHelpers.getUniqueNodeName(this.$store.getters.allNodes, node.name, newNodeNames);
|
newName = CanvasHelpers.getUniqueNodeName({
|
||||||
|
nodes: this.$store.getters.allNodes,
|
||||||
|
originalName: node.name,
|
||||||
|
additionalUsedNames: newNodeNames,
|
||||||
|
nativelyNumberSuffixed: this.nativelyNumberSuffixedDefaults,
|
||||||
|
});
|
||||||
|
|
||||||
newNodeNames.push(newName);
|
newNodeNames.push(newName);
|
||||||
nodeNameTable[oldName] = newName;
|
nodeNameTable[oldName] = newName;
|
||||||
|
|
|
@ -597,9 +597,19 @@ export const getZoomToFit = (nodes: INodeUi[]): {offset: XYPosition, zoomLevel:
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getUniqueNodeName = (nodes: INodeUi[], originalName: string, additinalUsedNames?: string[]) => {
|
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
|
// Check if node-name is unique else find one that is
|
||||||
additinalUsedNames = additinalUsedNames || [];
|
additionalUsedNames = additionalUsedNames || [];
|
||||||
|
|
||||||
// Get all the names of the current nodes
|
// Get all the names of the current nodes
|
||||||
const nodeNames = nodes.map((node: INodeUi) => {
|
const nodeNames = nodes.map((node: INodeUi) => {
|
||||||
|
@ -607,31 +617,42 @@ export const getUniqueNodeName = (nodes: INodeUi[], originalName: string, additi
|
||||||
});
|
});
|
||||||
|
|
||||||
// Check first if the current name is already unique
|
// Check first if the current name is already unique
|
||||||
if (!nodeNames.includes(originalName) && !additinalUsedNames.includes(originalName)) {
|
if (!nodeNames.includes(originalName) && !additionalUsedNames.includes(originalName)) {
|
||||||
return originalName;
|
return originalName;
|
||||||
}
|
}
|
||||||
|
|
||||||
const nameMatch = originalName.match(/(.*\D+)(\d*)/);
|
const found = nativelyNumberSuffixed.find((n) => originalName.startsWith(n));
|
||||||
|
|
||||||
let ignore, baseName, nameIndex, uniqueName;
|
let ignore, baseName, nameIndex, uniqueName;
|
||||||
let index = 1;
|
let index = 1;
|
||||||
|
|
||||||
if (nameMatch === null) {
|
if (found) {
|
||||||
// Name is only a number
|
nameIndex = originalName.split(found).pop();
|
||||||
index = parseInt(originalName, 10);
|
if (nameIndex) {
|
||||||
baseName = '';
|
|
||||||
uniqueName = baseName + index;
|
|
||||||
} else {
|
|
||||||
// Name is string or string/number combination
|
|
||||||
[ignore, baseName, nameIndex] = nameMatch;
|
|
||||||
if (nameIndex !== '') {
|
|
||||||
index = parseInt(nameIndex, 10);
|
index = parseInt(nameIndex, 10);
|
||||||
}
|
}
|
||||||
uniqueName = baseName;
|
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 (
|
while (
|
||||||
nodeNames.includes(uniqueName) ||
|
nodeNames.includes(uniqueName) ||
|
||||||
additinalUsedNames.includes(uniqueName)
|
additionalUsedNames.includes(uniqueName)
|
||||||
) {
|
) {
|
||||||
uniqueName = baseName + (index++);
|
uniqueName = baseName + (index++);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue