mozfet / ExpertBox

ExpertBox.com is a knowledge automation platform that is used by experts from different domains to create constructs of systematic conversations that converse with users, for free or for a fee.
0 stars 0 forks source link

Switch Component #163

Open mozfet opened 6 years ago

mozfet commented 6 years ago

Todo:

Background

It is a very frequent use case when designing a construct to want the user to select an option from a choice and then do something directly based on this choice. For example a menu structure.

This functionality is currently possible using a branch, however, branches may appear intimidating due to the leaves and expressions used to users without software backgrounds. For this reason, a simplified branch is being introduced, the Switch.

While a Branch can be compared with a JavaScript if then else then if chain with expressions, a Switch is modeled on JavaScript switch statement, the decision pivots on a single point instead of multiple expressions.

Branch Component processing, expressed in JavaScript

for (let leaf of branch.leaves) {
  if (leaf.expression) {
    process(leafA.component)
    break;
  }
}

A Switch is just a Branch with Managed Leaves with Managed Expressions with leaf expressions not being shown to the user in the designer. A switch must also be able to convert to a Branch, for when the user learns the logic is not a simple switch and needs multiple expressions.

It is not simple to convert Branches to switches, as the complexity of Branches is greater than Switches, and logic may be lost during simplification, and it is difficult to map which expressions should be replaced with which managed expressions. For this reason Branch to Switch is a one-way conversion. If you want to make a Switch from a Branch, create a new Switch and drag the Leaf Components one by one into the switch as applicable.

When a Switch is created and linked to a Choice, each Choice option becomes a Leaf with an Expression with a script return choice.value === option.value, and a default leaf if the user wants one.

When a Switch is created and linked to a Question, the user needs to supply the cases to compare the value to, because there could be an excessive amount of valid combinations (such as an alphabetic formatted question with a max length of 5 has more than 11 million possible answers).

How it must thus work, for example, if the question.value is a number between 1 and 5, you might only want cases for 2 and 4, and ignore the rest or having a default to catch them.