From c5e2a904c6933b93fafe02f0d83e4b64ccd5fda2 Mon Sep 17 00:00:00 2001 From: Tyler Cooper Date: Thu, 14 Aug 2025 14:39:54 -0500 Subject: [PATCH] Update compare.js --- app/blocks/text/compare.js | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/app/blocks/text/compare.js b/app/blocks/text/compare.js index d1f95a8..6c5d8ed 100644 --- a/app/blocks/text/compare.js +++ b/app/blocks/text/compare.js @@ -6,47 +6,40 @@ export default { colour: 180, inputsInline: true, primaryCategory: "Logic", - description: "Compare two chunks of text for equality, inequality, or inclusion.", - + description: "Compare any two pieces of text or data to build conditional logic in your Actions. Perfect for creating if/then statements like 'if device status equals online', 'if user name is not guest', or 'if error message contains timeout'. Works with feed values, variables, user input, or any text-based data.", connections: { mode: "value", output: "expression", }, - template: `%A %OP %B`, - inputs: { A: { - description: "The left side of the comparison. Will be coerced to a string", + description: "The first value to compare (left side). Can be feed data, variable content, user input, or any text. Numbers and other data types will be automatically converted to text for comparison.", check: "expression", shadow: 'io_text' }, - B: { - description: "The right side of the comparison. Will be coerced to a string", + description: "The second value to compare (right side). Can be literal text like 'online', variable content, feed values, or any data you want to compare against the first input. Also automatically converted to text.", check: "expression", shadow: 'io_text' }, }, - fields: { OP: { - description: "Select what kind of comparison to do:", + description: "Choose how to compare the two text inputs:", options: [ - ['=', 'EQ', "Returns true if the the inputs are the same."], - ['\u2260', 'NEQ', "Returns true if the inputs not the same."], - ['includes', 'INC', "Returns true if input A includes input B."], + ['=', 'EQ', "Exact match: Returns true only if both inputs are identical (e.g., 'online' = 'online' is true, but 'Online' = 'online' is false due to case sensitivity)."], + ['\u2260', 'NEQ', "Not equal: Returns true if the inputs are different in any way (e.g., useful for 'if status is not offline' or 'if username is not empty' conditions)."], + ['includes', 'INC', "Contains: Returns true if the first input contains the second input anywhere within it (e.g., 'sensor error timeout' includes 'error' would be true)."], ] } }, - generators: { json: (block, generator) => { const comparator = block.getFieldValue('OP'), leftExp = generator.valueToCode(block, 'A', 0) || null, rightExp = generator.valueToCode(block, 'B', 0) || null, - blockPayload = JSON.stringify({ textCompare: { left: JSON.parse(leftExp), @@ -54,11 +47,9 @@ export default { right: JSON.parse(rightExp), }, }) - return [ blockPayload, 0 ] } }, - regenerators: { json: (blockObject, helpers) => { const @@ -70,7 +61,6 @@ export default { A: helpers.expressionToBlock(left, { shadow: "io_text" }), B: helpers.expressionToBlock(right, { shadow: "io_text" }), } - return { type: 'text_compare', fields, inputs } } }