From 062633ec9bac3e6949dbc887c3aa955a93ba7468 Mon Sep 17 00:00:00 2001 From: Elias Meire Date: Fri, 19 Jul 2024 14:29:11 +0200 Subject: [PATCH] feat(editor): Open NDV when a node is added to canvas v2 (no-changelog) (#10114) --- .../__tests__/useCanvasOperations.spec.ts | 14 ++++++++++++++ .../src/composables/useCanvasOperations.ts | 8 +++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/editor-ui/src/composables/__tests__/useCanvasOperations.spec.ts b/packages/editor-ui/src/composables/__tests__/useCanvasOperations.spec.ts index cb57fe3c17..2b9a12ef15 100644 --- a/packages/editor-ui/src/composables/__tests__/useCanvasOperations.spec.ts +++ b/packages/editor-ui/src/composables/__tests__/useCanvasOperations.spec.ts @@ -167,6 +167,20 @@ describe('useCanvasOperations', () => { }); expect(result.credentials).toBeUndefined(); }); + + it('should open NDV when specified', async () => { + nodeTypesStore.setNodeTypes([mockNodeTypeDescription({ name: 'type' })]); + + await canvasOperations.addNode( + { + type: 'type', + name: 'Test Name', + }, + { openNDV: true }, + ); + + expect(ndvStore.activeNodeName).toBe('Test Name'); + }); }); describe('updateNodePosition', () => { diff --git a/packages/editor-ui/src/composables/useCanvasOperations.ts b/packages/editor-ui/src/composables/useCanvasOperations.ts index be1e021c8e..e3dc885811 100644 --- a/packages/editor-ui/src/composables/useCanvasOperations.ts +++ b/packages/editor-ui/src/composables/useCanvasOperations.ts @@ -76,7 +76,7 @@ import type { import { NodeConnectionType, NodeHelpers, TelemetryHelpers } from 'n8n-workflow'; import { v4 as uuid } from 'uuid'; import type { Ref } from 'vue'; -import { computed } from 'vue'; +import { computed, nextTick } from 'vue'; import type { useRouter } from 'vue-router'; type AddNodeData = Partial & { @@ -429,6 +429,12 @@ export function useCanvasOperations({ workflowsStore.setNodePristine(nodeData.name, true); uiStore.stateIsDirty = true; + if (options.openNDV) { + void nextTick(() => { + ndvStore.setActiveNodeName(nodeData.name); + }); + } + return nodeData; }