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"
>
<NodeIcon
v-if="nodeTypeDescription"
:node-type="nodeTypeDescription"
:size="nodeIconSize"
:shrink="false"

View file

@ -102,15 +102,6 @@ describe('useCanvasOperations', () => {
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', () => {
const nodeTypesStore = useNodeTypesStore();
const type = 'testTypeWithoutVersion';
@ -123,6 +114,25 @@ describe('useCanvasOperations', () => {
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', () => {

View file

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