feat(editor): Add Python to Code actions (#18668)

This commit is contained in:
Iván Ovejero
2025-08-26 14:29:50 +02:00
committed by GitHub
parent b73f2393b4
commit 38f25d74eb
16 changed files with 185 additions and 59 deletions

View File

@@ -185,6 +185,11 @@ export const useActions = () => {
actionName: actionData.name,
};
if (typeof actionData.value.language === 'string') {
result.parameters = { language: actionData.value.language };
return result;
}
if (
typeof actionData.value.resource === 'string' ||
typeof actionData.value.operation === 'string'

View File

@@ -54,6 +54,25 @@ const customNodeActionsParsers: {
}),
);
},
['n8n-nodes-base.code']: (matchedProperty, nodeTypeDescription) => {
if (matchedProperty.name !== 'language') return;
const languageOptions = matchedProperty.options as INodePropertyOptions[] | undefined;
if (!languageOptions) return;
return languageOptions.map(
(option): ActionTypeDescription => ({
...getNodeTypeBase(nodeTypeDescription),
actionKey: `language_${option.value}`,
displayName: `Code in ${option.name}`,
description: `Run custom ${option.name} code`,
displayOptions: matchedProperty.displayOptions,
values: {
language: option.value,
},
}),
);
},
};
function getNodeTypeBase(nodeTypeDescription: INodeTypeDescription, label?: string) {
@@ -79,6 +98,21 @@ function getNodeTypeBase(nodeTypeDescription: INodeTypeDescription, label?: stri
function operationsCategory(nodeTypeDescription: INodeTypeDescription): ActionTypeDescription[] {
if (nodeTypeDescription.properties.find((property) => property.name === 'resource')) return [];
if (nodeTypeDescription.name === 'n8n-nodes-base.code') {
const languageProperty = nodeTypeDescription.properties.find(
(property) =>
property.name === 'language' && property.displayOptions?.show?.['@version']?.[0] === 2,
);
if (languageProperty) {
const customParsedItems = customNodeActionsParsers[nodeTypeDescription.name]?.(
languageProperty,
nodeTypeDescription,
);
if (customParsedItems) return customParsedItems;
}
}
const matchedProperty = nodeTypeDescription.properties.find(
(property) => property.name?.toLowerCase() === 'operation',
);