Skip to content

Commit 70283ba

Browse files
Merge branch 'dev' into CU-86bzht0qz_M-and-U-value-update-on-edit
2 parents 9710302 + f71cbae commit 70283ba

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

JeMPI_Apps/JeMPI_UI/src/pages/settings/deterministic/DeterministicContent.tsx

+47-1
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ import {
1010
IconButton
1111
} from '@mui/material'
1212
import AddIcon from '@mui/icons-material/Add'
13-
import { Field, Rule } from 'types/Configuration'
13+
import { Configuration, Field, Rule } from 'types/Configuration'
1414
import { transformFieldName } from 'utils/helpers'
1515
import SourceView, { RowData } from './SourceView'
1616
import { useConfiguration } from 'hooks/useUIConfiguration'
17+
import { DeleteOutline } from '@mui/icons-material'
1718

1819
interface DeterministicContentProps {
1920
demographicData: Field[]
@@ -225,6 +226,39 @@ const DeterministicContent = ({
225226
return updatedConfiguration
226227
}
227228

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+
};
228262
return (
229263
<Box>
230264
<Box
@@ -318,6 +352,9 @@ const DeterministicContent = ({
318352
label="Select Field"
319353
onChange={event => handleFieldChange(index, event)}
320354
>
355+
<MenuItem value="" disabled>
356+
Select a field
357+
</MenuItem>
321358
{Array.isArray(demographicData) &&
322359
demographicData.map(demographicField => (
323360
<MenuItem
@@ -353,6 +390,15 @@ const DeterministicContent = ({
353390
))}
354391
</Select>
355392
</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>
356402
</Box>
357403
))}
358404
<Box

0 commit comments

Comments
 (0)