From 4fe8aea655266aaeade089aa4659cd0582d0ac78 Mon Sep 17 00:00:00 2001 From: Nawaz Dhandala Date: Wed, 25 Mar 2026 20:29:24 +0000 Subject: [PATCH] refactor: improve code readability and comments in IfElse and Condition components --- .../Workflow/Components/Conditions/IfElse.ts | 33 +++++++++++-------- Common/Types/Workflow/Components/Condition.ts | 6 ++-- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/Common/Server/Types/Workflow/Components/Conditions/IfElse.ts b/Common/Server/Types/Workflow/Components/Conditions/IfElse.ts index 6291418e1f..efada84e9c 100644 --- a/Common/Server/Types/Workflow/Components/Conditions/IfElse.ts +++ b/Common/Server/Types/Workflow/Components/Conditions/IfElse.ts @@ -64,19 +64,25 @@ export default class IfElse extends ComponentCode { // Get explicit types from dropdowns, default to text let input1Type: ConditionValueType = - (args["input-1-type"] as ConditionValueType) || - ConditionValueType.Text; + (args["input-1-type"] as ConditionValueType) || ConditionValueType.Text; let input2Type: ConditionValueType = - (args["input-2-type"] as ConditionValueType) || - ConditionValueType.Text; + (args["input-2-type"] as ConditionValueType) || ConditionValueType.Text; - // When types differ, coerce both to the more specific type - // so comparisons like text "true" == boolean true work correctly. - // Priority: Null/Undefined keep as-is, Boolean > Number > Text. + /* + * When types differ, coerce both to the more specific type + * so comparisons like text "true" == boolean true work correctly. + * Priority: Null/Undefined keep as-is, Boolean > Number > Text. + */ if (input1Type !== input2Type) { - const isNullish = (t: ConditionValueType): boolean => - t === ConditionValueType.Null || - t === ConditionValueType.Undefined; + type IsNullishFunction = (t: ConditionValueType) => boolean; + + const isNullish: IsNullishFunction = ( + t: ConditionValueType, + ): boolean => { + return ( + t === ConditionValueType.Null || t === ConditionValueType.Undefined + ); + }; if (!isNullish(input1Type) && !isNullish(input2Type)) { const typePriority: Record = { @@ -103,9 +109,10 @@ export default class IfElse extends ComponentCode { value: JSONValue, valueType: ConditionValueType, ): string => { - const strValue: string = typeof value === "object" - ? JSON.stringify(value) - : String(value ?? ""); + const strValue: string = + typeof value === "object" + ? JSON.stringify(value) + : String(value ?? ""); switch (valueType) { case ConditionValueType.Boolean: diff --git a/Common/Types/Workflow/Components/Condition.ts b/Common/Types/Workflow/Components/Condition.ts index 081ebd3613..439127b9c6 100644 --- a/Common/Types/Workflow/Components/Condition.ts +++ b/Common/Types/Workflow/Components/Condition.ts @@ -38,8 +38,7 @@ const components: Array = [ { type: ComponentInputType.ValueType, name: "Input 1 Type", - description: - "Type of Input 1. Defaults to Text if not selected.", + description: "Type of Input 1. Defaults to Text if not selected.", placeholder: "Text", required: false, id: "input-1-type", @@ -63,8 +62,7 @@ const components: Array = [ { type: ComponentInputType.ValueType, name: "Input 2 Type", - description: - "Type of Input 2. Defaults to Text if not selected.", + description: "Type of Input 2. Defaults to Text if not selected.", placeholder: "Text", required: false, id: "input-2-type",