From 53433c2f61b1f2d86efb7d568b17ba530b97a426 Mon Sep 17 00:00:00 2001 From: Jan Date: Thu, 4 Apr 2024 00:49:47 +0200 Subject: [PATCH 1/3] 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 From cd339cf78834fdf02da691021e96c9ab00c4073e Mon Sep 17 00:00:00 2001 From: Jan Date: Thu, 4 Apr 2024 15:13:50 +0200 Subject: [PATCH 2/3] CM-447: last adjustments --- src/components/BeneficiaryDuplicatesTable.js | 42 +++++++++++++------- src/translations/en.json | 3 +- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/src/components/BeneficiaryDuplicatesTable.js b/src/components/BeneficiaryDuplicatesTable.js index ab59491..9354598 100644 --- a/src/components/BeneficiaryDuplicatesTable.js +++ b/src/components/BeneficiaryDuplicatesTable.js @@ -34,6 +34,9 @@ const useStyles = makeStyles((theme) => ({ deactivatedRow: { opacity: 0.5, }, + strikethrough: { + textDecoration: 'line-through', + }, })); function BeneficiaryDuplicatesTable({ @@ -49,14 +52,14 @@ function BeneficiaryDuplicatesTable({ 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; + const parsedFieldValues = selectedCells.reduce((accumulation, cell) => { + accumulation[cell.header] = cell.value ?? ''; + return accumulation; }, {}); - setFieldValues(parsedFieldValues); const additionalData = ( - { values: fieldValues, beneficiaryIds: filteredIds } + { 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); @@ -141,6 +144,10 @@ function BeneficiaryDuplicatesTable({ // 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) { @@ -174,12 +181,16 @@ function BeneficiaryDuplicatesTable({ className={classes.tableRow} > - handleMergeCheckboxChange(rowIndex)} - disabled={completedData} - /> + {rowIndex + ? ( + handleMergeCheckboxChange(rowIndex)} + disabled={completedData} + /> + ) + : } ( handleCellClick(rowIndex, header, row[header])} > {row[header]} diff --git a/src/translations/en.json b/src/translations/en.json index ab95256..6fd7c12 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -13,5 +13,6 @@ "deduplication.deduplicate.mutation.createTasks": "Deduplication tasks have been created.", "deduplication.BeneficiaryDuplicatesTable.checkbox.header": "Select all columns", "deduplication.BeneficiaryDuplicatesTable.merge.header": "Don't merge", - "deduplication.BeneficiaryDuplicatesTable.output": "OUTPUT:" + "deduplication.BeneficiaryDuplicatesTable.output": "OUTPUT:", + "deduplication.BeneficiaryDuplicatesTable.oldest": "Oldest" } \ No newline at end of file From 7f6a633770627624e5372d9280f29d851bf0a440 Mon Sep 17 00:00:00 2001 From: Jan Date: Thu, 4 Apr 2024 15:32:56 +0200 Subject: [PATCH 3/3] CM-447: remove selected row if celll clicked --- src/components/BeneficiaryDuplicatesTable.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/BeneficiaryDuplicatesTable.js b/src/components/BeneficiaryDuplicatesTable.js index 9354598..2809fa4 100644 --- a/src/components/BeneficiaryDuplicatesTable.js +++ b/src/components/BeneficiaryDuplicatesTable.js @@ -98,6 +98,7 @@ function BeneficiaryDuplicatesTable({ if (isCellClicked) { clearCellSelection(rowIndex, header); + setSelectedRow(null); return; }