@@ -15,6 +15,28 @@ import { NodeInfo } from '../types/node-info';
1515
1616import { RunCounter } from '../follow-path/run-counter' ;
1717import { runNodeFromThumb } from '../flow-engine/flow-engine' ;
18+ import {
19+ compileExpressionAsInfo ,
20+ runExpression ,
21+ } from '@devhelpr/expression-compiler' ;
22+ import { getVariablePayloadInputUtils } from './variable-payload-input-utils.ts/variable-payload-input-utils' ;
23+
24+ function handleExpression ( expression : string , payload : any ) {
25+ const compiledExpression = compileExpressionAsInfo ( expression ) ;
26+ const expressionFunction = (
27+ new Function ( 'payload' , `${ compiledExpression . script } ` ) as unknown as (
28+ payload ?: any
29+ ) => any
30+ ) . bind ( compiledExpression . bindings ) ;
31+
32+ const result = runExpression (
33+ expressionFunction ,
34+ payload ,
35+ false ,
36+ compiledExpression . payloadProperties
37+ ) ;
38+ return Boolean ( result ) ;
39+ }
1840
1941export const getSplitByCase = ( updated : ( ) => void ) : NodeTask < NodeInfo > => {
2042 let node : IRectNodeComponent < NodeInfo > ;
@@ -26,7 +48,7 @@ export const getSplitByCase = (updated: () => void): NodeTask<NodeInfo> => {
2648 const computeAsync = (
2749 input : string ,
2850 loopIndex ?: number ,
29- _payload ?: any ,
51+ payload ?: any ,
3052 _thumbName ?: string ,
3153 scopeId ?: string ,
3254 runCounterCompute ?: RunCounter
@@ -47,10 +69,30 @@ export const getSplitByCase = (updated: () => void): NodeTask<NodeInfo> => {
4769 const case1 = node ?. nodeInfo ?. formValues ?. [ 'case1' ] ?? '' ;
4870 const case2 = node ?. nodeInfo ?. formValues ?. [ 'case2' ] ?? '' ;
4971 const case3 = node ?. nodeInfo ?. formValues ?. [ 'case3' ] ?? '' ;
72+ const useExpression =
73+ node ?. nodeInfo ?. formValues ?. [ 'useExpression' ] ?? false ;
5074
5175 let thumbNode : IThumbNodeComponent < NodeInfo > | undefined = undefined ;
5276 if ( input !== 'true' ) {
53- if ( typeof inputAsString === 'string' ) {
77+ if ( useExpression ) {
78+ const payloadForExpression = getVariablePayloadInputUtils (
79+ input ,
80+ payload ,
81+ 'string' ,
82+ - 1 ,
83+ - 1 ,
84+ scopeId ,
85+ canvasAppInstance
86+ ) ;
87+
88+ if ( handleExpression ( case1 , payloadForExpression ) ) {
89+ thumbNode = node . thumbConnectors [ 0 ] ;
90+ } else if ( handleExpression ( case2 , payloadForExpression ) ) {
91+ thumbNode = node . thumbConnectors [ 1 ] ;
92+ } else if ( handleExpression ( case3 , payloadForExpression ) ) {
93+ thumbNode = node . thumbConnectors [ 2 ] ;
94+ }
95+ } else if ( typeof inputAsString === 'string' ) {
5496 if ( case1 && inputAsString === case1 ) {
5597 thumbNode = node . thumbConnectors [ 0 ] ;
5698 } else if ( case2 && inputAsString === case2 ) {
@@ -101,7 +143,9 @@ export const getSplitByCase = (updated: () => void): NodeTask<NodeInfo> => {
101143 y : number ,
102144 id ?: string ,
103145 initalValues ?: InitialValues ,
104- containerNode ?: IRectNodeComponent < NodeInfo >
146+ containerNode ?: IRectNodeComponent < NodeInfo > ,
147+ width ?: number ,
148+ height ?: number
105149 ) => {
106150 canvasAppInstance = canvasApp ;
107151 const formElements = [
@@ -160,6 +204,25 @@ export const getSplitByCase = (updated: () => void): NodeTask<NodeInfo> => {
160204 case3 : value ,
161205 } ;
162206
207+ if ( updated ) {
208+ updated ( ) ;
209+ }
210+ } ,
211+ } ,
212+ {
213+ fieldType : FormFieldType . Checkbox ,
214+ fieldName : 'useExpression' ,
215+ label : 'Use expressions' ,
216+ value : initalValues ?. [ 'useExpression' ] ?? 'false' ,
217+ onChange : ( value : boolean ) => {
218+ if ( ! node . nodeInfo ) {
219+ return ;
220+ }
221+ node . nodeInfo . formValues = {
222+ ...node . nodeInfo . formValues ,
223+ useExpression : value ,
224+ } ;
225+
163226 if ( updated ) {
164227 updated ( ) ;
165228 }
@@ -187,8 +250,8 @@ export const getSplitByCase = (updated: () => void): NodeTask<NodeInfo> => {
187250 const rect = canvasApp . createRect (
188251 x ,
189252 y ,
190- 200 ,
191- 110 ,
253+ width ?? 200 ,
254+ height ?? 110 ,
192255 undefined ,
193256 [
194257 {
@@ -233,7 +296,7 @@ export const getSplitByCase = (updated: () => void): NodeTask<NodeInfo> => {
233296 {
234297 classNames : `bg-slate-500 p-4 rounded` ,
235298 } ,
236- false ,
299+ true ,
237300 undefined ,
238301 undefined ,
239302 id ,
@@ -252,6 +315,9 @@ export const getSplitByCase = (updated: () => void): NodeTask<NodeInfo> => {
252315 node . nodeInfo . formElements = formElements ;
253316 node . nodeInfo . computeAsync = computeAsync ;
254317 node . nodeInfo . initializeCompute = initializeCompute ;
318+ node . nodeInfo . showFormOnlyInPopup = false ;
319+ node . nodeInfo . hasNoFormPopup = true ;
320+ node . nodeInfo . isSettingsPopup = false ;
255321 }
256322 return node ;
257323 } ,
0 commit comments