mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
fix(editor): Sort start start nodes for manual execution by Y position (#15254)
This commit is contained in:
@@ -822,4 +822,37 @@ describe('useRunWorkflow({ router })', () => {
|
|||||||
await waitFor(() => expect(markStoppedSpy).toHaveBeenCalled());
|
await waitFor(() => expect(markStoppedSpy).toHaveBeenCalled());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('sortNodesByYPosition()', () => {
|
||||||
|
const getNodeUi = (name: string, position: [number, number]) => {
|
||||||
|
return {
|
||||||
|
name,
|
||||||
|
position,
|
||||||
|
type: 'n8n-nodes-base.test',
|
||||||
|
typeVersion: 1,
|
||||||
|
id: name,
|
||||||
|
parameters: {},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
it('should sort nodes by Y position in ascending order', () => {
|
||||||
|
const { sortNodesByYPosition } = useRunWorkflow({ router });
|
||||||
|
|
||||||
|
const topNode = 'topNode';
|
||||||
|
const middleNode = 'middleNode';
|
||||||
|
const bottomNode = 'bottomNode';
|
||||||
|
|
||||||
|
vi.mocked(workflowsStore.getNodeByName).mockImplementation((name) => {
|
||||||
|
if (name === topNode) return getNodeUi(topNode, [100, 50]);
|
||||||
|
if (name === middleNode) return getNodeUi(middleNode, [200, 200]);
|
||||||
|
if (name === bottomNode) return getNodeUi(bottomNode, [150, 350]);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Test with different order of input nodes
|
||||||
|
const result = sortNodesByYPosition([bottomNode, topNode, middleNode]);
|
||||||
|
|
||||||
|
// Should be sorted by Y position (top to bottom)
|
||||||
|
expect(result).toEqual([topNode, middleNode, bottomNode]);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -60,6 +60,20 @@ export function useRunWorkflow(useRunWorkflowOpts: { router: ReturnType<typeof u
|
|||||||
const executionsStore = useExecutionsStore();
|
const executionsStore = useExecutionsStore();
|
||||||
const { dirtinessByName } = useNodeDirtiness();
|
const { dirtinessByName } = useNodeDirtiness();
|
||||||
|
|
||||||
|
function sortNodesByYPosition(nodes: string[]) {
|
||||||
|
return [...nodes].sort((a, b) => {
|
||||||
|
const nodeA = workflowsStore.getNodeByName(a)?.position ?? [0, 0];
|
||||||
|
const nodeB = workflowsStore.getNodeByName(b)?.position ?? [0, 0];
|
||||||
|
|
||||||
|
const nodeAYPosition = nodeA[1];
|
||||||
|
const nodeBYPosition = nodeB[1];
|
||||||
|
|
||||||
|
if (nodeAYPosition === nodeBYPosition) return 0;
|
||||||
|
|
||||||
|
return nodeAYPosition > nodeBYPosition ? 1 : -1;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Starts to execute a workflow on server
|
// Starts to execute a workflow on server
|
||||||
async function runWorkflowApi(runData: IStartRunData): Promise<IExecutionPushResponse> {
|
async function runWorkflowApi(runData: IStartRunData): Promise<IExecutionPushResponse> {
|
||||||
if (!pushConnectionStore.isConnected) {
|
if (!pushConnectionStore.isConnected) {
|
||||||
@@ -223,7 +237,7 @@ export function useRunWorkflow(useRunWorkflowOpts: { router: ReturnType<typeof u
|
|||||||
const version = settingsStore.partialExecutionVersion;
|
const version = settingsStore.partialExecutionVersion;
|
||||||
|
|
||||||
// TODO: this will be redundant once we cleanup the partial execution v1
|
// TODO: this will be redundant once we cleanup the partial execution v1
|
||||||
const startNodes: StartNodeData[] = startNodeNames.map((name) => {
|
const startNodes: StartNodeData[] = sortNodesByYPosition(startNodeNames).map((name) => {
|
||||||
// Find for each start node the source data
|
// Find for each start node the source data
|
||||||
let sourceData = get(runData, [name, 0, 'source', 0], null);
|
let sourceData = get(runData, [name, 0, 'source', 0], null);
|
||||||
if (sourceData === null) {
|
if (sourceData === null) {
|
||||||
@@ -519,5 +533,6 @@ export function useRunWorkflow(useRunWorkflowOpts: { router: ReturnType<typeof u
|
|||||||
runWorkflowApi,
|
runWorkflowApi,
|
||||||
stopCurrentExecution,
|
stopCurrentExecution,
|
||||||
stopWaitingForWebhook,
|
stopWaitingForWebhook,
|
||||||
|
sortNodesByYPosition,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user