1
1
import { get } from "lodash" ;
2
2
import type { ReactNode } from "react" ;
3
+ import { useMemo } from "react" ;
3
4
import React , { useCallback , useState } from "react" ;
4
5
import { useTranslation } from "react-i18next" ;
5
6
7
+ import type ProcessUtils from "../../../../../common/ProcessUtils" ;
6
8
import type { NodeType , NodeValidationError , UIParameter } from "../../../../../types" ;
7
9
import { useDiffMark } from "../../PathsToMark" ;
8
10
import { useTestResults } from "../../TestResultsWrapper" ;
@@ -20,13 +22,14 @@ type Props = {
20
22
isEditMode : boolean ;
21
23
showValidation : boolean ;
22
24
showSwitch : boolean ;
25
+ findAvailableVariables : ReturnType < typeof ProcessUtils . findAvailableVariables > ;
23
26
setNodeDataAt : < T > ( propToMutate : string , newValue : T , defaultValue ?: T ) => void ;
24
27
renderFieldLabel : ( paramName : string ) => ReactNode ;
25
28
errors : NodeValidationError [ ] ;
26
29
} ;
27
30
28
31
function MockExpressionField ( props : Props ) : JSX . Element {
29
- const { editedNode, isEditMode, showValidation, showSwitch, setNodeDataAt, renderFieldLabel, errors } = props ;
32
+ const { editedNode, isEditMode, showValidation, showSwitch, findAvailableVariables , setNodeDataAt, renderFieldLabel, errors } = props ;
30
33
const [ mockExpression , setMockExpression ] = useState ( ( ) => {
31
34
return get ( editedNode , MOCK_EXPRESSION_FIELD_NAME ) || { expression : "" , language : "spel" } ;
32
35
} ) ;
@@ -46,6 +49,8 @@ function MockExpressionField(props: Props): JSX.Element {
46
49
[ setNodeDataAt ] ,
47
50
) ;
48
51
52
+ const variableTypes = useMemo ( ( ) => findAvailableVariables ( editedNode . id ) , [ findAvailableVariables , editedNode . id ] ) ;
53
+
49
54
const { t } = useTranslation ( ) ;
50
55
const testResultsState = useTestResults ( ) ;
51
56
@@ -59,7 +64,7 @@ function MockExpressionField(props: Props): JSX.Element {
59
64
const mockExpressionParameter : UIParameter = {
60
65
additionalVariables : { } ,
61
66
branchParam : false ,
62
- defaultValue : { expression : "" , language : undefined } ,
67
+ defaultValue : { expression : "" , language : "spel" } ,
63
68
editor : { type : EditorType . SPEL_PARAMETER_EDITOR } ,
64
69
label : "" ,
65
70
name : MOCK_EXPRESSION_FIELD_NAME ,
@@ -78,9 +83,9 @@ function MockExpressionField(props: Props): JSX.Element {
78
83
showValidation = { showValidation }
79
84
showSwitch = { showSwitch }
80
85
readOnly = { readOnly }
81
- variableTypes = { { } }
86
+ variableTypes = { variableTypes }
82
87
onValueChange = { onValueChange }
83
- fieldErrors = { getValidationErrorsForField ( errors , MOCK_EXPRESSION_FIELD_NAME ) } // todo: check if it works
88
+ fieldErrors = { getValidationErrorsForField ( errors , MOCK_EXPRESSION_FIELD_NAME ) }
84
89
/>
85
90
</ ExpressionTestResults >
86
91
) ;
0 commit comments