Skip to content

Commit

Permalink
feat(ui): prevent connections to direct-only inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
psychedelicious committed May 17, 2024
1 parent ad8778d commit 4d33181
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ export const useIsValidConnection = () => {
return false;
}

if (targetFieldTemplate.input === 'direct') {
return false;
}

if (!shouldValidateGraph) {
// manual override!
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const getFirstValidConnection = (
};
}
// Only one connection per target field is allowed - look for an unconnected target field
const candidateFields = map(candidateTemplate.inputs);
const candidateFields = map(candidateTemplate.inputs).filter((i) => i.input !== 'direct');
const candidateConnectedFields = edges
.filter((edge) => edge.target === candidateNode.id)
.map((edge) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,16 @@ export const makeConnectionErrorSelector = (
return i18n.t('nodes.cannotDuplicateConnection');
}

const targetNode = nodes.find((node) => node.id === target);
if (targetNode?.data.type === 'collect' && targetHandle === 'item') {
const targetNode = nodes.find((node) => node.id === targetNodeId);
assert(targetNode, `Target node not found: ${targetNodeId}`);
const targetTemplate = templates[targetNode.data.type];
assert(targetTemplate, `Target template not found: ${targetNode.data.type}`);

if (targetTemplate.inputs[targetFieldName]?.input === 'direct') {
return i18n.t('nodes.cannotConnectToDirectInput');
}

if (targetNode.data.type === 'collect' && targetFieldName === 'item') {
// Collect nodes shouldn't mix and match field types
const collectItemType = getCollectItemType(templates, nodes, edges, targetNode.id);
if (collectItemType) {
Expand Down

0 comments on commit 4d33181

Please sign in to comment.