Allow to load sibling parameters in loadOptionsMethod

This commit is contained in:
Jan Oberhauser 2021-05-16 18:16:24 -05:00
parent a68145a88b
commit 002f53a4af
6 changed files with 20 additions and 14 deletions

View file

@ -717,6 +717,7 @@ class App {
// get generated dynamically // get generated dynamically
this.app.get(`/${this.restEndpoint}/node-parameter-options`, ResponseHelper.send(async (req: express.Request, res: express.Response): Promise<INodePropertyOptions[]> => { this.app.get(`/${this.restEndpoint}/node-parameter-options`, ResponseHelper.send(async (req: express.Request, res: express.Response): Promise<INodePropertyOptions[]> => {
const nodeType = req.query.nodeType as string; const nodeType = req.query.nodeType as string;
const path = req.query.path as string;
let credentials: INodeCredentials | undefined = undefined; let credentials: INodeCredentials | undefined = undefined;
const currentNodeParameters = JSON.parse('' + req.query.currentNodeParameters) as INodeParameters; const currentNodeParameters = JSON.parse('' + req.query.currentNodeParameters) as INodeParameters;
if (req.query.credentials !== undefined) { if (req.query.credentials !== undefined) {
@ -726,7 +727,7 @@ class App {
const nodeTypes = NodeTypes(); const nodeTypes = NodeTypes();
const loadDataInstance = new LoadNodeParameterOptions(nodeType, nodeTypes, JSON.parse('' + req.query.currentNodeParameters), credentials!); const loadDataInstance = new LoadNodeParameterOptions(nodeType, nodeTypes, path, JSON.parse('' + req.query.currentNodeParameters), credentials!);
const workflowData = loadDataInstance.getWorkflowData() as IWorkflowBase; const workflowData = loadDataInstance.getWorkflowData() as IWorkflowBase;
const workflowCredentials = await WorkflowCredentials(workflowData.nodes); const workflowCredentials = await WorkflowCredentials(workflowData.nodes);

View file

@ -18,10 +18,12 @@ const TEMP_WORKFLOW_NAME = 'Temp-Workflow';
export class LoadNodeParameterOptions { export class LoadNodeParameterOptions {
path: string;
workflow: Workflow; workflow: Workflow;
constructor(nodeTypeName: string, nodeTypes: INodeTypes, currentNodeParameters: INodeParameters, credentials?: INodeCredentials) { constructor(nodeTypeName: string, nodeTypes: INodeTypes, path: string, currentNodeParameters: INodeParameters, credentials?: INodeCredentials) {
this.path = path;
const nodeType = nodeTypes.getByName(nodeTypeName); const nodeType = nodeTypes.getByName(nodeTypeName);
if (nodeType === undefined) { if (nodeType === undefined) {
@ -89,7 +91,7 @@ export class LoadNodeParameterOptions {
throw new Error(`The node-type "${node!.type}" does not have the method "${methodName}" defined!`); throw new Error(`The node-type "${node!.type}" does not have the method "${methodName}" defined!`);
} }
const thisArgs = NodeExecuteFunctions.getLoadOptionsFunctions(this.workflow, node!, additionalData); const thisArgs = NodeExecuteFunctions.getLoadOptionsFunctions(this.workflow, node!, this.path, additionalData);
return nodeType!.methods.loadOptions[methodName].call(thisArgs); return nodeType!.methods.loadOptions[methodName].call(thisArgs);
} }

View file

@ -871,18 +871,20 @@ export function getExecuteSingleFunctions(workflow: Workflow, runExecutionData:
* @param {IWorkflowExecuteAdditionalData} additionalData * @param {IWorkflowExecuteAdditionalData} additionalData
* @returns {ILoadOptionsFunctions} * @returns {ILoadOptionsFunctions}
*/ */
export function getLoadOptionsFunctions(workflow: Workflow, node: INode, additionalData: IWorkflowExecuteAdditionalData): ILoadOptionsFunctions { export function getLoadOptionsFunctions(workflow: Workflow, node: INode, path: string, additionalData: IWorkflowExecuteAdditionalData): ILoadOptionsFunctions {
return ((workflow: Workflow, node: INode) => { return ((workflow: Workflow, node: INode, path: string) => {
const that = { const that = {
getCredentials(type: string): ICredentialDataDecryptedObject | undefined { getCredentials(type: string): ICredentialDataDecryptedObject | undefined {
return getCredentials(workflow, node, type, additionalData, 'internal'); return getCredentials(workflow, node, type, additionalData, 'internal');
}, },
getCurrentNodeParameter: (parameterName: string): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object | undefined => { getCurrentNodeParameter: (parameterPath: string): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object | undefined => {
const nodeParameters = additionalData.currentNodeParameters; const nodeParameters = additionalData.currentNodeParameters;
if (nodeParameters && nodeParameters[parameterName]) {
return nodeParameters[parameterName]; if (parameterPath.charAt(0) === '&') {
parameterPath = `${path.split('.').slice(1, -1).join('.')}.${parameterPath.slice(1)}`;
} }
return undefined;
return get(nodeParameters, parameterPath);
}, },
getCurrentNodeParameters: (): INodeParameters | undefined => { getCurrentNodeParameters: (): INodeParameters | undefined => {
return additionalData.currentNodeParameters; return additionalData.currentNodeParameters;
@ -915,7 +917,7 @@ export function getLoadOptionsFunctions(workflow: Workflow, node: INode, additio
}, },
}; };
return that; return that;
})(workflow, node); })(workflow, node, path);
} }

View file

@ -131,7 +131,7 @@ export interface IRestApi {
getSettings(): Promise<IN8nUISettings>; getSettings(): Promise<IN8nUISettings>;
getNodeTypes(): Promise<INodeTypeDescription[]>; getNodeTypes(): Promise<INodeTypeDescription[]>;
getNodesInformation(nodeList: string[]): Promise<INodeTypeDescription[]>; getNodesInformation(nodeList: string[]): Promise<INodeTypeDescription[]>;
getNodeParameterOptions(nodeType: string, methodName: string, currentNodeParameters: INodeParameters, credentials?: INodeCredentials): Promise<INodePropertyOptions[]>; getNodeParameterOptions(nodeType: string, path: string, methodName: string, currentNodeParameters: INodeParameters, credentials?: INodeCredentials): Promise<INodePropertyOptions[]>;
removeTestWebhook(workflowId: string): Promise<boolean>; removeTestWebhook(workflowId: string): Promise<boolean>;
runWorkflow(runData: IStartRunData): Promise<IExecutionPushResponse>; runWorkflow(runData: IStartRunData): Promise<IExecutionPushResponse>;
createNewWorkflow(sendData: IWorkflowData): Promise<IWorkflowDb>; createNewWorkflow(sendData: IWorkflowData): Promise<IWorkflowDb>;
@ -444,4 +444,4 @@ export interface ILinkMenuItemProperties {
icon: string; icon: string;
href: string; href: string;
newWindow?: boolean; newWindow?: boolean;
} }

View file

@ -484,7 +484,7 @@ export default mixins(
const resolvedNodeParameters = this.getResolveNodeParameters(currentNodeParameters); const resolvedNodeParameters = this.getResolveNodeParameters(currentNodeParameters);
try { try {
const options = await this.restApi().getNodeParameterOptions(this.node.type, this.remoteMethod, resolvedNodeParameters, this.node.credentials); const options = await this.restApi().getNodeParameterOptions(this.node.type, this.path, this.remoteMethod, resolvedNodeParameters, this.node.credentials);
this.remoteParameterOptions.push.apply(this.remoteParameterOptions, options); this.remoteParameterOptions.push.apply(this.remoteParameterOptions, options);
} catch (error) { } catch (error) {
this.remoteParameterOptionsLoadingIssues = error.message; this.remoteParameterOptionsLoadingIssues = error.message;

View file

@ -157,9 +157,10 @@ export const restApi = Vue.extend({
}, },
// Returns all the parameter options from the server // Returns all the parameter options from the server
getNodeParameterOptions: (nodeType: string, methodName: string, currentNodeParameters: INodeParameters, credentials?: INodeCredentials): Promise<INodePropertyOptions[]> => { getNodeParameterOptions: (nodeType: string, path: string, methodName: string, currentNodeParameters: INodeParameters, credentials?: INodeCredentials): Promise<INodePropertyOptions[]> => {
const sendData = { const sendData = {
nodeType, nodeType,
path,
methodName, methodName,
credentials, credentials,
currentNodeParameters, currentNodeParameters,