feat(editor): Allow unknown nodes on new canvas (no-changelog) (#10962)

This commit is contained in:
Alex Grozav 2024-09-25 13:05:40 +03:00 committed by GitHub
parent dd3b2cb62d
commit 5ce05b33d2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 36 additions and 20 deletions

View file

@ -313,7 +313,6 @@ onBeforeUnmount(() => {
@open:contextmenu="onOpenContextMenuFromNode" @open:contextmenu="onOpenContextMenuFromNode"
> >
<NodeIcon <NodeIcon
v-if="nodeTypeDescription"
:node-type="nodeTypeDescription" :node-type="nodeTypeDescription"
:size="nodeIconSize" :size="nodeIconSize"
:shrink="false" :shrink="false"

View file

@ -102,15 +102,6 @@ describe('useCanvasOperations', () => {
expect(result).toBe(expectedDescription); expect(result).toBe(expectedDescription);
}); });
it('should throw an error when node type does not exist', () => {
const type = 'nonexistentType';
const { requireNodeTypeDescription } = useCanvasOperations({ router });
expect(() => {
requireNodeTypeDescription(type);
}).toThrow();
});
it('should return node type description when only type is provided and it exists', () => { it('should return node type description when only type is provided and it exists', () => {
const nodeTypesStore = useNodeTypesStore(); const nodeTypesStore = useNodeTypesStore();
const type = 'testTypeWithoutVersion'; const type = 'testTypeWithoutVersion';
@ -123,6 +114,25 @@ describe('useCanvasOperations', () => {
expect(result).toBe(expectedDescription); expect(result).toBe(expectedDescription);
}); });
it("should return placeholder node type description if node type doesn't exist", () => {
const type = 'nonexistentType';
const { requireNodeTypeDescription } = useCanvasOperations({ router });
const result = requireNodeTypeDescription(type);
expect(result).toEqual({
name: type,
displayName: type,
description: '',
defaults: {},
group: [],
inputs: [],
outputs: [],
properties: [],
version: 1,
});
});
}); });
describe('addNode', () => { describe('addNode', () => {

View file

@ -445,16 +445,23 @@ export function useCanvasOperations({ router }: { router: ReturnType<typeof useR
historyStore.stopRecordingUndo(); historyStore.stopRecordingUndo();
} }
function requireNodeTypeDescription(type: INodeUi['type'], version?: INodeUi['typeVersion']) { function requireNodeTypeDescription(
const nodeTypeDescription = nodeTypesStore.getNodeType(type, version); type: INodeUi['type'],
if (!nodeTypeDescription) { version?: INodeUi['typeVersion'],
throw new Error( ): INodeTypeDescription {
i18n.baseText('nodeView.showMessage.addNodeButton.message', { return (
interpolate: { nodeTypeName: type }, nodeTypesStore.getNodeType(type, version) ?? {
}), properties: [],
); displayName: type,
} name: type,
return nodeTypeDescription; group: [],
description: '',
version: version ?? 1,
defaults: {},
inputs: [],
outputs: [],
}
);
} }
async function addNodes( async function addNodes(