Skip to content

Commit

Permalink
Merge pull request #18810 from mvdbeek/prevent_connecting_optional_ou…
Browse files Browse the repository at this point in the history
…tput_to_required_input

[24.1] Prevent optional output to required input connection in editor
  • Loading branch information
mvdbeek authored Sep 16, 2024
2 parents aad1caf + 4a92363 commit 972c3c7
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 1 deletion.
2 changes: 1 addition & 1 deletion client/src/components/Workflow/Editor/NodeOutput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ const outputDetails = computed(() => {
const outputType =
collectionType && collectionType.isCollection && collectionType.collectionType
? `output is ${collectionTypeToDescription(collectionType)}`
: `output is ${terminal.value.type || "dataset"}`;
: `output is ${terminal.value.optional ? "optional " : ""}${terminal.value.type || "dataset"}`;
if (isMultiple.value) {
if (!collectionType) {
collectionType = NULL_COLLECTION_TYPE_DESCRIPTION;
Expand Down
10 changes: 10 additions & 0 deletions client/src/components/Workflow/Editor/modules/terminals.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,16 @@ describe("canAccept", () => {
"Cannot attach a text parameter to a integer input"
);
});
it("rejects optional integer to required parameter connection", () => {
const integerInputParam = terminals["multi data"]!["advanced|advanced_threshold"] as InputParameterTerminal;
const optionalIntegerOutputParam = terminals["optional integer parameter input"]![
"output"
] as OutputParameterTerminal;
expect(integerInputParam.canAccept(optionalIntegerOutputParam).canAccept).toBe(false);
expect(integerInputParam.canAccept(optionalIntegerOutputParam).reason).toBe(
"Cannot attach an optional output to a required parameter"
);
});
it("rejects data to parameter connection", () => {
const dataOut = terminals["data input"]!["output"] as OutputTerminal;
const integerInputParam = terminals["multi data"]!["advanced|advanced_threshold"] as InputParameterTerminal;
Expand Down
3 changes: 3 additions & 0 deletions client/src/components/Workflow/Editor/modules/terminals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,9 @@ export class InputParameterTerminal extends BaseInputTerminal {
const effectiveThisType = this.effectiveType(this.type);
const otherType = ("type" in other && other.type) || "data";
const effectiveOtherType = this.effectiveType(otherType);
if (!this.optional && other.optional) {
return new ConnectionAcceptable(false, `Cannot attach an optional output to a required parameter`);
}
const canAccept = effectiveThisType === effectiveOtherType;
return new ConnectionAcceptable(
canAccept,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -906,5 +906,69 @@
"left": 12.8729248046875,
"top": 501.7839660644531
}
},
"19": {
"id": 19,
"type": "parameter_input",
"label": "optional text parameter input",
"content_id": null,
"name": "Input parameter",
"tool_state": {
"parameter_definition": "{\"__current_case__\": 0, \"optional\": {\"__current_case__\": 1, \"optional\": \"true\"}, \"parameter_type\": \"text\", \"restrictions\": {\"__current_case__\": 0, \"how\": \"none\"}}",
"__page__": null,
"__rerun_remap_job_id__": null
},
"errors": null,
"inputs": [],
"outputs": [
{
"name": "output",
"label": "optional text parameter input",
"type": "text",
"optional": true,
"parameter": true
}
],
"annotation": "",
"post_job_actions": {},
"uuid": "71c030ff-a29f-4e32-a735-37471e7a3f12",
"workflow_outputs": [],
"input_connections": {},
"position": {
"left": 95.0506591796875,
"top": 867.0427551269531
}
},
"19": {
"id": 19,
"type": "parameter_input",
"label": "optional integer parameter input",
"content_id": null,
"name": "Input parameter",
"tool_state": {
"parameter_definition": "{\"__current_case__\": 1, \"optional\": {\"__current_case__\": 1, \"optional\": \"true\"}, \"parameter_type\": \"integer\"}",
"__page__": null,
"__rerun_remap_job_id__": null
},
"errors": null,
"inputs": [],
"outputs": [
{
"name": "output",
"label": "integer parameter input",
"type": "integer",
"optional": true,
"parameter": true
}
],
"annotation": "",
"post_job_actions": {},
"uuid": "634f06f1-b279-4160-9390-a004018e92ce",
"workflow_outputs": [],
"input_connections": {},
"position": {
"left": 148.72970581054688,
"top": 620.5069274902344
}
}
}

0 comments on commit 972c3c7

Please sign in to comment.