Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
182 changes: 182 additions & 0 deletions content/assets/conditional-constructs/data/branch_example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
[
{
"comment": "",
"evaluate-labels": "true",
"label": null,
"nodes": [
{
"comment": "",
"exit-on": "FAILURE",
"label": "action == 'multiplication'",
"nodes": [
{
"comment": "",
"label": "Math",
"nodes": [
{
"comment": "",
"label": null,
"mode": "INPUT",
"type": "MAP",
"nodeIndex": 0
},
{
"comment": "",
"label": null,
"mode": "OUTPUT",
"type": "MAP",
"nodeIndex": 1
}
],
"service": "pub.math:multiplyInts",
"type": "INVOKE",
"validate-in": null,
"validate-out": null,
"node_hints": {
"name": null,
"itemType": "SERVICES",
"serviceInfo": {
"groupDisplayName": "Math",
"groupName": "math",
"services": null
},
"serviceName": {
"displayName": "multiplyInts",
"serviceName": "pub.math:multiplyInts",
"transformerSupport": "true"
},
"ui_step_index": 3,
"nodeIndex": 0,
"mapSet": null,
"outputMapSet": null,
"serviceReferenceResolved": true
},
"nodeIndex": 0
}
],
"type": "SEQUENCE",
"node_hints": {
"name": "EXPRESSION",
"itemType": "CONTROLS",
"nodeIndex": 0
},
"nodeIndex": 0
},
{
"comment": "",
"exit-on": "FAILURE",
"label": "action = /^add/",
"nodes": [
{
"comment": "",
"label": "Math",
"service": "pub.math:addInts",
"type": "INVOKE",
"validate-in": null,
"validate-out": null,
"node_hints": {
"name": null,
"itemType": "SERVICES",
"serviceInfo": {
"groupDisplayName": "Math",
"groupName": "math",
"services": null
},
"serviceName": {
"displayName": "addInts",
"serviceName": "pub.math:addInts",
"transformerSupport": "true"
},
"ui_step_index": 5,
"nodeIndex": 0,
"serviceReferenceResolved": true
},
"nodeIndex": 0
}
],
"type": "SEQUENCE",
"node_hints": {
"name": "EXPRESSION",
"itemType": "CONTROLS",
"nodeIndex": 1
},
"nodeIndex": 1
},
{
"comment": "",
"exit-on": "FAILURE",
"label": "action=='subtraction'",
"nodes": [
{
"comment": "",
"label": "Math",
"service": "pub.math:subtractInts",
"type": "INVOKE",
"validate-in": null,
"validate-out": null,
"node_hints": {
"name": null,
"itemType": "SERVICES",
"serviceInfo": {
"groupDisplayName": "Math",
"groupName": "math",
"services": null
},
"serviceName": {
"displayName": "subtractInts",
"serviceName": "pub.math:subtractInts",
"transformerSupport": "true"
},
"ui_step_index": 7,
"nodeIndex": 0,
"serviceReferenceResolved": true
},
"nodeIndex": 0
}
],
"type": "SEQUENCE",
"node_hints": {
"name": "EXPRESSION",
"itemType": "CONTROLS",
"nodeIndex": 2
},
"nodeIndex": 2
},
{
"comment": "",
"exit-on": "FAILURE",
"label": "$default",
"nodes": [
{
"comment": "",
"failure-message": "No Match Found",
"from": "$flow",
"label": null,
"signal": "FAILURE",
"type": "EXIT",
"node_hints": {
"itemType": "CONTROLS",
"name": "EXIT",
"nodeIndex": 1
},
"nodeIndex": 0
}
],
"type": "SEQUENCE",
"node_hints": {
"name": "EXPRESSION",
"itemType": "CONTROLS",
"nodeIndex": 3
},
"nodeIndex": 3
}
],
"type": "BRANCH",
"node_hints": {
"name": "BRANCH",
"itemType": "CONTROLS",
"nodeIndex": 0
},
"nodeIndex": 0
}
]
1 change: 1 addition & 0 deletions content/conditional-constructs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ Conditional steps are those steps which performs different actions based on the
* Else
* ElseIf
* Switch
* Branch
<Feature name="Conditional Constructs"/>
42 changes: 42 additions & 0 deletions content/conditional-constructs/5-using-branch.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
title: "Conditions with Branch"
metaTitle: "Syntax Highlighting is the meta title tag for this page"
metaDescription: "This is the meta description for this page"
---
import branchJSON from '../assets/conditional-constructs/data/branch_example.json'

The `Branch` step contains one or many `Expression` steps and executes only one of the `Expression` step which is evaluated to true and comes sequentially first.
All the other `Expression` steps under branch are ignored.

## Types of 'Expression' step
There are mainly two kinds of `Expression` steps:
* **'custom'** Expression
This step executes when the condition/conditions given inside this step is evalated to true.
The conditions can be any of the options mentioned in the conditional builder, in addition, user can specify a **regex** as well.

* Expression with **'$default'**
This step executes when none of the `Expression` steps are evaluated to true.
This step, if present, can be anywhere in the sequence and is executed at the last.

## Example - perform basic arithmetic operations based on user input

Lets write a FlowService which will perform arithmetic operations based on the action given by user.
* `Expression 1`: If input is equal to 'multiplication', perform multiplication of two integers.
* `Expression 2`: If input starts with 'add', perform addition of two integers.
* `Expression 3`: If input is equal to 'subtraction', perform subtraction of two integers.
* `Expression $default`: If the input doesn't match with any of the above expressions, the exit with failure message 'No match Found'

Add input from [I/O panel](/define-io/1_adding_fields)

![I/O panel](../assets/conditional-constructs/Branch-io.png)

* Add steps as shown

<FlowService
textToCopy={branchJSON}>
<FlowStep comment="Conditional execution of arithmetic operations" img="conditional-constructs/branch-example.png"/>
</FlowService>

* Following is the demo of how the branch executes for a sample of inputs

![branch](../assets/conditional-constructs/branchexec_demo.gif)
4 changes: 4 additions & 0 deletions src/components/mdxComponents/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@
{
"title": "The Switch Case",
"link": "/conditional-constructs/4-using-switch"
},
{
"title": "Evaluating Expressions with Branch",
"link": "/conditional-constructs/5-using-branch"
}
]
},
Expand Down