diff --git a/src/components/BeneficiaryDuplicatesTable.js b/src/components/BeneficiaryDuplicatesTable.js index 789f9d4..2809fa4 100644 --- a/src/components/BeneficiaryDuplicatesTable.js +++ b/src/components/BeneficiaryDuplicatesTable.js @@ -14,6 +14,8 @@ const useStyles = makeStyles((theme) => ({ tableHeader: theme.table.header, tableRow: theme.table.row, title: theme.paper.title, + tableDisabledRow: theme.table.disabledRow, + tableDisabledCell: theme.table.disabledCell, tableContainer: { overflow: 'auto', }, @@ -32,23 +34,36 @@ const useStyles = makeStyles((theme) => ({ deactivatedRow: { opacity: 0.5, }, + strikethrough: { + textDecoration: 'line-through', + }, })); function BeneficiaryDuplicatesTable({ - headers, rows, setAdditionalData, beneficiaryUuids, + headers, rows, setAdditionalData, completedData, }) { const classes = useStyles(); const [selectedCells, setSelectedCells] = useState([]); const [selectedRow, setSelectedRow] = useState(null); + const [dontMergeRows, setDontMergeRows] = useState([]); + const [fieldValues, setFieldValues] = useState({}); useEffect(() => { + const filteredIds = rows + .filter((row, index) => !dontMergeRows.includes(index)) + .map((row) => row.beneficiaryId); + const parsedFieldValues = selectedCells.reduce((accumulation, cell) => { + accumulation[cell.header] = cell.value ?? ''; + return accumulation; + }, {}); const additionalData = ( - { values: selectedCells.map((cell) => ({ [cell.header]: cell.value })), beneficiaryIds: beneficiaryUuids } + { values: parsedFieldValues, beneficiaryIds: filteredIds } ); + setFieldValues(parsedFieldValues); // eslint-disable-next-line max-len const additionalDataString = `{\\"values\\": ${JSON.stringify(additionalData.values).replace(/"/g, '\\"')},\\"beneficiaryIds\\": ${JSON.stringify(additionalData.beneficiaryIds).replace(/"/g, '\\"')}}`; setAdditionalData(additionalDataString); - }, [selectedCells]); + }, [selectedCells, dontMergeRows]); const isCellSelected = (rowIndex, header) => selectedCells.some( (cell) => cell.rowIndex === rowIndex && cell.header === header, ); @@ -74,11 +89,16 @@ function BeneficiaryDuplicatesTable({ return; } + if (dontMergeRows.includes(rowIndex)) { + return; + } + const isCellSelectedInColumn = selectedCells.some((cell) => cell.header === header); const isCellClicked = isCellSelected(rowIndex, header); if (isCellClicked) { clearCellSelection(rowIndex, header); + setSelectedRow(null); return; } @@ -108,12 +128,45 @@ function BeneficiaryDuplicatesTable({ } }; + const handleMergeCheckboxChange = (rowIndex) => { + if (!dontMergeRows.includes(rowIndex)) { + clearRowSelection(rowIndex); + setDontMergeRows([...dontMergeRows, rowIndex]); + } else { + const index = dontMergeRows.indexOf(rowIndex); + if (index !== -1) { + const newDontMergeRows = [...dontMergeRows]; + newDontMergeRows.splice(index, 1); + setDontMergeRows(newDontMergeRows); + } + } + }; + + // eslint-disable-next-line max-len + const shouldHoverCell = (rowIndex, header) => !isCellSelected(rowIndex, header) && header !== 'individual' && !dontMergeRows.includes(rowIndex); + const shouldDisableCell = (rowIndex) => dontMergeRows.includes(rowIndex); + const shouldCrossText = (rowIndex) => rows[rowIndex]?.is_deleted; + const isDontMereChecked = (rowIndex) => ( + (dontMergeRows.includes(rowIndex) && !completedData) || (completedData && !rows[rowIndex]?.is_deleted) + ); + + useEffect(() => { + if (completedData) { + const numberOfRows = Array.from(Array(rows.length).keys()); + clearAllCellSelection(); + setDontMergeRows(numberOfRows); + } + }, [completedData]); + return (
+ + + @@ -128,19 +181,35 @@ function BeneficiaryDuplicatesTable({ key={rowIndex} className={classes.tableRow} > + + {rowIndex + ? ( + handleMergeCheckboxChange(rowIndex)} + disabled={completedData} + /> + ) + : } + handleCheckboxChange(rowIndex)} + disabled={shouldDisableCell(rowIndex)} /> {headers.map((header, headerIndex) => ( handleCellClick(rowIndex, header, row[header])} > {row[header]} @@ -148,6 +217,23 @@ function BeneficiaryDuplicatesTable({ ))} ))} + + + + + + {headers.map((header, headerIndex) => ( + + {Object.prototype.hasOwnProperty.call(fieldValues, header) ? fieldValues[header] : rows[0][header]} + + ))} +
diff --git a/src/components/tasks/DeduplicationResolutionTask.js b/src/components/tasks/DeduplicationResolutionTask.js index 5c51bf6..7b705d4 100644 --- a/src/components/tasks/DeduplicationResolutionTask.js +++ b/src/components/tasks/DeduplicationResolutionTask.js @@ -8,19 +8,26 @@ const useStyles = makeStyles((theme) => ({ })); function BeneficiaryDeduplicationTaskDisplay({ - businessData, setAdditionalData, + businessData, setAdditionalData, jsonExt, }) { + if (!businessData) return null; + const classes = useStyles(); - const beneficiaryUuids = (businessData?.ids || []).map((id) => id.uuid); + const completedData = jsonExt?.additional_resolve_data + ? Object.values(jsonExt.additional_resolve_data)[0].values + : null; const beneficiaries = (businessData?.ids || []).map((id) => { - // eslint-disable-next-line camelcase - const { individual, json_ext, ...rest } = id; + const { + // eslint-disable-next-line camelcase + individual, json_ext, uuid, ...rest + } = id; return { ...rest, ...individual, // eslint-disable-next-line camelcase ...json_ext, individual: individual.uuid, + beneficiaryId: uuid, }; }); @@ -32,6 +39,8 @@ function BeneficiaryDeduplicationTaskDisplay({ headers.unshift('individual'); } + beneficiaries.sort((a, b) => new Date(a.date_created) - new Date(b.date_created)); + return (
@@ -47,7 +56,7 @@ function BeneficiaryDeduplicationTaskDisplay({ headers={headers} rows={beneficiaries} setAdditionalData={setAdditionalData} - beneficiaryUuids={beneficiaryUuids} + completedData={completedData} />
@@ -62,6 +71,7 @@ const DeduplicationResolutionItemFormatters = () => [ ), ]; diff --git a/src/translations/en.json b/src/translations/en.json index a72010c..6fd7c12 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -11,5 +11,8 @@ "deduplication.deduplicationSummaryTable.duplicates": "Duplicates", "deduplication.tasks.deduplication.title": "Benefit Plan Deduplication Task", "deduplication.deduplicate.mutation.createTasks": "Deduplication tasks have been created.", - "deduplication.BeneficiaryDuplicatesTable.checkbox.header": "Select all columns" + "deduplication.BeneficiaryDuplicatesTable.checkbox.header": "Select all columns", + "deduplication.BeneficiaryDuplicatesTable.merge.header": "Don't merge", + "deduplication.BeneficiaryDuplicatesTable.output": "OUTPUT:", + "deduplication.BeneficiaryDuplicatesTable.oldest": "Oldest" } \ No newline at end of file