Skip to content

Commit

Permalink
Merge pull request #3239 from bettyblocks/feat/array-compare-option-c…
Browse files Browse the repository at this point in the history
…onditional

Feat/array compare option conditional
  • Loading branch information
ingmar-stipriaan authored Nov 21, 2023
2 parents 6c0d0e6 + 9e911ea commit a2500fe
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/components/conditional.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@
const [visible, setVisible] = useState();
const logic = useLogic(displayLogic);

function isEmpty(value) {
return (
value == null ||
(typeof value === 'string' && value.trim().length === 0)
);
}

const evalCondition = () => {
if (!initVisibility && leftValue === '' && rightValue === '') {
return false;
Expand All @@ -59,6 +66,12 @@
return leftParsed >= rightParsed;
case 'lteq':
return leftParsed <= rightParsed;
case 'in': {
if (isEmpty(leftParsed) || isEmpty(rightParsed)) return false;
const leftArr = leftParsed.split(',') || leftParsed;
const rightArr = rightParsed.split(',') || rightParsed;
return leftArr.some((i) => rightArr.includes(i));
}
default:
return leftParsed === rightParsed;
}
Expand Down
4 changes: 4 additions & 0 deletions src/prefabs/structures/Conditional/options/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ export const conditionalOptions = {
name: 'Less than or equal to',
value: 'lteq',
},
{
name: 'IN',
value: 'in',
},
],
condition: showIf('type', 'EQ', 'singleRule'),
},
Expand Down

0 comments on commit a2500fe

Please sign in to comment.