From 7d3cae5639b26b32d170e516b72dbe782e25f4bb Mon Sep 17 00:00:00 2001 From: Csaba Tuncsik Date: Fri, 16 May 2025 14:41:08 +0200 Subject: [PATCH] fix(editor): Fix paired items after renaming a node (#15440) --- .../src/stores/workflows.store.test.ts | 84 +++++++++++++++++++ .../editor-ui/src/stores/workflows.store.ts | 12 ++- 2 files changed, 92 insertions(+), 4 deletions(-) diff --git a/packages/frontend/editor-ui/src/stores/workflows.store.test.ts b/packages/frontend/editor-ui/src/stores/workflows.store.test.ts index d599d51f2a4..409ce3523f4 100644 --- a/packages/frontend/editor-ui/src/stores/workflows.store.test.ts +++ b/packages/frontend/editor-ui/src/stores/workflows.store.test.ts @@ -990,6 +990,90 @@ describe('useWorkflowsStore', () => { ); }); }); + + describe('renameNodeSelectedAndExecution', () => { + it('should rename node and update execution data', () => { + const nodeName = 'Rename me'; + const newName = 'Renamed'; + + workflowsStore.workflowExecutionData = { + data: { + resultData: { + runData: { + "When clicking 'Test workflow'": [ + { + startTime: 1747389900668, + executionIndex: 0, + source: [], + hints: [], + executionTime: 1, + executionStatus: 'success', + data: {}, + }, + ], + [nodeName]: [ + { + startTime: 1747389900670, + executionIndex: 2, + source: [ + { + previousNode: "When clicking 'Test workflow'", + }, + ], + hints: [], + executionTime: 1, + executionStatus: 'success', + data: {}, + }, + ], + 'Edit Fields': [ + { + startTime: 1747389900671, + executionIndex: 3, + source: [ + { + previousNode: nodeName, + }, + ], + hints: [], + executionTime: 3, + executionStatus: 'success', + data: {}, + }, + ], + }, + pinData: {}, + lastNodeExecuted: 'Edit Fields', + }, + }, + } as unknown as IExecutionResponse; + + workflowsStore.addNode({ + parameters: {}, + id: '554c7ff4-7ee2-407c-8931-e34234c5056a', + name: nodeName, + type: 'n8n-nodes-base.set', + position: [680, 180], + typeVersion: 3.4, + }); + + workflowsStore.renameNodeSelectedAndExecution({ old: nodeName, new: newName }); + + expect(workflowsStore.nodeMetadata[nodeName]).not.toBeDefined(); + expect(workflowsStore.nodeMetadata[newName]).toEqual({}); + expect( + workflowsStore.workflowExecutionData?.data?.resultData.runData[nodeName], + ).not.toBeDefined(); + expect(workflowsStore.workflowExecutionData?.data?.resultData.runData[newName]).toBeDefined(); + expect( + workflowsStore.workflowExecutionData?.data?.resultData.runData['Edit Fields'][0].source, + ).toEqual([ + { + previousNode: newName, + }, + ]); + }); + }); }); function getMockEditFieldsNode() { diff --git a/packages/frontend/editor-ui/src/stores/workflows.store.ts b/packages/frontend/editor-ui/src/stores/workflows.store.ts index b4fb29446ad..4f649e83401 100644 --- a/packages/frontend/editor-ui/src/stores/workflows.store.ts +++ b/packages/frontend/editor-ui/src/stores/workflows.store.ts @@ -1180,10 +1180,7 @@ export const useWorkflowsStore = defineStore(STORES.WORKFLOWS, () => { // If node has any WorkflowResultData rename also that one that the data // does still get displayed also after node got renamed - if ( - workflowExecutionData.value?.data && - workflowExecutionData.value.data.resultData.runData.hasOwnProperty(nameData.old) - ) { + if (workflowExecutionData.value?.data?.resultData.runData[nameData.old]) { workflowExecutionData.value.data.resultData.runData[nameData.new] = workflowExecutionData.value.data.resultData.runData[nameData.old]; delete workflowExecutionData.value.data.resultData.runData[nameData.old]; @@ -1207,6 +1204,13 @@ export const useWorkflowsStore = defineStore(STORES.WORKFLOWS, () => { }, }; } + + Object.values(workflowExecutionData.value?.data?.resultData.runData ?? {}) + .flatMap((taskData) => taskData.map((task) => task.source).flat()) + .forEach((source) => { + if (!source || source.previousNode !== nameData.old) return; + source.previousNode = nameData.new; + }); } function setParentFolder(folder: IWorkflowDb['parentFolder']) {