From 53433c2f61b1f2d86efb7d568b17ba530b97a426 Mon Sep 17 00:00:00 2001 From: Jan Date: Thu, 4 Apr 2024 00:49:47 +0200 Subject: [PATCH] CM-447: adjust frontend deduplication --- src/components/BeneficiaryDuplicatesTable.js | 81 +++++++++++++++++-- .../tasks/DeduplicationResolutionTask.js | 20 +++-- src/translations/en.json | 4 +- 3 files changed, 94 insertions(+), 11 deletions(-) diff --git a/src/components/BeneficiaryDuplicatesTable.js b/src/components/BeneficiaryDuplicatesTable.js index 789f9d4..ab59491 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', }, @@ -35,20 +37,30 @@ const useStyles = makeStyles((theme) => ({ })); 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((acc, cell) => { + acc[cell.header] = cell.value ?? ''; + return acc; + }, {}); + setFieldValues(parsedFieldValues); const additionalData = ( - { values: selectedCells.map((cell) => ({ [cell.header]: cell.value })), beneficiaryIds: beneficiaryUuids } + { values: fieldValues, beneficiaryIds: filteredIds } ); // 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,6 +86,10 @@ function BeneficiaryDuplicatesTable({ return; } + if (dontMergeRows.includes(rowIndex)) { + return; + } + const isCellSelectedInColumn = selectedCells.some((cell) => cell.header === header); const isCellClicked = isCellSelected(rowIndex, header); @@ -108,12 +124,41 @@ 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); + + useEffect(() => { + if (completedData) { + const numberOfRows = Array.from(Array(rows.length).keys()); + clearAllCellSelection(); + setDontMergeRows(numberOfRows); + } + }, [completedData]); + return (
+ + + @@ -128,19 +173,28 @@ function BeneficiaryDuplicatesTable({ key={rowIndex} className={classes.tableRow} > + + handleMergeCheckboxChange(rowIndex)} + disabled={completedData} + /> + handleCheckboxChange(rowIndex)} + disabled={shouldDisableCell(rowIndex)} /> {headers.map((header, headerIndex) => ( handleCellClick(rowIndex, header, row[header])} > {row[header]} @@ -148,6 +202,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..ab95256 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -11,5 +11,7 @@ "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:" } \ No newline at end of file