@@ -44,6 +44,11 @@ const FormSchema = z.object({
4444 required_error : 'biasSettings.form.errors.dataTypeRequired' ,
4545 } )
4646 . nonempty ( ) ,
47+ selectedDataType : z
48+ . string ( {
49+ required_error : 'biasSettings.form.errors.dataTypeRequired' ,
50+ } )
51+ . nonempty ( ) ,
4752} ) ;
4853
4954export default function BiasSettings ( {
@@ -72,6 +77,7 @@ export default function BiasSettings({
7277
7378 const [ performanceMetricColumnError , setPerformanceMetricColumnError ] =
7479 useState < string | null > ( null ) ;
80+ const [ dataTypeError , setDataTypeError ] = useState < string | null > ( null ) ;
7581
7682 const [ dataKey , setDataKey ] = useState < string > ( new Date ( ) . toISOString ( ) ) ;
7783 const [ data , setData ] = useState < {
@@ -88,7 +94,7 @@ export default function BiasSettings({
8894 const isReset = stringified . length === 0 ;
8995 if ( isReset ) {
9096 form . reset ( ) ;
91- //setDefaultDataType('numeric' );
97+ setDataTypeError ( null ) ;
9298 } else {
9399 form . setValue ( 'file' , stringified ) ;
94100 }
@@ -98,6 +104,7 @@ export default function BiasSettings({
98104 setClusters ( [ Math . round ( dataLength / 4 ) ] ) ;
99105
100106 setPerformanceMetricColumnError ( null ) ;
107+ setDataTypeError ( null ) ;
101108 if ( ! isReset ) {
102109 // Find numeric columns
103110 const numericColumns = Object . keys ( data [ 0 ] || { } )
@@ -116,10 +123,8 @@ export default function BiasSettings({
116123
117124 if ( numericColumns . length === Object . keys ( data [ 0 ] || { } ) . length ) {
118125 form . setValue ( 'dataType' , 'numeric' ) ;
119- //setDefaultDataType('numeric');
120126 } else {
121127 form . setValue ( 'dataType' , 'categorical' ) ;
122- //setDefaultDataType('categorical');
123128 }
124129 }
125130
@@ -142,21 +147,18 @@ export default function BiasSettings({
142147 ) ;
143148 } ;
144149
145- const onSubmit = ( data : z . infer < typeof FormSchema > ) => {
150+ const onSubmit = ( formData : z . infer < typeof FormSchema > ) => {
146151 // Check if data type matches the actual data
147- const isNumericData = data . data . every ( row => {
148- return ! isNaN ( parseFloat ( row [ data . targetColumn ] ) ) ;
149- } ) ;
150152
151- if ( data . dataType === 'numeric' && ! isNumericData ) {
152- setPerformanceMetricColumnError (
153- t ( 'biasSettings.form.errors.numericDataRequired' )
154- ) ;
153+ const isNumericData = formData . dataType === 'numeric' ;
154+
155+ if ( formData . selectedDataType === 'numeric' && ! isNumericData ) {
156+ setDataTypeError ( t ( 'biasSettings.form.errors.numericDataRequired' ) ) ;
155157 return ;
156158 }
157159
158- if ( data . dataType === 'categorical' && isNumericData ) {
159- setPerformanceMetricColumnError (
160+ if ( formData . dataType === 'categorical' && isNumericData ) {
161+ setDataTypeError (
160162 t ( 'biasSettings.form.errors.categoricalDataRequired' )
161163 ) ;
162164 return ;
@@ -165,10 +167,10 @@ export default function BiasSettings({
165167 onRun ( {
166168 clusterSize : clusters [ 0 ] ,
167169 iterations : iter [ 0 ] ,
168- targetColumn : data . targetColumn ,
169- dataType : data . dataType ,
170+ targetColumn : formData . targetColumn ,
171+ dataType : formData . dataType ,
170172 higherIsBetter :
171- data . whichPerformanceMetricValueIsBetter === 'higher' ,
173+ formData . whichPerformanceMetricValueIsBetter === 'higher' ,
172174 isDemo : false ,
173175 } ) ;
174176 } ;
@@ -281,7 +283,7 @@ export default function BiasSettings({
281283 < div className = "grid gap-3" >
282284 < FormField
283285 control = { form . control }
284- name = "dataType "
286+ name = "selectedDataType "
285287 disabled = { isLoading }
286288 render = { ( { field } ) => (
287289 < FormItem >
@@ -291,9 +293,12 @@ export default function BiasSettings({
291293 ) }
292294 </ FormLabel >
293295 < RadioGroup
294- onValueChange = { field . onChange }
296+ onValueChange = { value => {
297+ setDataTypeError ( null ) ;
298+ field . onChange ( value ) ;
299+ } }
295300 defaultValue = { field . value }
296- key = { `${ dataKey } _dataType ` }
301+ key = { `${ dataKey } _selecteddataType ` }
297302 className = "flex flex-col space-y-1"
298303 >
299304 < FormItem className = "flex items-center space-x-3 space-y-0" >
@@ -323,6 +328,11 @@ export default function BiasSettings({
323328 </ FormLabel >
324329 </ FormItem >
325330 </ RadioGroup >
331+ { dataTypeError && (
332+ < div className = "text-red-500 text-sm mt-1" >
333+ { dataTypeError }
334+ </ div >
335+ ) }
326336 </ FormItem >
327337 ) }
328338 />
0 commit comments