44 Flow ,
55 LiteralValue ,
66 NodeFunction ,
7- NodeParameterValue ,
7+ NodeParameterValue , ParameterDefinition ,
88 ReferenceValue
99} from "@code0-tech/sagittarius-graphql-types" ;
1010import { FileTabsService } from "@code0-tech/pictor/dist/components/file-tabs/FileTabs.service" ;
@@ -30,9 +30,8 @@ export const FunctionFileDefaultComponent: React.FC<FunctionFileDefaultComponent
3030 const functionStore = useStore ( FunctionService )
3131 const flowService = useService ( FlowService )
3232 const fileTabsService = useService ( FileTabsService )
33- const validation = useFlowValidation ( flowId )
34-
3533 const changedParameters = React . useRef < Set < number > > ( new Set ( ) )
34+ const validation = useFlowValidation ( flowId )
3635
3736 const definition = React . useMemo ( ( ) => {
3837 return functionService . getById ( node . functionDefinition ?. id ! ! )
@@ -42,24 +41,24 @@ export const FunctionFileDefaultComponent: React.FC<FunctionFileDefaultComponent
4241 const values : Record < string , any > = { }
4342 definition ?. parameterDefinitions ?. nodes ?. forEach ( ( parameter , index ) => {
4443 const nodeParameter = node . parameters ?. nodes ?. [ index ]
45- values [ index ] = nodeParameter ?. value ?. __typename === "LiteralValue" ? ( typeof nodeParameter . value ?. value === "object" && nodeParameter . value ?. value != null ? JSON . stringify ( nodeParameter . value ?. value ) : nodeParameter . value . value ) : nodeParameter ?. value != null ? JSON . stringify ( nodeParameter ?. value ) : nodeParameter ?. value
44+ values [ parameter ! . id ! ] = nodeParameter ?. value ?. __typename === "LiteralValue" ? ( typeof nodeParameter . value ?. value === "object" && nodeParameter . value ?. value != null ? JSON . stringify ( nodeParameter . value ?. value ) : nodeParameter . value . value ) : nodeParameter ?. value != null ? JSON . stringify ( nodeParameter ?. value ) : nodeParameter ?. value
4645 } )
4746 return values
48- } , [ node ] )
47+ } , [ node , definition ] )
4948
5049 const validations = React . useMemo ( ( ) => {
5150 const values : Record < string , any > = { }
52- node . parameters ?. nodes ?. forEach ( ( parameter , index ) => {
53- values [ index ] = ( _ : any ) => {
54- const validationForParameter = validation ?. find ( v => v ? .parameterIndex === index && v ? .nodeId === node . id )
51+ definition ?. parameterDefinitions ?. nodes ?. forEach ( ( parameter , index ) => {
52+ values [ parameter ! . id ! ] = ( _ : any ) => {
53+ const validationForParameter = validation ?. find ( v => v . parameterIndex === index && v . nodeId === node . id )
5554 if ( validationForParameter ) {
5655 return validationForParameter ?. message ?. [ 0 ] ?. content ?? "Invalid value"
5756 }
5857 return null
5958 }
6059 } )
6160 return values
62- } , [ node , validation ] )
61+ } , [ validation , flowId , node , definition ] )
6362
6463 const onSubmit = React . useCallback ( ( values : any ) => {
6564 startTransition ( async ( ) => {
@@ -68,7 +67,7 @@ export const FunctionFileDefaultComponent: React.FC<FunctionFileDefaultComponent
6867 if ( typeof parameterIndex !== "number" ) return
6968 if ( ! changedParameters . current . has ( parameterIndex ) ) continue ;
7069 const nodeParameter = node . parameters ?. nodes ?. find ( p => p ?. parameterDefinition ?. id === parameterDefinition ?. id )
71- const syntaxSegment = values [ parameterIndex ]
70+ const syntaxSegment = values [ parameterDefinition ! . id ! ]
7271 const previousValue = nodeParameter ?. value as NodeParameterValue
7372 const syntaxValue = syntaxSegment ?. [ 0 ] ?. value ?? syntaxSegment ?. value ?? syntaxSegment ?? null as NodeFunction | LiteralValue | ReferenceValue | null
7473
@@ -111,13 +110,18 @@ export const FunctionFileDefaultComponent: React.FC<FunctionFileDefaultComponent
111110 } )
112111 } , [ flowService ] )
113112
114- const [ inputs , validate ] = useForm < Record < number , InputSyntaxSegment [ ] > > ( {
113+ const [ inputs , validate ] = useForm < Record < string , InputSyntaxSegment [ ] > > ( {
114+ useInitialValidation : true ,
115+ truthyValidationBeforeSubmit : false ,
115116 initialValues : initialValues ,
116117 validate : validations ,
117- truthyValidationBeforeSubmit : false ,
118118 onSubmit : onSubmit
119119 } )
120120
121+ React . useEffect ( ( ) => {
122+ validate ( )
123+ } , [ validation ] )
124+
121125 return < Flex style = { { gap : ".7rem" , flexDirection : "column" } } >
122126 { definition ?. parameterDefinitions ?. nodes ?. map ( ( parameterDefinition , index ) => {
123127
@@ -139,7 +143,7 @@ export const FunctionFileDefaultComponent: React.FC<FunctionFileDefaultComponent
139143 changedParameters . current . add ( index )
140144 validate ( )
141145 } }
142- { ...inputs . getInputProps ( index ) }
146+ { ...inputs . getInputProps ( parameterDefinition . id ! ) }
143147 />
144148 </ div >
145149 } ) }
0 commit comments