From c821f1c532048c9afa0bc51e3566ae65bf9caf0a Mon Sep 17 00:00:00 2001 From: Elias Meire Date: Wed, 5 Mar 2025 10:27:54 +0100 Subject: [PATCH] fix(editor): Render credential-only nodes when loading from the backend (#13689) Co-authored-by: Michael Kret --- .../src/stores/workflows.store.test.ts | 36 ++++++++++++++++++- .../editor-ui/src/stores/workflows.store.ts | 8 ++--- 2 files changed, 39 insertions(+), 5 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 d00ab16731..55ca261f8e 100644 --- a/packages/frontend/editor-ui/src/stores/workflows.store.test.ts +++ b/packages/frontend/editor-ui/src/stores/workflows.store.test.ts @@ -12,7 +12,13 @@ import type { IExecutionResponse, INodeUi, IWorkflowDb, IWorkflowSettings } from import { useNodeTypesStore } from '@/stores/nodeTypes.store'; import { SEND_AND_WAIT_OPERATION } from 'n8n-workflow'; -import type { IPinData, ExecutionSummary, IConnection, INodeExecutionData } from 'n8n-workflow'; +import type { + IPinData, + ExecutionSummary, + IConnection, + INodeExecutionData, + INode, +} from 'n8n-workflow'; import { stringSizeInBytes } from '@/utils/typesUtils'; import { dataPinningEventBus } from '@/event-bus'; import { useUIStore } from '@/stores/ui.store'; @@ -681,6 +687,34 @@ describe('useWorkflowsStore', () => { }); }); + describe('setNodes()', () => { + it('should transform credential-only nodes', () => { + const setNodeId = '1'; + const credentialOnlyNodeId = '2'; + workflowsStore.setNodes([ + mock({ + id: setNodeId, + name: 'Edit Fields', + type: 'n8n-nodes-base.set', + }), + mock({ + id: credentialOnlyNodeId, + name: 'AlienVault Request', + type: 'n8n-nodes-base.httpRequest', + extendsCredential: 'alienVaultApi', + }), + ]); + + expect(workflowsStore.workflow.nodes[0].id).toEqual(setNodeId); + expect(workflowsStore.workflow.nodes[1].id).toEqual(credentialOnlyNodeId); + expect(workflowsStore.workflow.nodes[1].type).toEqual('n8n-creds-base.alienVaultApi'); + expect(workflowsStore.nodeMetadata).toEqual({ + 'AlienVault Request': { pristine: true }, + 'Edit Fields': { pristine: true }, + }); + }); + }); + describe('updateNodeAtIndex', () => { it.each([ { diff --git a/packages/frontend/editor-ui/src/stores/workflows.store.ts b/packages/frontend/editor-ui/src/stores/workflows.store.ts index c98328da36..5adb91fa66 100644 --- a/packages/frontend/editor-ui/src/stores/workflows.store.ts +++ b/packages/frontend/editor-ui/src/stores/workflows.store.ts @@ -1117,6 +1117,10 @@ export const useWorkflowsStore = defineStore(STORES.WORKFLOWS, () => { nodeHelpers.assignNodeId(node); } + if (node.extendsCredential) { + node.type = getCredentialOnlyNodeTypeName(node.extendsCredential); + } + if (!nodeMetadata.value[node.name]) { nodeMetadata.value[node.name] = { pristine: true }; } @@ -1190,10 +1194,6 @@ export const useWorkflowsStore = defineStore(STORES.WORKFLOWS, () => { return; } - if (nodeData.extendsCredential) { - nodeData.type = getCredentialOnlyNodeTypeName(nodeData.extendsCredential); - } - workflow.value.nodes.push(nodeData); // Init node metadata if (!nodeMetadata.value[nodeData.name]) {