mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-02 07:01:30 -08:00
🐛 Fix issue that expressions always read from output with index 0 even
when the nodes with the expression were connected to a different one
This commit is contained in:
parent
3d80d9602e
commit
00f00f9cbe
|
@ -15,9 +15,9 @@
|
||||||
import Vue from 'vue';
|
import Vue from 'vue';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
GenericValue,
|
||||||
IContextObject,
|
IContextObject,
|
||||||
IDataObject,
|
IDataObject,
|
||||||
GenericValue,
|
|
||||||
IRun,
|
IRun,
|
||||||
IRunData,
|
IRunData,
|
||||||
IRunExecutionData,
|
IRunExecutionData,
|
||||||
|
@ -28,6 +28,7 @@ import {
|
||||||
import VariableSelectorItem from '@/components/VariableSelectorItem.vue';
|
import VariableSelectorItem from '@/components/VariableSelectorItem.vue';
|
||||||
import {
|
import {
|
||||||
IExecutionResponse,
|
IExecutionResponse,
|
||||||
|
INodeUi,
|
||||||
IVariableItemSelected,
|
IVariableItemSelected,
|
||||||
IVariableSelectorOption,
|
IVariableSelectorOption,
|
||||||
} from '@/Interface';
|
} from '@/Interface';
|
||||||
|
@ -417,7 +418,12 @@ export default mixins(
|
||||||
getFilterResults (filterText: string, itemIndex: number): IVariableSelectorOption[] {
|
getFilterResults (filterText: string, itemIndex: number): IVariableSelectorOption[] {
|
||||||
const inputName = 'main';
|
const inputName = 'main';
|
||||||
|
|
||||||
const activeNode = this.$store.getters.activeNode;
|
const activeNode: INodeUi | null = this.$store.getters.activeNode;
|
||||||
|
|
||||||
|
if (activeNode === null) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
const executionData = this.$store.getters.getWorkflowExecution as IExecutionResponse | null;
|
const executionData = this.$store.getters.getWorkflowExecution as IExecutionResponse | null;
|
||||||
let parentNode = this.workflow.getParentNodes(activeNode.name, inputName, 1);
|
let parentNode = this.workflow.getParentNodes(activeNode.name, inputName, 1);
|
||||||
let runData = this.$store.getters.getWorkflowRunData as IRunData | null;
|
let runData = this.$store.getters.getWorkflowRunData as IRunData | null;
|
||||||
|
@ -453,7 +459,14 @@ export default mixins(
|
||||||
|
|
||||||
if (parentNode.length) {
|
if (parentNode.length) {
|
||||||
// If the node has an input node add the input data
|
// If the node has an input node add the input data
|
||||||
tempOutputData = this.getNodeOutputData(runData, parentNode[0], filterText, itemIndex) as IVariableSelectorOption[];
|
|
||||||
|
// Check from which output to read the data.
|
||||||
|
// Depends on how the nodes are connected.
|
||||||
|
// (example "IF" node. If node is connected to "true" or to "false" output)
|
||||||
|
const outputIndex = this.workflow.getNodeConnectionOutputIndex(activeNode.name, parentNode[0], 'main');
|
||||||
|
|
||||||
|
tempOutputData = this.getNodeOutputData(runData, parentNode[0], filterText, itemIndex, 0, 'main', outputIndex) as IVariableSelectorOption[];
|
||||||
|
|
||||||
if (tempOutputData) {
|
if (tempOutputData) {
|
||||||
currentNodeData.push(
|
currentNodeData.push(
|
||||||
{
|
{
|
||||||
|
|
|
@ -456,9 +456,7 @@ export class Workflow {
|
||||||
return currentHighest;
|
return currentHighest;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (checkedNodes === undefined) {
|
checkedNodes = checkedNodes || [];
|
||||||
checkedNodes = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (checkedNodes!.includes(nodeName)) {
|
if (checkedNodes!.includes(nodeName)) {
|
||||||
// Node got checked already before
|
// Node got checked already before
|
||||||
|
@ -537,9 +535,7 @@ export class Workflow {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (checkedNodes === undefined) {
|
checkedNodes = checkedNodes || [];
|
||||||
checkedNodes = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (checkedNodes!.includes(nodeName)) {
|
if (checkedNodes!.includes(nodeName)) {
|
||||||
// Node got checked already before
|
// Node got checked already before
|
||||||
|
@ -587,6 +583,70 @@ export class Workflow {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns via which output of the parent-node the node
|
||||||
|
* is connected to.
|
||||||
|
*
|
||||||
|
* @param {string} nodeName The node to check how it is connected with parent node
|
||||||
|
* @param {string} parentNodeName The parent node to get the output index of
|
||||||
|
* @param {string} [type='main']
|
||||||
|
* @param {*} [depth=-1]
|
||||||
|
* @param {string[]} [checkedNodes]
|
||||||
|
* @returns {(number | undefined)}
|
||||||
|
* @memberof Workflow
|
||||||
|
*/
|
||||||
|
getNodeConnectionOutputIndex(nodeName: string, parentNodeName: string, type = 'main', depth = -1, checkedNodes?: string[]): number | undefined {
|
||||||
|
depth = depth === -1 ? -1 : depth;
|
||||||
|
const newDepth = depth === -1 ? depth : depth - 1;
|
||||||
|
if (depth === 0) {
|
||||||
|
// Reached max depth
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.connectionsByDestinationNode.hasOwnProperty(nodeName)) {
|
||||||
|
// Node does not have incoming connections
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.connectionsByDestinationNode[nodeName].hasOwnProperty(type)) {
|
||||||
|
// Node does not have incoming connections of given type
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
checkedNodes = checkedNodes || [];
|
||||||
|
|
||||||
|
if (checkedNodes!.includes(nodeName)) {
|
||||||
|
// Node got checked already before
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
checkedNodes!.push(nodeName);
|
||||||
|
|
||||||
|
let outputIndex: number | undefined;
|
||||||
|
for (const connectionsByIndex of this.connectionsByDestinationNode[nodeName][type]) {
|
||||||
|
for (const connection of connectionsByIndex) {
|
||||||
|
if (parentNodeName === connection.node) {
|
||||||
|
return connection.index;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (checkedNodes!.includes(connection.node)) {
|
||||||
|
// Node got checked already before
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
outputIndex = this.getNodeConnectionOutputIndex(connection.node, parentNodeName, type, newDepth, checkedNodes);
|
||||||
|
|
||||||
|
if (outputIndex !== undefined) {
|
||||||
|
return outputIndex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolves parameter value of parameter in webhook description
|
* Resolves parameter value of parameter in webhook description
|
||||||
*
|
*
|
||||||
|
|
|
@ -150,9 +150,20 @@ export class WorkflowDataProxy {
|
||||||
throw new Error(`No data found from "main" input.`);
|
throw new Error(`No data found from "main" input.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Currently it is only possible to reference data from the first input
|
// Check from which output to read the data.
|
||||||
// so we hardcode it.
|
// Depends on how the nodes are connected.
|
||||||
executionData = taskData.main[0] as INodeExecutionData[];
|
// (example "IF" node. If node is connected to "true" or to "false" output)
|
||||||
|
const outputIndex = that.workflow.getNodeConnectionOutputIndex(that.activeNodeName, nodeName, 'main');
|
||||||
|
|
||||||
|
if (outputIndex === undefined) {
|
||||||
|
throw new Error(`The node "${that.activeNodeName}" is not connected with node "${nodeName}" so no data can get returned from it.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (taskData.main.length < outputIndex) {
|
||||||
|
throw new Error(`No data found from "main" input with index "${outputIndex}" via which node is connected with.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
executionData = taskData.main[outputIndex] as INodeExecutionData[];
|
||||||
} else {
|
} else {
|
||||||
// Short syntax got used to return data from active node
|
// Short syntax got used to return data from active node
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue