@@ -56,44 +56,6 @@ export function ConfigForm(props: ConfigFormProps): JSX.Element {
56
56
groupLabels,
57
57
} = props
58
58
59
- const getInitialValues : ( ) => FormValues = ( ) => {
60
- const fields = getVisibleFields ( )
61
- const initialFieldValues = mapValues <
62
- PipetteSettingsFieldsMap ,
63
- string | boolean
64
- > ( fields , f => {
65
- if ( f . value === true || f . value === false ) return f . value
66
- // @ts -expect-error(sa, 2021-05-27): avoiding src code change, use optional chain to access f.value
67
- return f . value !== f . default ? f . value . toString ( ) : ''
68
- } )
69
- const initialQuirkValues = settings [ QUIRK_KEY ]
70
- const initialValues = Object . assign (
71
- { } ,
72
- initialFieldValues ,
73
- initialQuirkValues
74
- )
75
-
76
- return initialValues
77
- }
78
- const initialValues = getInitialValues ( )
79
-
80
- const resolver : Resolver < FormValues > = values => {
81
- let errors = { }
82
- errors = validate ( values , errors )
83
- return { values, errors }
84
- }
85
-
86
- const {
87
- handleSubmit,
88
- reset,
89
- getValues,
90
- control,
91
- formState : { errors } ,
92
- } = useForm < FormValues > ( {
93
- defaultValues : initialValues ,
94
- resolver : resolver ,
95
- } )
96
-
97
59
const getFieldsByKey = (
98
60
keys : string [ ] ,
99
61
fields : PipetteSettingsFieldsMap
@@ -205,6 +167,26 @@ export function ConfigForm(props: ConfigFormProps): JSX.Element {
205
167
return errors
206
168
}
207
169
170
+ const getInitialValues : ( ) => FormValues = ( ) => {
171
+ const fields = getVisibleFields ( )
172
+ const initialFieldValues = mapValues <
173
+ PipetteSettingsFieldsMap ,
174
+ string | boolean
175
+ > ( fields , f => {
176
+ if ( f . value === true || f . value === false ) return f . value
177
+ // @ts -expect-error(sa, 2021-05-27): avoiding src code change, use optional chain to access f.value
178
+ return f . value !== f . default ? f . value . toString ( ) : ''
179
+ } )
180
+ const initialQuirkValues = settings [ QUIRK_KEY ]
181
+ const initialValues = Object . assign (
182
+ { } ,
183
+ initialFieldValues ,
184
+ initialQuirkValues
185
+ )
186
+
187
+ return initialValues
188
+ }
189
+
208
190
const fields = getVisibleFields ( )
209
191
const UNKNOWN_KEYS = getUnknownKeys ( )
210
192
const plungerFields = getFieldsByKey ( PLUNGER_KEYS , fields )
@@ -213,6 +195,24 @@ export function ConfigForm(props: ConfigFormProps): JSX.Element {
213
195
const quirkFields = getKnownQuirks ( )
214
196
const quirksPresent = quirkFields . length > 0
215
197
const unknownFields = getFieldsByKey ( UNKNOWN_KEYS , fields )
198
+ const initialValues = getInitialValues ( )
199
+
200
+ const resolver : Resolver < FormValues > = values => {
201
+ let errors = { }
202
+ errors = validate ( values , errors )
203
+ return { values, errors }
204
+ }
205
+
206
+ const {
207
+ handleSubmit,
208
+ reset,
209
+ getValues,
210
+ control,
211
+ formState : { errors } ,
212
+ } = useForm < FormValues > ( {
213
+ defaultValues : initialValues ,
214
+ resolver : resolver ,
215
+ } )
216
216
217
217
const handleReset = ( ) : void => {
218
218
const newValues = mapValues ( getValues ( ) , v => {
0 commit comments