@@ -227,45 +227,38 @@ const DeterministicContent = ({
227
227
}
228
228
229
229
const handleDeleteRow = ( index : number ) => {
230
- const newComparators = [ ...comparators ]
231
- const newFields = [ ...fields ]
232
- const newOperators = [ ...operators ]
233
- newComparators . splice ( index , 1 )
234
- newFields . splice ( index , 1 )
235
-
230
+ const updateArray = ( arr : any [ ] , idx : number ) => {
231
+ const newArr = [ ...arr ] ;
232
+ newArr . splice ( idx , 1 ) ;
233
+ return newArr ;
234
+ } ;
235
+
236
+ setComparators ( updateArray ( comparators , index ) ) ;
237
+ setFields ( updateArray ( fields , index ) ) ;
236
238
if ( index > 0 ) {
237
- newOperators . splice ( index - 1 , 1 )
239
+ setOperators ( updateArray ( operators , index - 1 ) ) ;
238
240
}
239
-
240
- setComparators ( newComparators )
241
- setFields ( newFields )
242
- setOperators ( newOperators )
243
-
244
- const updatedConfiguration = { ...configuration }
241
+
242
+ const updatedConfiguration = { ...configuration } ;
245
243
const ruleType =
246
244
currentTab === 'link'
247
245
? 'link'
248
246
: currentTab === 'validate'
249
247
? 'validate'
250
- : 'matchNotification'
251
-
252
- if ( newFields . length === 0 ) {
253
- const newRules = [ ...rules ]
254
- newRules . splice ( index , 1 )
255
- setRules ( newRules )
256
-
257
- if ( updatedConfiguration . rules && updatedConfiguration . rules [ ruleType ] ) {
258
- updatedConfiguration . rules [ ruleType ] . deterministic . splice ( index , 1 )
248
+ : 'matchNotification' ;
249
+
250
+ if ( fields . length === 0 ) {
251
+ const newRules = updateArray ( rules , index ) ;
252
+ setRules ( newRules ) ;
253
+
254
+ if ( updatedConfiguration . rules ?. [ ruleType ] ) {
255
+ updatedConfiguration . rules [ ruleType ] . deterministic . splice ( index , 1 ) ;
259
256
}
260
-
261
- setConfiguration ( updatedConfiguration as Configuration )
262
- localStorage . setItem (
263
- 'configuration' ,
264
- JSON . stringify ( updatedConfiguration )
265
- )
257
+
258
+ setConfiguration ( updatedConfiguration as Configuration ) ;
259
+ localStorage . setItem ( 'configuration' , JSON . stringify ( updatedConfiguration ) ) ;
266
260
}
267
- }
268
-
261
+ } ;
269
262
return (
270
263
< Box >
271
264
< Box
0 commit comments