mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-23 11:44:06 -08:00
⚡ Integrate number suffix fix
This commit is contained in:
parent
e1ac523797
commit
0baace0a5c
|
@ -196,21 +196,14 @@ export default mixins(externalHooks, nodeBase, nodeHelpers, renderText, workflow
|
|||
return this.$shortNodeType(this.data.type);
|
||||
},
|
||||
nodeTitle (): string {
|
||||
const node = this.data;
|
||||
|
||||
const nodeName = this.$headerText({
|
||||
key: `headers.${this.$shortNodeType(node.type)}.displayName`,
|
||||
fallback: node.name,
|
||||
});
|
||||
|
||||
if (!/\d$/.test(node.name)) return nodeName;
|
||||
|
||||
const nativeDuplicateSuffix = this.getDuplicateSuffix(node, { fromNative: true });
|
||||
|
||||
if (nativeDuplicateSuffix) return nodeName + nativeDuplicateSuffix;
|
||||
|
||||
return nodeName + this.getDuplicateSuffix(node, { fromStandard: true });
|
||||
if (this.data.name === 'Start') {
|
||||
return this.$headerText({
|
||||
key: `headers.start.displayName`,
|
||||
fallback: 'Start',
|
||||
});
|
||||
}
|
||||
|
||||
return this.data.name;
|
||||
},
|
||||
waiting (): string | undefined {
|
||||
const workflowExecution = this.$store.getters.getWorkflowExecution;
|
||||
|
@ -343,34 +336,6 @@ export default mixins(externalHooks, nodeBase, nodeHelpers, renderText, workflow
|
|||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Extract the duplicate number suffix from a node name:
|
||||
* - from a node name natively ending in a number, e.g. `'S31'` → `'1'`
|
||||
* - from a standard node name, e.g. `'GitHub1'` → `'1'`
|
||||
*/
|
||||
getDuplicateSuffix(
|
||||
node: INodeUi,
|
||||
{ fromNative, fromStandard }: { fromNative?: true; fromStandard?: true; },
|
||||
) {
|
||||
if (fromNative) {
|
||||
const { nativelyNumberSuffixedNodeNames: natives } = this.$store.getters;
|
||||
const found = natives.find((native: string) => node.name.includes(native));
|
||||
|
||||
if (!found) return null;
|
||||
|
||||
return node.name.split(found).pop()!;
|
||||
}
|
||||
|
||||
if (fromStandard) {
|
||||
const match = node.name.match(/(.*)(?<duplicateSuffix>\d)$/);
|
||||
if (!match || !match.groups || !match.groups.duplicateSuffix) return null;
|
||||
|
||||
return match.groups.duplicateSuffix;
|
||||
}
|
||||
|
||||
throw new Error('Either "fromNative" or "fromStandard" must be specified');
|
||||
},
|
||||
|
||||
setNodeActive () {
|
||||
this.$store.commit('setActiveNode', this.data.name);
|
||||
},
|
||||
|
|
|
@ -270,6 +270,9 @@ export default mixins(
|
|||
defaultLocale (): string {
|
||||
return this.$store.getters.defaultLocale;
|
||||
},
|
||||
englishLocale(): boolean {
|
||||
return this.defaultLocale === 'en';
|
||||
},
|
||||
...mapGetters(['nativelyNumberSuffixedDefaults']),
|
||||
activeNode (): INodeUi | null {
|
||||
return this.$store.getters.activeNode;
|
||||
|
@ -354,6 +357,76 @@ export default mixins(
|
|||
this.$store.commit('setWorkflowExecutionData', null);
|
||||
this.updateNodesExecutionIssues();
|
||||
},
|
||||
translateName(type: string, originalName: string) {
|
||||
return this.$headerText({
|
||||
key: `headers.${this.$shortNodeType(type)}.displayName`,
|
||||
fallback: originalName,
|
||||
});
|
||||
},
|
||||
getUniqueNodeName({
|
||||
originalName,
|
||||
additionalUsedNames = [],
|
||||
type = '',
|
||||
} : {
|
||||
originalName: string,
|
||||
additionalUsedNames?: string[],
|
||||
type?: string,
|
||||
}) {
|
||||
const allNodeNamesOnCanvas = this.$store.getters.allNodes.map((n: INodeUi) => n.name);
|
||||
originalName = this.englishLocale ? originalName : this.translateName(type, originalName);
|
||||
|
||||
if (
|
||||
!allNodeNamesOnCanvas.includes(originalName) &&
|
||||
!additionalUsedNames.includes(originalName)
|
||||
) {
|
||||
return originalName; // already unique
|
||||
}
|
||||
|
||||
let natives: string[] = this.nativelyNumberSuffixedDefaults;
|
||||
natives = this.englishLocale ? natives : natives.map(name => {
|
||||
const type = name.toLowerCase().replace('_', '');
|
||||
return this.translateName(type, name);
|
||||
});
|
||||
|
||||
const found = natives.find((n) => originalName.startsWith(n));
|
||||
|
||||
let ignore, baseName, nameIndex, uniqueName;
|
||||
let index = 1;
|
||||
|
||||
if (found) {
|
||||
// name natively ends with number
|
||||
nameIndex = originalName.split(found).pop();
|
||||
if (nameIndex) {
|
||||
index = parseInt(nameIndex, 10);
|
||||
}
|
||||
baseName = uniqueName = originalName;
|
||||
} 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 = originalName;
|
||||
}
|
||||
}
|
||||
|
||||
while (
|
||||
allNodeNamesOnCanvas.includes(uniqueName) ||
|
||||
additionalUsedNames.includes(uniqueName)
|
||||
) {
|
||||
uniqueName = baseName + (index++);
|
||||
}
|
||||
|
||||
return uniqueName;
|
||||
},
|
||||
openNodeCreator (source: string) {
|
||||
this.createNodeActive = true;
|
||||
this.$externalHooks().run('nodeView.createNodeActiveChanged', { source, createNodeActive: this.createNodeActive });
|
||||
|
@ -1265,11 +1338,11 @@ export default mixins(
|
|||
newNodeData.position = CanvasHelpers.getNewNodePosition(this.nodes, this.lastClickPosition);
|
||||
}
|
||||
|
||||
|
||||
// Check if node-name is unique else find one that is
|
||||
newNodeData.name = CanvasHelpers.getUniqueNodeName({
|
||||
nodes: this.$store.getters.allNodes,
|
||||
newNodeData.name = this.getUniqueNodeName({
|
||||
originalName: newNodeData.name,
|
||||
nativelyNumberSuffixed: this.nativelyNumberSuffixedDefaults,
|
||||
type: newNodeData.type,
|
||||
});
|
||||
|
||||
if (nodeTypeData.webhooks && nodeTypeData.webhooks.length) {
|
||||
|
@ -1862,10 +1935,9 @@ export default mixins(
|
|||
const newNodeData = JSON.parse(JSON.stringify(this.getNodeDataToSave(node)));
|
||||
|
||||
// Check if node-name is unique else find one that is
|
||||
newNodeData.name = CanvasHelpers.getUniqueNodeName({
|
||||
nodes: this.$store.getters.allNodes,
|
||||
newNodeData.name = this.getUniqueNodeName({
|
||||
originalName: newNodeData.name,
|
||||
nativelyNumberSuffixed: this.nativelyNumberSuffixedDefaults,
|
||||
type: newNodeData.type,
|
||||
});
|
||||
|
||||
newNodeData.position = CanvasHelpers.getNewNodePosition(
|
||||
|
@ -2110,10 +2182,8 @@ export default mixins(
|
|||
return;
|
||||
}
|
||||
// Check if node-name is unique else find one that is
|
||||
newName = CanvasHelpers.getUniqueNodeName({
|
||||
nodes: this.$store.getters.allNodes,
|
||||
newName = this.getUniqueNodeName({
|
||||
originalName: newName,
|
||||
nativelyNumberSuffixed: this.nativelyNumberSuffixedDefaults,
|
||||
});
|
||||
|
||||
// Rename the node and update the connections
|
||||
|
@ -2333,11 +2403,10 @@ export default mixins(
|
|||
}
|
||||
|
||||
oldName = node.name;
|
||||
newName = CanvasHelpers.getUniqueNodeName({
|
||||
nodes: this.$store.getters.allNodes,
|
||||
newName = this.getUniqueNodeName({
|
||||
originalName: node.name,
|
||||
additionalUsedNames: newNodeNames,
|
||||
nativelyNumberSuffixed: this.nativelyNumberSuffixedDefaults,
|
||||
type: node.type,
|
||||
});
|
||||
|
||||
newNodeNames.push(newName);
|
||||
|
|
|
@ -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) {
|
||||
|
|
8
packages/nodes-base/nodes/Signl4/translations/de.json
Normal file
8
packages/nodes-base/nodes/Signl4/translations/de.json
Normal file
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"signl4": {
|
||||
"header": {
|
||||
"displayName": "🇩🇪 SIGNL4",
|
||||
"description": "🇩🇪 Some description"
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue