@@ -10,10 +10,11 @@ import {
10
10
IconButton
11
11
} from '@mui/material'
12
12
import AddIcon from '@mui/icons-material/Add'
13
- import { Field , Rule } from 'types/Configuration'
13
+ import { Configuration , Field , Rule } from 'types/Configuration'
14
14
import { transformFieldName } from 'utils/helpers'
15
15
import SourceView , { RowData } from './SourceView'
16
16
import { useConfiguration } from 'hooks/useUIConfiguration'
17
+ import { DeleteOutline } from '@mui/icons-material'
17
18
18
19
interface DeterministicContentProps {
19
20
demographicData : Field [ ]
@@ -225,6 +226,39 @@ const DeterministicContent = ({
225
226
return updatedConfiguration
226
227
}
227
228
229
+ const handleDeleteRow = ( index : number ) => {
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 ) ) ;
238
+ if ( index > 0 ) {
239
+ setOperators ( updateArray ( operators , index - 1 ) ) ;
240
+ }
241
+
242
+ const updatedConfiguration = { ...configuration } ;
243
+ const ruleType =
244
+ currentTab === 'link'
245
+ ? 'link'
246
+ : currentTab === 'validate'
247
+ ? 'validate'
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 ) ;
256
+ }
257
+
258
+ setConfiguration ( updatedConfiguration as Configuration ) ;
259
+ localStorage . setItem ( 'configuration' , JSON . stringify ( updatedConfiguration ) ) ;
260
+ }
261
+ } ;
228
262
return (
229
263
< Box >
230
264
< Box
@@ -318,6 +352,9 @@ const DeterministicContent = ({
318
352
label = "Select Field"
319
353
onChange = { event => handleFieldChange ( index , event ) }
320
354
>
355
+ < MenuItem value = "" disabled >
356
+ Select a field
357
+ </ MenuItem >
321
358
{ Array . isArray ( demographicData ) &&
322
359
demographicData . map ( demographicField => (
323
360
< MenuItem
@@ -353,6 +390,15 @@ const DeterministicContent = ({
353
390
) ) }
354
391
</ Select >
355
392
</ FormControl >
393
+ < IconButton
394
+ aria-label = "delete"
395
+ color = "secondary"
396
+ id = "delete-button"
397
+ onClick = { ( ) => handleDeleteRow ( index ) }
398
+ sx = { { alignSelf : 'center' } }
399
+ >
400
+ < DeleteOutline />
401
+ </ IconButton >
356
402
</ Box >
357
403
) ) }
358
404
< Box
0 commit comments