@@ -46,8 +46,8 @@ import {
46
46
TriangleAlert ,
47
47
} from "lucide-react" ;
48
48
import { type FC , useEffect , useId , useRef , useState } from "react" ;
49
- import { maskText } from "utils/text" ;
50
49
import type { AutofillBuildParameter } from "utils/richParameters" ;
50
+ import { maskText } from "utils/text" ;
51
51
import * as Yup from "yup" ;
52
52
53
53
interface DynamicParameterProps {
@@ -782,119 +782,120 @@ export const useValidationSchemaForDynamicParameters = (
782
782
. of (
783
783
Yup . object ( ) . shape ( {
784
784
name : Yup . string ( ) . required ( ) ,
785
- value : Yup . string ( ) . test ( "verify with template" , ( val , ctx ) => {
786
- const name = ctx . parent . name ;
787
- const parameter = parameters . find (
788
- ( parameter ) => parameter . name === name ,
789
- ) ;
790
- if ( parameter ) {
791
- switch ( parameter . type ) {
792
- case "number" : {
793
- const minValidation = parameter . validations . find (
794
- ( v ) => v . validation_min !== null ,
795
- ) ;
796
- const maxValidation = parameter . validations . find (
797
- ( v ) => v . validation_max !== null ,
798
- ) ;
799
-
800
- if (
801
- minValidation &&
802
- minValidation . validation_min !== null &&
803
- ! maxValidation &&
804
- Number ( val ) < minValidation . validation_min
805
- ) {
806
- return ctx . createError ( {
807
- path : ctx . path ,
808
- message :
809
- parameterError ( parameter , val ) ??
810
- `Value must be greater than ${ minValidation . validation_min } .` ,
811
- } ) ;
812
- }
785
+ value : Yup . string ( )
786
+ . test ( "verify with template" , ( val , ctx ) => {
787
+ const name = ctx . parent . name ;
788
+ const parameter = parameters . find (
789
+ ( parameter ) => parameter . name === name ,
790
+ ) ;
791
+ if ( parameter ) {
792
+ switch ( parameter . type ) {
793
+ case "number" : {
794
+ const minValidation = parameter . validations . find (
795
+ ( v ) => v . validation_min !== null ,
796
+ ) ;
797
+ const maxValidation = parameter . validations . find (
798
+ ( v ) => v . validation_max !== null ,
799
+ ) ;
813
800
814
- if (
815
- ! minValidation &&
816
- maxValidation &&
817
- maxValidation . validation_max !== null &&
818
- Number ( val ) > maxValidation . validation_max
819
- ) {
820
- return ctx . createError ( {
821
- path : ctx . path ,
822
- message :
823
- parameterError ( parameter , val ) ??
824
- `Value must be less than ${ maxValidation . validation_max } .` ,
825
- } ) ;
826
- }
801
+ if (
802
+ minValidation &&
803
+ minValidation . validation_min !== null &&
804
+ ! maxValidation &&
805
+ Number ( val ) < minValidation . validation_min
806
+ ) {
807
+ return ctx . createError ( {
808
+ path : ctx . path ,
809
+ message :
810
+ parameterError ( parameter , val ) ??
811
+ `Value must be greater than ${ minValidation . validation_min } .` ,
812
+ } ) ;
813
+ }
827
814
828
- if (
829
- minValidation &&
830
- minValidation . validation_min !== null &&
831
- maxValidation &&
832
- maxValidation . validation_max !== null &&
833
- ( Number ( val ) < minValidation . validation_min ||
834
- Number ( val ) > maxValidation . validation_max )
835
- ) {
836
- return ctx . createError ( {
837
- path : ctx . path ,
838
- message :
839
- parameterError ( parameter , val ) ??
840
- `Value must be between ${ minValidation . validation_min } and ${ maxValidation . validation_max } .` ,
841
- } ) ;
842
- }
815
+ if (
816
+ ! minValidation &&
817
+ maxValidation &&
818
+ maxValidation . validation_max !== null &&
819
+ Number ( val ) > maxValidation . validation_max
820
+ ) {
821
+ return ctx . createError ( {
822
+ path : ctx . path ,
823
+ message :
824
+ parameterError ( parameter , val ) ??
825
+ `Value must be less than ${ maxValidation . validation_max } .` ,
826
+ } ) ;
827
+ }
843
828
844
- const monotonic = parameter . validations . find (
845
- ( v ) =>
846
- v . validation_monotonic !== null &&
847
- v . validation_monotonic !== "" ,
848
- ) ;
829
+ if (
830
+ minValidation &&
831
+ minValidation . validation_min !== null &&
832
+ maxValidation &&
833
+ maxValidation . validation_max !== null &&
834
+ ( Number ( val ) < minValidation . validation_min ||
835
+ Number ( val ) > maxValidation . validation_max )
836
+ ) {
837
+ return ctx . createError ( {
838
+ path : ctx . path ,
839
+ message :
840
+ parameterError ( parameter , val ) ??
841
+ `Value must be between ${ minValidation . validation_min } and ${ maxValidation . validation_max } .` ,
842
+ } ) ;
843
+ }
849
844
850
- if ( monotonic && lastBuildParameters ) {
851
- const lastBuildParameter = lastBuildParameters . find (
852
- ( last : { name : string } ) => last . name === name ,
845
+ const monotonic = parameter . validations . find (
846
+ ( v ) =>
847
+ v . validation_monotonic !== null &&
848
+ v . validation_monotonic !== "" ,
853
849
) ;
854
- if ( lastBuildParameter ) {
855
- switch ( monotonic . validation_monotonic ) {
856
- case "increasing" :
857
- if ( Number ( lastBuildParameter . value ) > Number ( val ) ) {
858
- return ctx . createError ( {
859
- path : ctx . path ,
860
- message : `Value must only ever increase (last value was ${ lastBuildParameter . value } )` ,
861
- } ) ;
862
- }
863
- break ;
864
- case "decreasing" :
865
- if ( Number ( lastBuildParameter . value ) < Number ( val ) ) {
866
- return ctx . createError ( {
867
- path : ctx . path ,
868
- message : `Value must only ever decrease (last value was ${ lastBuildParameter . value } )` ,
869
- } ) ;
870
- }
871
- break ;
850
+
851
+ if ( monotonic && lastBuildParameters ) {
852
+ const lastBuildParameter = lastBuildParameters . find (
853
+ ( last : { name : string } ) => last . name === name ,
854
+ ) ;
855
+ if ( lastBuildParameter ) {
856
+ switch ( monotonic . validation_monotonic ) {
857
+ case "increasing" :
858
+ if ( Number ( lastBuildParameter . value ) > Number ( val ) ) {
859
+ return ctx . createError ( {
860
+ path : ctx . path ,
861
+ message : `Value must only ever increase (last value was ${ lastBuildParameter . value } )` ,
862
+ } ) ;
863
+ }
864
+ break ;
865
+ case "decreasing" :
866
+ if ( Number ( lastBuildParameter . value ) < Number ( val ) ) {
867
+ return ctx . createError ( {
868
+ path : ctx . path ,
869
+ message : `Value must only ever decrease (last value was ${ lastBuildParameter . value } )` ,
870
+ } ) ;
871
+ }
872
+ break ;
873
+ }
872
874
}
873
875
}
876
+ break ;
874
877
}
875
- break ;
876
- }
877
- case "string" : {
878
- const regex = parameter . validations . find (
879
- ( v ) =>
880
- v . validation_regex !== null && v . validation_regex !== "" ,
881
- ) ;
882
- if ( ! regex || ! regex . validation_regex ) {
883
- return true ;
884
- }
878
+ case "string" : {
879
+ const regex = parameter . validations . find (
880
+ ( v ) =>
881
+ v . validation_regex !== null && v . validation_regex !== "" ,
882
+ ) ;
883
+ if ( ! regex || ! regex . validation_regex ) {
884
+ return true ;
885
+ }
885
886
886
- if ( val && ! new RegExp ( regex . validation_regex ) . test ( val ) ) {
887
- return ctx . createError ( {
888
- path : ctx . path ,
889
- message : parameterError ( parameter , val ) ,
890
- } ) ;
887
+ if ( val && ! new RegExp ( regex . validation_regex ) . test ( val ) ) {
888
+ return ctx . createError ( {
889
+ path : ctx . path ,
890
+ message : parameterError ( parameter , val ) ,
891
+ } ) ;
892
+ }
893
+ break ;
891
894
}
892
- break ;
893
895
}
894
896
}
895
- }
896
- return true ;
897
- } ) ,
897
+ return true ;
898
+ } ) ,
898
899
} ) ,
899
900
)
900
901
. required ( ) ;
0 commit comments