Operators Rules
The 'rules' in Flower are used to define conditions and conditional behaviors within the workflow. These rules allow for dynamically changing the display or behavior of certain fields or components based on specific conditions.
The rules schema follows the MongoDB style, below is the list of available operators:
- $exists: Checks if a value exists or not.
- $eq: Checks if two values are equal.
- $ne: Checks if two values are not equal.
- $gt: Checks if the first value is greater than the second.
- $gte: Checks if the first value is greater than or equal to the second.
- $lt: Checks if the first value is less than the second.
- $lte: Checks if the first value is less than or equal to the second.
- $strGt: Checks if the length of a string is greater than the specified value.
- $strLt: Checks if the length of a string is less than the specified value.
- $strLte: Checks if the length of a string is less than or equal to the specified value.
- $in: Checks if a value is present in a given array.
- $nin: Checks if a value is not present in a given array.
- $all: Checks if all values are present in a given array.
- $$regex: Checks if a string matches a regular expression.
Examples
Rules in $and | $or
<FlowerNode id="node"
to={{
node2: {
rules: { $and: [
{ myValue: { $exists: true } },
{ myValue: { $strGt: 6 } }
]}
}
}}>
...
</Flower>
<FlowerNode id="node"
to={{
node2: {
rules: { $or: [
{ myValue: { $exists: false } },
{ myValue: { $strGt: 6 } }
]}
}
}}>
...
</Flower>
Compare state value, use '$ref:'
<Flower name="demo" initialData={{ myValue1: 'test', myValue2: 'test2' }}>
<FlowerNode id="node"
to={{
node2: {
rules: [
{ myValue1: { $eq: '$ref:myValue2' } }
]}
}}>
...
</Flower>