fix(editor): Fix node type properties not updating regression (no-changelog) (#11700)

This commit is contained in:
Alex Grozav 2024-11-12 17:58:56 +02:00 committed by GitHub
parent 01ebe9dd38
commit e3871dbfe2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 40 additions and 5 deletions

View file

@ -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<INodeTypeDescription>({
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,

View file

@ -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() {

View file

@ -778,8 +778,8 @@ export function useCanvasOperations({ router }: { router: ReturnType<typeof useR
parameters,
};
resolveNodeParameters(nodeData);
resolveNodeName(nodeData);
resolveNodeParameters(nodeData, nodeTypeDescription);
resolveNodeWebhook(nodeData, nodeTypeDescription);
return nodeData;
@ -828,10 +828,9 @@ export function useCanvasOperations({ router }: { router: ReturnType<typeof useR
return nodeVersion;
}
function resolveNodeParameters(node: INodeUi) {
const nodeType = nodeTypesStore.getNodeType(node.type, node.typeVersion);
function resolveNodeParameters(node: INodeUi, nodeTypeDescription: INodeTypeDescription) {
const nodeParameters = NodeHelpers.getNodeParameters(
nodeType?.properties ?? [],
nodeTypeDescription?.properties ?? [],
node.parameters,
true,
false,
@ -1381,7 +1380,10 @@ export function useCanvasOperations({ router }: { router: ReturnType<typeof useR
workflowHelpers.initState(data);
data.nodes.forEach((node) => {
const nodeTypeDescription = requireNodeTypeDescription(node.type, node.typeVersion);
nodeHelpers.matchCredentials(node);
resolveNodeParameters(node, nodeTypeDescription);
resolveNodeWebhook(node, nodeTypeDescription);
});
workflowsStore.setNodes(data.nodes);