mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 10:31:15 +00:00
fix(editor): Fix node renaming in pinned data (#15482)
This commit is contained in:
@@ -1042,7 +1042,36 @@ describe('useWorkflowsStore', () => {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
pinData: {},
|
pinData: {
|
||||||
|
[nodeName]: [
|
||||||
|
{
|
||||||
|
json: {
|
||||||
|
foo: 'bar',
|
||||||
|
},
|
||||||
|
pairedItem: [
|
||||||
|
{
|
||||||
|
item: 0,
|
||||||
|
sourceOverwrite: {
|
||||||
|
previousNode: "When clicking 'Test workflow'",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
'Edit Fields': [
|
||||||
|
{
|
||||||
|
json: {
|
||||||
|
bar: 'foo',
|
||||||
|
},
|
||||||
|
pairedItem: {
|
||||||
|
item: 1,
|
||||||
|
sourceOverwrite: {
|
||||||
|
previousNode: nodeName,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
lastNodeExecuted: 'Edit Fields',
|
lastNodeExecuted: 'Edit Fields',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -1057,6 +1086,37 @@ describe('useWorkflowsStore', () => {
|
|||||||
typeVersion: 3.4,
|
typeVersion: 3.4,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
workflowsStore.workflow.pinData = {
|
||||||
|
[nodeName]: [
|
||||||
|
{
|
||||||
|
json: {
|
||||||
|
foo: 'bar',
|
||||||
|
},
|
||||||
|
pairedItem: {
|
||||||
|
item: 2,
|
||||||
|
sourceOverwrite: {
|
||||||
|
previousNode: "When clicking 'Test workflow'",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
'Edit Fields': [
|
||||||
|
{
|
||||||
|
json: {
|
||||||
|
bar: 'foo',
|
||||||
|
},
|
||||||
|
pairedItem: [
|
||||||
|
{
|
||||||
|
item: 3,
|
||||||
|
sourceOverwrite: {
|
||||||
|
previousNode: nodeName,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
workflowsStore.renameNodeSelectedAndExecution({ old: nodeName, new: newName });
|
workflowsStore.renameNodeSelectedAndExecution({ old: nodeName, new: newName });
|
||||||
|
|
||||||
expect(workflowsStore.nodeMetadata[nodeName]).not.toBeDefined();
|
expect(workflowsStore.nodeMetadata[nodeName]).not.toBeDefined();
|
||||||
@@ -1072,6 +1132,32 @@ describe('useWorkflowsStore', () => {
|
|||||||
previousNode: newName,
|
previousNode: newName,
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
expect(
|
||||||
|
workflowsStore.workflowExecutionData?.data?.resultData.pinData?.[nodeName],
|
||||||
|
).not.toBeDefined();
|
||||||
|
expect(
|
||||||
|
workflowsStore.workflowExecutionData?.data?.resultData.pinData?.[newName],
|
||||||
|
).toBeDefined();
|
||||||
|
expect(
|
||||||
|
workflowsStore.workflowExecutionData?.data?.resultData.pinData?.['Edit Fields'][0]
|
||||||
|
.pairedItem,
|
||||||
|
).toEqual({
|
||||||
|
item: 1,
|
||||||
|
sourceOverwrite: {
|
||||||
|
previousNode: newName,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(workflowsStore.workflow.pinData?.[nodeName]).not.toBeDefined();
|
||||||
|
expect(workflowsStore.workflow.pinData?.[newName]).toBeDefined();
|
||||||
|
expect(workflowsStore.workflow.pinData?.['Edit Fields'][0].pairedItem).toEqual([
|
||||||
|
{
|
||||||
|
item: 3,
|
||||||
|
sourceOverwrite: {
|
||||||
|
previousNode: newName,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1180,10 +1180,10 @@ export const useWorkflowsStore = defineStore(STORES.WORKFLOWS, () => {
|
|||||||
|
|
||||||
// If node has any WorkflowResultData rename also that one that the data
|
// If node has any WorkflowResultData rename also that one that the data
|
||||||
// does still get displayed also after node got renamed
|
// does still get displayed also after node got renamed
|
||||||
if (workflowExecutionData.value?.data?.resultData.runData[nameData.old]) {
|
const runData = workflowExecutionData.value?.data?.resultData?.runData;
|
||||||
workflowExecutionData.value.data.resultData.runData[nameData.new] =
|
if (runData?.[nameData.old]) {
|
||||||
workflowExecutionData.value.data.resultData.runData[nameData.old];
|
runData[nameData.new] = runData[nameData.old];
|
||||||
delete workflowExecutionData.value.data.resultData.runData[nameData.old];
|
delete runData[nameData.old];
|
||||||
}
|
}
|
||||||
|
|
||||||
// In case the renamed node was last selected set it also there with the new name
|
// In case the renamed node was last selected set it also there with the new name
|
||||||
@@ -1194,7 +1194,7 @@ export const useWorkflowsStore = defineStore(STORES.WORKFLOWS, () => {
|
|||||||
const { [nameData.old]: removed, ...rest } = nodeMetadata.value;
|
const { [nameData.old]: removed, ...rest } = nodeMetadata.value;
|
||||||
nodeMetadata.value = { ...rest, [nameData.new]: nodeMetadata.value[nameData.old] };
|
nodeMetadata.value = { ...rest, [nameData.new]: nodeMetadata.value[nameData.old] };
|
||||||
|
|
||||||
if (workflow.value.pinData && workflow.value.pinData.hasOwnProperty(nameData.old)) {
|
if (workflow.value.pinData?.[nameData.old]) {
|
||||||
const { [nameData.old]: renamed, ...restPinData } = workflow.value.pinData;
|
const { [nameData.old]: renamed, ...restPinData } = workflow.value.pinData;
|
||||||
workflow.value = {
|
workflow.value = {
|
||||||
...workflow.value,
|
...workflow.value,
|
||||||
@@ -1205,8 +1205,33 @@ export const useWorkflowsStore = defineStore(STORES.WORKFLOWS, () => {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const resultData = workflowExecutionData.value?.data?.resultData;
|
||||||
|
if (resultData?.pinData?.[nameData.old]) {
|
||||||
|
resultData.pinData[nameData.new] = resultData.pinData[nameData.old];
|
||||||
|
delete resultData.pinData[nameData.old];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the name in pinData
|
||||||
|
Object.values(workflow.value.pinData ?? {})
|
||||||
|
.concat(Object.values(workflowExecutionData.value?.data?.resultData.pinData ?? {}))
|
||||||
|
.flatMap((executionData) =>
|
||||||
|
executionData.flatMap((nodeExecution) =>
|
||||||
|
Array.isArray(nodeExecution.pairedItem)
|
||||||
|
? nodeExecution.pairedItem
|
||||||
|
: [nodeExecution.pairedItem],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.forEach((pairedItem) => {
|
||||||
|
if (
|
||||||
|
typeof pairedItem === 'number' ||
|
||||||
|
pairedItem?.sourceOverwrite?.previousNode !== nameData.old
|
||||||
|
)
|
||||||
|
return;
|
||||||
|
pairedItem.sourceOverwrite.previousNode = nameData.new;
|
||||||
|
});
|
||||||
|
|
||||||
Object.values(workflowExecutionData.value?.data?.resultData.runData ?? {})
|
Object.values(workflowExecutionData.value?.data?.resultData.runData ?? {})
|
||||||
.flatMap((taskData) => taskData.map((task) => task.source).flat())
|
.flatMap((taskData) => taskData.flatMap((task) => task.source))
|
||||||
.forEach((source) => {
|
.forEach((source) => {
|
||||||
if (!source || source.previousNode !== nameData.old) return;
|
if (!source || source.previousNode !== nameData.old) return;
|
||||||
source.previousNode = nameData.new;
|
source.previousNode = nameData.new;
|
||||||
|
|||||||
Reference in New Issue
Block a user