mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
refactor: improve code readability and comments in IfElse and Condition components
This commit is contained in:
@@ -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<string, number> = {
|
||||
@@ -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:
|
||||
|
||||
@@ -38,8 +38,7 @@ const components: Array<ComponentMetadata> = [
|
||||
{
|
||||
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<ComponentMetadata> = [
|
||||
{
|
||||
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",
|
||||
|
||||
Reference in New Issue
Block a user