From 13f3b946b8dd3433c93912dd3446352e19e8db1a Mon Sep 17 00:00:00 2001 From: Jan Date: Tue, 23 Jan 2024 22:09:46 +0100 Subject: [PATCH 1/2] CM-456: adjust fe to create deduplication tasks --- src/actions.js | 39 ++++++++++++++++++- .../DeduplicationFieldSelectionDialog.js | 1 + .../dialogs/DeduplicationSummaryDialog.js | 19 +++++++-- .../tables/DeduplicationSummaryTable.js | 6 ++- src/reducer.js | 5 +++ src/translations/en.json | 3 +- 6 files changed, 67 insertions(+), 6 deletions(-) diff --git a/src/actions.js b/src/actions.js index 19eb1a5..f058397 100644 --- a/src/actions.js +++ b/src/actions.js @@ -1,11 +1,13 @@ import { graphql, formatQuery, + formatMutation, } from '@openimis/fe-core'; import { ACTION_TYPE } from './reducer'; +import { ERROR, REQUEST, SUCCESS } from './util/action-type'; const DEDUPLICATION_SUMMARY_FULL_PROJECTION = () => [ - 'rows {count, columnValues}', + 'rows {count, ids, columnValues}', ]; // eslint-disable-next-line import/prefer-default-export @@ -13,3 +15,38 @@ export function fetchDeduplicationSummary(params) { const payload = formatQuery('beneficiaryDeduplicationSummary', params, DEDUPLICATION_SUMMARY_FULL_PROJECTION()); return graphql(payload, ACTION_TYPE.GET_DEDUPLICATION_SUMMARY); } + +function formatDeduplicationTasksMutation(summary) { + if (!summary || !Array.isArray(summary)) { + return ''; + } + + const formattedSummary = summary.map((item) => { + const keyValuePairs = Object.entries(item) + .map(([key, value]) => `${key}: ${JSON.stringify(value)}`) + .join(', '); + + return `{ ${keyValuePairs} }`; + }); + + return `summary: [${formattedSummary.join(', ')}]`; +} +export function createDeduplicationTasks(summary, clientMutationLabel) { + console.log(formatDeduplicationTasksMutation(summary)); + const mutation = formatMutation( + 'createDeduplicationTasks', + formatDeduplicationTasksMutation(summary), + clientMutationLabel, + ); + const requestedDateTime = new Date(); + return graphql( + mutation.payload, + [REQUEST(ACTION_TYPE.MUTATION), SUCCESS(ACTION_TYPE.CREATE_DEDUPLICATION_TASKS), ERROR(ACTION_TYPE.MUTATION)], + { + actionType: ACTION_TYPE.CREATE_DEDUPLICATION_TASKS, + clientMutationId: mutation.clientMutationId, + clientMutationLabel, + requestedDateTime, + }, + ); +} diff --git a/src/components/dialogs/DeduplicationFieldSelectionDialog.js b/src/components/dialogs/DeduplicationFieldSelectionDialog.js index aedf531..e349f42 100644 --- a/src/components/dialogs/DeduplicationFieldSelectionDialog.js +++ b/src/components/dialogs/DeduplicationFieldSelectionDialog.js @@ -136,6 +136,7 @@ function DeduplicationFieldSelectionDialog({ benefitPlan={benefitPlan} handleClose={handleSummaryDialogClose} showSummaryDialog={showSummaryDialog} + setShowSummaryDialog={setShowSummaryDialog} selectedValues={selectedValues} setSelectedValues={setSelectedValues} /> diff --git a/src/components/dialogs/DeduplicationSummaryDialog.js b/src/components/dialogs/DeduplicationSummaryDialog.js index 2f60f52..8f2ab60 100644 --- a/src/components/dialogs/DeduplicationSummaryDialog.js +++ b/src/components/dialogs/DeduplicationSummaryDialog.js @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useState } from 'react'; import { injectIntl } from 'react-intl'; import Button from '@material-ui/core/Button'; import Dialog from '@material-ui/core/Dialog'; @@ -10,7 +10,7 @@ import { withTheme, withStyles } from '@material-ui/core/styles'; import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; import DeduplicationSummaryTable from '../tables/DeduplicationSummaryTable'; -import { fetchDeduplicationSummary } from '../../actions'; +import { createDeduplicationTasks, fetchDeduplicationSummary } from '../../actions'; const styles = (theme) => ({ item: theme.paper.item, @@ -21,13 +21,23 @@ function DeduplicationSummaryDialog({ benefitPlan, handleClose, showSummaryDialog, + setShowSummaryDialog, selectedValues, + createDeduplicationTasks, }) { + const [summary, setSummary] = useState(); if (!benefitPlan) return null; const columns = selectedValues.map((value) => value.id); const columnParam = `columns: ${JSON.stringify(columns)}`; + const onDeduplicationTasksClick = () => { + if (summary) { + createDeduplicationTasks(summary, formatMessage(intl, 'deduplication', 'deduplicate.mutation.createTasks')); + } + setShowSummaryDialog(false); + }; + return (