Skip to content

fix(editor): Fix paired items after renaming a node #15440

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 16, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions packages/frontend/editor-ui/src/stores/workflows.store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
12 changes: 8 additions & 4 deletions packages/frontend/editor-ui/src/stores/workflows.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1190,10 +1190,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];
Expand All @@ -1217,6 +1214,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']) {
Expand Down
Loading