feat(editor): Implement workflowSelector parameter type (#10482)

This commit is contained in:
oleg
2024-08-22 16:59:12 +02:00
committed by GitHub
parent a73b9a38d6
commit 84e54beac7
18 changed files with 954 additions and 140 deletions

View File

@@ -16,7 +16,7 @@ export class ExecuteWorkflow implements INodeType {
icon: 'fa:sign-in-alt',
iconColor: 'orange-red',
group: ['transform'],
version: 1,
version: [1, 1.1],
subtitle: '={{"Workflow: " + $parameter["workflowId"]}}',
description: 'Execute another workflow',
defaults: {
@@ -79,6 +79,7 @@ export class ExecuteWorkflow implements INodeType {
displayOptions: {
show: {
source: ['database'],
'@version': [1],
},
},
default: '',
@@ -87,7 +88,20 @@ export class ExecuteWorkflow implements INodeType {
description:
"Note on using an expression here: if this node is set to run once with all items, they will all be sent to the <em>same</em> workflow. That workflow's ID will be calculated by evaluating the expression for the <strong>first input item</strong>.",
},
{
displayName: 'Workflow',
name: 'workflowId',
type: 'workflowSelector',
displayOptions: {
show: {
source: ['database'],
'@version': [{ _cnd: { gte: 1.1 } }],
},
},
default: '',
required: true,
hint: "Note on using an expression here: if this node is set to run once with all items, they will all be sent to the <em>same</em> workflow. That workflow's ID will be calculated by evaluating the expression for the <strong>first input item</strong>.",
},
// ----------------------------------
// source:localFile
// ----------------------------------

View File

@@ -1,13 +1,27 @@
import { readFile as fsReadFile } from 'fs/promises';
import { NodeOperationError, jsonParse } from 'n8n-workflow';
import type { IExecuteFunctions, IExecuteWorkflowInfo, IRequestOptions } from 'n8n-workflow';
import type {
IExecuteFunctions,
IExecuteWorkflowInfo,
INodeParameterResourceLocator,
IRequestOptions,
} from 'n8n-workflow';
export async function getWorkflowInfo(this: IExecuteFunctions, source: string, itemIndex = 0) {
const workflowInfo: IExecuteWorkflowInfo = {};
const nodeVersion = this.getNode().typeVersion;
if (source === 'database') {
// Read workflow from database
workflowInfo.id = this.getNodeParameter('workflowId', itemIndex) as string;
if (nodeVersion === 1) {
workflowInfo.id = this.getNodeParameter('workflowId', itemIndex) as string;
} else {
const { value } = this.getNodeParameter(
'workflowId',
itemIndex,
{},
) as INodeParameterResourceLocator;
workflowInfo.id = value as string;
}
} else if (source === 'localFile') {
// Read workflow from filesystem
const workflowPath = this.getNodeParameter('workflowPath', itemIndex) as string;