From 059d5a682c8d5556d1dc3634d2b5026901d0aeeb Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Sun, 19 May 2024 00:30:49 +1000 Subject: [PATCH] tidy(ui): validateConnection code clarity --- .../nodes/store/util/validateConnection.ts | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/invokeai/frontend/web/src/features/nodes/store/util/validateConnection.ts b/invokeai/frontend/web/src/features/nodes/store/util/validateConnection.ts index db8b7b737e..debf294557 100644 --- a/invokeai/frontend/web/src/features/nodes/store/util/validateConnection.ts +++ b/invokeai/frontend/web/src/features/nodes/store/util/validateConnection.ts @@ -56,7 +56,8 @@ export const validateConnection: ValidateConnectionFunc = (c, nodes, edges, temp * We may need to ignore an edge when validating a connection. * * For example, while an edge is being updated, it still exists in the array of edges. As we validate the new connection, - * the user experience should be that the edge is temporarily removed from the graph, so we need to ignore it. + * the user experience should be that the edge is temporarily removed from the graph, so we need to ignore it, else + * the validation will fail unexpectedly. */ const filteredEdges = edges.filter((e) => e.id !== ignoreEdge?.id); @@ -100,21 +101,18 @@ export const validateConnection: ValidateConnectionFunc = (c, nodes, edges, temp } if (targetNode.data.type === 'collect' && c.targetHandle === 'item') { - // Collect nodes shouldn't mix and match field types + // Collect nodes shouldn't mix and match field types. const collectItemType = getCollectItemType(templates, nodes, edges, targetNode.id); - if (collectItemType) { - if (!areTypesEqual(sourceFieldTemplate.type, collectItemType)) { - return buildRejectResult('nodes.cannotMixAndMatchCollectionItemTypes'); - } + if (collectItemType && !areTypesEqual(sourceFieldTemplate.type, collectItemType)) { + return buildRejectResult('nodes.cannotMixAndMatchCollectionItemTypes'); } } - if ( - filteredEdges.find(getTargetEqualityPredicate(c)) && - // except CollectionItem inputs can have multiple input connections - targetFieldTemplate.type.name !== 'CollectionItemField' - ) { - return buildRejectResult('nodes.inputMayOnlyHaveOneConnection'); + if (filteredEdges.find(getTargetEqualityPredicate(c))) { + // CollectionItemField inputs can have multiple input connections + if (targetFieldTemplate.type.name !== 'CollectionItemField') { + return buildRejectResult('nodes.inputMayOnlyHaveOneConnection'); + } } if (!validateConnectionTypes(sourceFieldTemplate.type, targetFieldTemplate.type)) {