mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-24 04:04:06 -08:00
✨ Allow to load sibling parameters in loadOptionsMethod
This commit is contained in:
parent
a68145a88b
commit
002f53a4af
|
@ -717,6 +717,7 @@ class App {
|
|||
// get generated dynamically
|
||||
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 path = req.query.path as string;
|
||||
let credentials: INodeCredentials | undefined = undefined;
|
||||
const currentNodeParameters = JSON.parse('' + req.query.currentNodeParameters) as INodeParameters;
|
||||
if (req.query.credentials !== undefined) {
|
||||
|
@ -726,7 +727,7 @@ class App {
|
|||
|
||||
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 workflowCredentials = await WorkflowCredentials(workflowData.nodes);
|
||||
|
|
|
@ -18,10 +18,12 @@ const TEMP_WORKFLOW_NAME = 'Temp-Workflow';
|
|||
|
||||
|
||||
export class LoadNodeParameterOptions {
|
||||
path: string;
|
||||
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);
|
||||
|
||||
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!`);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -871,18 +871,20 @@ export function getExecuteSingleFunctions(workflow: Workflow, runExecutionData:
|
|||
* @param {IWorkflowExecuteAdditionalData} additionalData
|
||||
* @returns {ILoadOptionsFunctions}
|
||||
*/
|
||||
export function getLoadOptionsFunctions(workflow: Workflow, node: INode, additionalData: IWorkflowExecuteAdditionalData): ILoadOptionsFunctions {
|
||||
return ((workflow: Workflow, node: INode) => {
|
||||
export function getLoadOptionsFunctions(workflow: Workflow, node: INode, path: string, additionalData: IWorkflowExecuteAdditionalData): ILoadOptionsFunctions {
|
||||
return ((workflow: Workflow, node: INode, path: string) => {
|
||||
const that = {
|
||||
getCredentials(type: string): ICredentialDataDecryptedObject | undefined {
|
||||
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;
|
||||
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 => {
|
||||
return additionalData.currentNodeParameters;
|
||||
|
@ -915,7 +917,7 @@ export function getLoadOptionsFunctions(workflow: Workflow, node: INode, additio
|
|||
},
|
||||
};
|
||||
return that;
|
||||
})(workflow, node);
|
||||
})(workflow, node, path);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -131,7 +131,7 @@ export interface IRestApi {
|
|||
getSettings(): Promise<IN8nUISettings>;
|
||||
getNodeTypes(): 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>;
|
||||
runWorkflow(runData: IStartRunData): Promise<IExecutionPushResponse>;
|
||||
createNewWorkflow(sendData: IWorkflowData): Promise<IWorkflowDb>;
|
||||
|
@ -444,4 +444,4 @@ export interface ILinkMenuItemProperties {
|
|||
icon: string;
|
||||
href: string;
|
||||
newWindow?: boolean;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -484,7 +484,7 @@ export default mixins(
|
|||
const resolvedNodeParameters = this.getResolveNodeParameters(currentNodeParameters);
|
||||
|
||||
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);
|
||||
} catch (error) {
|
||||
this.remoteParameterOptionsLoadingIssues = error.message;
|
||||
|
|
|
@ -157,9 +157,10 @@ export const restApi = Vue.extend({
|
|||
},
|
||||
|
||||
// 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 = {
|
||||
nodeType,
|
||||
path,
|
||||
methodName,
|
||||
credentials,
|
||||
currentNodeParameters,
|
||||
|
|
Loading…
Reference in a new issue