fix(editor): Fix schema view output index filtering (#18383)

This commit is contained in:
oleg
2025-08-15 13:39:00 +02:00
committed by GitHub
parent f5d514f991
commit 675bb50122
2 changed files with 64 additions and 5 deletions

View File

@@ -744,6 +744,52 @@ describe('VirtualSchema.vue', () => {
expect(container).toMatchSnapshot();
});
it('does not filter single-output connected nodes by outputIndex', async () => {
// This test verifies the fix for the issue where nodes with single output connections
// were incorrectly being filtered by the current node's outputIndex
const originalNodeHelpers = nodeHelpers.useNodeHelpers();
vi.spyOn(nodeHelpers, 'useNodeHelpers').mockImplementation(() => {
return {
...originalNodeHelpers,
getLastRunIndexWithData: vi.fn(() => 0),
hasNodeExecuted: vi.fn(() => true),
getNodeInputData: vi.fn((node, _, outputIndex) => {
// Switch node has data on output 0
if (node.name === 'If' && outputIndex === 0) {
return [{ json: { id: 1, name: 'John' } }, { json: { id: 2, name: 'Jane' } }];
}
// No data on output 1
if (node.name === 'If' && outputIndex === 1) {
return [];
}
return [];
}),
};
});
const { getAllByTestId } = renderComponent({
props: {
// If node is connected only via output 0 to the current node
nodes: [{ name: 'If', indicies: [0], depth: 2 }],
// Even though outputIndex is 1, the If node should still show its data
// because it only has a single connection (output 0)
outputIndex: 1,
},
});
await waitFor(() => {
const headers = getAllByTestId('run-data-schema-header');
expect(headers[0]).toHaveTextContent('If');
// Should show 2 items from output 0, not filtered by outputIndex: 1
expect(headers[0]).toHaveTextContent('2 items');
const items = getAllByTestId('run-data-schema-item');
// Should show the data from output 0
expect(items[0]).toHaveTextContent('id1');
expect(items[1]).toHaveTextContent('nameJohn');
});
});
it('renders schema for loop node done-branch with correct filtering', async () => {
// Mock customer datastore output - 6 customer items
const customerData = Array.from({ length: 6 }, (_, i) => ({

View File

@@ -117,11 +117,24 @@ const getNodeSchema = async (fullNode: INodeUi, connectedNode: IConnectedNode) =
}))
.filter(({ runIndex }) => runIndex !== -1);
// If outputIndex is specified, only use data from that specific output branch
const filteredOutputsWithData =
props.outputIndex !== undefined
? connectedOutputsWithData.filter(({ outputIndex }) => outputIndex === props.outputIndex)
: connectedOutputsWithData;
// For connected nodes with multiple outputs that connect to the current node,
// filter by outputIndex if it's specified and matches one of the connected outputs
// This ensures we show the correct branch when viewing multi-output nodes like SplitInBatches
let filteredOutputsWithData = connectedOutputsWithData;
// Only apply outputIndex filtering if:
// 1. outputIndex is specified
// 2. The node has multiple connected outputs
// 3. The specified outputIndex is one of the connected outputs
if (
props.outputIndex !== undefined &&
connectedOutputIndexes.length > 1 &&
connectedOutputIndexes.includes(props.outputIndex)
) {
filteredOutputsWithData = connectedOutputsWithData.filter(
({ outputIndex }) => outputIndex === props.outputIndex,
);
}
const nodeData = filteredOutputsWithData
.map(({ outputIndex, runIndex }) =>