From e3871dbfe28dcf9019d73585b8360711e70d6842 Mon Sep 17 00:00:00 2001 From: Alex Grozav Date: Tue, 12 Nov 2024 17:58:56 +0200 Subject: [PATCH] fix(editor): Fix node type properties not updating regression (no-changelog) (#11700) --- packages/editor-ui/src/__tests__/mocks.ts | 5 +++- .../composables/useCanvasOperations.test.ts | 30 +++++++++++++++++++ .../src/composables/useCanvasOperations.ts | 10 ++++--- 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/packages/editor-ui/src/__tests__/mocks.ts b/packages/editor-ui/src/__tests__/mocks.ts index 993d5870a5..87b4a8bbf9 100644 --- a/packages/editor-ui/src/__tests__/mocks.ts +++ b/packages/editor-ui/src/__tests__/mocks.ts @@ -54,22 +54,25 @@ export const mockNodeTypeDescription = ({ credentials = [], inputs = [NodeConnectionType.Main], outputs = [NodeConnectionType.Main], + properties = [], }: { name?: INodeTypeDescription['name']; version?: INodeTypeDescription['version']; credentials?: INodeTypeDescription['credentials']; inputs?: INodeTypeDescription['inputs']; outputs?: INodeTypeDescription['outputs']; + properties?: INodeTypeDescription['properties']; } = {}) => mock({ name, displayName: name, + description: '', version, defaults: { name, }, defaultVersion: Array.isArray(version) ? version[version.length - 1] : version, - properties: [], + properties: properties as [], maxNodes: Infinity, group: EXECUTABLE_TRIGGER_NODE_TYPES.includes(name) ? ['trigger'] : [], inputs, diff --git a/packages/editor-ui/src/composables/useCanvasOperations.test.ts b/packages/editor-ui/src/composables/useCanvasOperations.test.ts index bb301173c9..4069a24f88 100644 --- a/packages/editor-ui/src/composables/useCanvasOperations.test.ts +++ b/packages/editor-ui/src/composables/useCanvasOperations.test.ts @@ -2050,6 +2050,36 @@ describe('useCanvasOperations', () => { expect(workflowsStore.setConnections).toHaveBeenCalled(); }); }); + + it('should initialize node data from node type description', () => { + const nodeTypesStore = mockedStore(useNodeTypesStore); + const type = SET_NODE_TYPE; + const version = 1; + const expectedDescription = mockNodeTypeDescription({ + name: type, + version, + properties: [ + { + displayName: 'Value', + name: 'value', + type: 'boolean', + default: true, + }, + ], + }); + + nodeTypesStore.nodeTypes = { [type]: { [version]: expectedDescription } }; + + const workflow = createTestWorkflow({ + nodes: [createTestNode()], + connections: {}, + }); + + const { initializeWorkspace } = useCanvasOperations({ router }); + initializeWorkspace(workflow); + + expect(workflow.nodes[0].parameters).toEqual({ value: true }); + }); }); function buildImportNodes() { diff --git a/packages/editor-ui/src/composables/useCanvasOperations.ts b/packages/editor-ui/src/composables/useCanvasOperations.ts index 23ac54a1c6..cbec5b44df 100644 --- a/packages/editor-ui/src/composables/useCanvasOperations.ts +++ b/packages/editor-ui/src/composables/useCanvasOperations.ts @@ -778,8 +778,8 @@ export function useCanvasOperations({ router }: { router: ReturnType { + const nodeTypeDescription = requireNodeTypeDescription(node.type, node.typeVersion); nodeHelpers.matchCredentials(node); + resolveNodeParameters(node, nodeTypeDescription); + resolveNodeWebhook(node, nodeTypeDescription); }); workflowsStore.setNodes(data.nodes);