@@ -27,21 +27,29 @@ export const MeasurementForm = ({
2727 displayUnits : measurement . displayUnits || '' ,
2828 podUnits : measurement . podUnits || ''
2929 } ) ;
30+ const [ enumInputValue , setEnumInputValue ] = useState ( measurement . enumValues ?. join ( ', ' ) || '' ) ;
3031 const [ originalId ] = useState ( measurement . id ) ;
3132
3233 const handleSubmit = ( e : React . FormEvent ) => {
3334 e . preventDefault ( ) ;
3435
36+ // Process enum values before validation
37+ const processedEnumValues = enumInputValue . split ( ',' ) . map ( v => v . trim ( ) ) . filter ( v => v . length > 0 ) ;
38+ const finalFormData = {
39+ ...formData ,
40+ enumValues : processedEnumValues
41+ } ;
42+
3543 // Validate required fields
36- if ( ! formData . id . trim ( ) ) {
44+ if ( ! finalFormData . id . trim ( ) ) {
3745 alert ( 'ID cannot be empty' ) ;
3846 return ;
3947 }
40- if ( ! formData . name . trim ( ) ) {
48+ if ( ! finalFormData . name . trim ( ) ) {
4149 alert ( 'Name cannot be empty' ) ;
4250 return ;
4351 }
44- if ( ! formData . type . trim ( ) ) {
52+ if ( ! finalFormData . type . trim ( ) ) {
4553 alert ( 'Type cannot be empty' ) ;
4654 return ;
4755 }
@@ -57,7 +65,7 @@ export const MeasurementForm = ({
5765
5866 if ( boardIndex !== - 1 ) {
5967 const existingMeasurement = config . boards [ boardIndex ] [ boardName ] . measurements . find (
60- ( m : Measurement ) => m . id === formData . id && m . id !== originalId
68+ ( m : Measurement ) => m . id === finalFormData . id && m . id !== originalId
6169 ) ;
6270
6371 if ( existingMeasurement ) {
@@ -67,44 +75,44 @@ export const MeasurementForm = ({
6775 }
6876
6977 if ( isCreating ) {
70- addMeasurement ( boardName , formData ) ;
78+ addMeasurement ( boardName , finalFormData ) ;
7179 } else {
72- if ( originalId !== formData . id ) {
80+ if ( originalId !== finalFormData . id ) {
7381 removeMeasurement ( boardName , originalId ) ;
74- addMeasurement ( boardName , formData ) ;
82+ addMeasurement ( boardName , finalFormData ) ;
7583 } else {
76- updateMeasurement ( boardName , measurement . id , 'id' , formData . id ) ;
77- updateMeasurement ( boardName , measurement . id , 'name' , formData . name ) ;
78- updateMeasurement ( boardName , measurement . id , 'type' , formData . type ) ;
84+ updateMeasurement ( boardName , measurement . id , 'id' , finalFormData . id ) ;
85+ updateMeasurement ( boardName , measurement . id , 'name' , finalFormData . name ) ;
86+ updateMeasurement ( boardName , measurement . id , 'type' , finalFormData . type ) ;
7987 updateMeasurement (
8088 boardName ,
8189 measurement . id ,
8290 'displayUnits' ,
83- formData . displayUnits ,
91+ finalFormData . displayUnits ,
8492 ) ;
8593 updateMeasurement (
8694 boardName ,
8795 measurement . id ,
8896 'podUnits' ,
89- formData . podUnits ,
97+ finalFormData . podUnits ,
9098 ) ;
9199 updateMeasurement (
92100 boardName ,
93101 measurement . id ,
94102 'enumValues' ,
95- formData . enumValues ,
103+ finalFormData . enumValues ,
96104 ) ;
97105 updateMeasurement (
98106 boardName ,
99107 measurement . id ,
100108 'safeRange' ,
101- formData . safeRange ,
109+ finalFormData . safeRange ,
102110 ) ;
103111 updateMeasurement (
104112 boardName ,
105113 measurement . id ,
106114 'warningRange' ,
107- formData . warningRange ,
115+ finalFormData . warningRange ,
108116 ) ;
109117 }
110118 }
@@ -156,146 +164,107 @@ export const MeasurementForm = ({
156164 label = "Name"
157165 />
158166
159- < Input
160- object = { formData }
161- field = { 'type' }
162- setObject = { ( field , value ) =>
163- updateFormField ( 'type' , field , value )
164- }
165- label = "Type"
166- />
167+ < div className = "mb-2" >
168+ < label className = "block text-sm font-medium text-gray-700 mb-1" > Type</ label >
169+ < select
170+ value = { formData . type }
171+ onChange = { ( e ) => updateFormField ( 'type' , 'type' , e . target . value ) }
172+ className = "w-full border border-gray-300 rounded-md px-3 py-2 focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200"
173+ >
174+ < option value = "float32" > float32</ option >
175+ < option value = "float64" > float64</ option >
176+ < option value = "uint16" > uint16</ option >
177+ < option value = "uint32" > uint32</ option >
178+ < option value = "bool" > bool</ option >
179+ < option value = "enum" > enum</ option >
180+ </ select >
181+ </ div >
167182
168- < Input
169- object = { formData }
170- field = { 'displayUnits' }
171- setObject = { ( field , value ) =>
172- updateFormField ( 'displayUnits' , field , value )
173- }
174- label = "Display Units"
175- />
183+ { formData . type !== 'enum' && (
184+ < >
185+ < Input
186+ object = { formData }
187+ field = { 'displayUnits' }
188+ setObject = { ( field , value ) =>
189+ updateFormField ( 'displayUnits' , field , value )
190+ }
191+ label = "Display Units"
192+ />
176193
177- < Input
178- object = { formData }
179- field = { 'podUnits' }
180- setObject = { ( field , value ) =>
181- updateFormField ( 'podUnits' , field , value )
182- }
183- label = "Pod Units"
184- />
194+ < Input
195+ object = { formData }
196+ field = { 'podUnits' }
197+ setObject = { ( field , value ) =>
198+ updateFormField ( 'podUnits' , field , value )
199+ }
200+ label = "Pod Units"
201+ />
202+ </ >
203+ ) }
185204
186- < div className = "mb-2 flex flex-col gap-2" >
187- < div className = "flex items-center justify-between" >
188- < label className = "text-sm font-medium text-gray-700" >
189- Enum Values ({ formData . enumValues ?. length || 0 } )
190- </ label >
205+ { formData . type === 'enum' && (
206+ < div className = "mb-2" >
207+ < label className = "block text-sm font-medium text-gray-700 mb-1" > Enum Values (comma-separated)</ label >
208+ < input
209+ type = "text"
210+ value = { enumInputValue }
211+ onChange = { ( e ) => setEnumInputValue ( e . target . value ) }
212+ onBlur = { ( e ) => {
213+ const values = e . target . value . split ( ',' ) . map ( v => v . trim ( ) ) . filter ( v => v . length > 0 ) ;
214+ updateFormField ( 'enumValues' , 'enumValues' , values ) ;
215+ } }
216+ placeholder = "Value1, Value2, Value3"
217+ className = "w-full border border-gray-300 rounded-md px-3 py-2 focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200"
218+ />
191219 </ div >
220+ ) }
221+ { formData . type !== 'enum' && (
222+ < >
223+ < div className = "flex w-full gap-4" >
224+ < Input
225+ object = { { safeMin : formData . safeRange ?. [ 0 ] || 0 } }
226+ field = { 'safeMin' }
227+ setObject = { ( _ , value ) =>
228+ updateFormField ( 'safeRange' , '0' , value )
229+ }
230+ label = "Safe Range Min"
231+ className = 'flex-1'
232+ />
192233
193- < details className = "rounded-lg" >
194- < summary className = "cursor-pointer" >
195- Show/Hide Enum Values
196- </ summary >
197- < div className = "mt-3 space-y-2" >
198- { ( formData . enumValues || [ ] ) . map ( ( value , index ) => (
199- < div key = { index } className = "flex gap-2" >
200- < input
201- type = "text"
202- value = { value }
203- onChange = { ( e ) => {
204- const newValues = [
205- ...( formData . enumValues || [ ] ) ,
206- ] ;
207- newValues [ index ] =
208- e . target . value ;
209- updateFormField (
210- 'enumValues' ,
211- 'enumValues' ,
212- newValues ,
213- ) ;
214- } }
215- className = "block w-full rounded-lg border border-gray-300 p-2.5 focus:border-blue-500 focus:ring-blue-500"
216- />
217- < button
218- type = "button"
219- onClick = { ( ) => {
220- const newValues =
221- ( formData . enumValues || [ ] ) . filter (
222- ( _ , i ) => i !== index ,
223- ) ;
224- updateFormField (
225- 'enumValues' ,
226- 'enumValues' ,
227- newValues ,
228- ) ;
229- } }
230- className = "cursor-pointer rounded-lg bg-red-500 px-3 text-white hover:bg-red-600"
231- >
232- < i className = "fa-solid fa-xmark" > </ i >
233- </ button >
234- </ div >
235- ) ) }
234+ < Input
235+ object = { { safeMax : formData . safeRange ?. [ 1 ] || 0 } }
236+ field = { 'safeMax' }
237+ setObject = { ( _ , value ) =>
238+ updateFormField ( 'safeRange' , '1' , value )
239+ }
240+ label = "Safe Range Max"
241+ className = 'flex-1'
242+ />
236243 </ div >
237- < button
238- type = "button"
239- onClick = { ( ) => {
240- const newValues = [
241- ...( formData . enumValues || [ ] ) ,
242- '' ,
243- ] ;
244- updateFormField (
245- 'enumValues' ,
246- 'enumValues' ,
247- newValues ,
248- ) ;
249- } }
250- className = "mt-4 cursor-pointer rounded-lg bg-blue-500 px-3 py-1 text-white hover:bg-blue-600"
251- >
252- < i className = "fa-solid fa-plus" > </ i >
253- </ button >
254- </ details >
255- </ div >
256- < div className = "flex w-full gap-4" >
257- < Input
258- object = { { safeMin : formData . safeRange ?. [ 0 ] || 0 } }
259- field = { 'safeMin' }
260- setObject = { ( _ , value ) =>
261- updateFormField ( 'safeRange' , '0' , value )
262- }
263- label = "Safe Range Min"
264- className = 'flex-1'
265- />
266244
267- < Input
268- object = { { safeMax : formData . safeRange ?. [ 1 ] || 0 } }
269- field = { 'safeMax' }
270- setObject = { ( _ , value ) =>
271- updateFormField ( 'safeRange' , '1' , value )
272- }
273- label = "Safe Range Max"
274- className = 'flex-1'
275- />
276- </ div >
245+ < div className = "flex w-full gap-4" >
246+ < Input
247+ object = { { warningMin : formData . warningRange ?. [ 0 ] || 0 } }
248+ field = { 'warningMin' }
249+ setObject = { ( _ , value ) =>
250+ updateFormField ( 'warningRange' , '0' , value )
251+ }
252+ label = "Warning Range Min"
253+ className = 'flex-1'
254+ / >
277255
278- < div className = "flex w-full gap-4" >
279- < Input
280- object = { { warningMin : formData . warningRange ?. [ 0 ] || 0 } }
281- field = { 'warningMin' }
282- setObject = { ( _ , value ) =>
283- updateFormField ( 'warningRange' , '0' , value )
284- }
285- label = "Warning Range Min"
286- className = 'flex-1'
287- />
288-
289- < Input
290- object = { { warningMax : formData . warningRange ?. [ 1 ] || 0 } }
291- field = { 'warningMax' }
292- setObject = { ( _ , value ) =>
293- updateFormField ( 'warningRange' , '1' , value )
294- }
295- label = "Warning Range Max"
296- className = 'flex-1'
297- />
298- </ div >
256+ < Input
257+ object = { { warningMax : formData . warningRange ?. [ 1 ] || 0 } }
258+ field = { 'warningMax' }
259+ setObject = { ( _ , value ) =>
260+ updateFormField ( 'warningRange' , '1' , value )
261+ }
262+ label = "Warning Range Max"
263+ className = 'flex-1'
264+ />
265+ </ div >
266+ </ >
267+ ) }
299268
300269 < div className = 'flex gap-4' >
301270 { ! isCreating && (
0 commit comments