Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CM-456: adjust fe to create deduplication tasks #5

Merged
merged 2 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion src/actions.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,51 @@
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
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) {
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,
},
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ function DeduplicationFieldSelectionDialog({
benefitPlan={benefitPlan}
handleClose={handleSummaryDialogClose}
showSummaryDialog={showSummaryDialog}
setShowSummaryDialog={setShowSummaryDialog}
selectedValues={selectedValues}
setSelectedValues={setSelectedValues}
/>
Expand Down
19 changes: 16 additions & 3 deletions src/components/dialogs/DeduplicationSummaryDialog.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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,
Expand All @@ -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 (
<Dialog
open={showSummaryDialog}
Expand All @@ -51,6 +61,7 @@ function DeduplicationSummaryDialog({
columnParam={columnParam}
benefitPlan={benefitPlan}
fetchDeduplicationSummary={fetchDeduplicationSummary}
setSummary={setSummary}
/>
</DialogContent>
<DialogActions
Expand All @@ -64,9 +75,10 @@ function DeduplicationSummaryDialog({
<div>
<div style={{ float: 'left' }}>
<Button
onClick={() => []}
onClick={() => onDeduplicationTasksClick()}
variant="outlined"
autoFocus
disabled={!summary}
style={{ margin: '0 16px' }}
>
{formatMessage(intl, 'deduplication', 'deduplicate.button.createDeduplicationReviewTask')}
Expand Down Expand Up @@ -98,6 +110,7 @@ const mapStateToProps = (state) => ({
});

const mapDispatchToProps = (dispatch) => bindActionCreators({
createDeduplicationTasks,
}, dispatch);

export default injectIntl(
Expand Down
6 changes: 5 additions & 1 deletion src/components/tables/DeduplicationSummaryTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const DEDUPLICATION_SUMMARY_HEADERS = [
];

function DeduplicationSummaryTable({
columnParam, benefitPlan, fetchDeduplicationSummary,
columnParam, benefitPlan, fetchDeduplicationSummary, setSummary,
}) {
const dispatch = useDispatch();
const modulesManager = useModulesManager();
Expand All @@ -42,6 +42,10 @@ function DeduplicationSummaryTable({
dispatch(fetchDeduplicationSummary(params));
}, []);

useEffect(() => {
setSummary(summary);
}, [summary]);

function reshapeColumnValues(inputString) {
const columnValues = JSON.parse(inputString);
const formattedValues = Object.entries(columnValues).map(([key, value]) => {
Expand Down
5 changes: 5 additions & 0 deletions src/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@

import {
formatServerError,
dispatchMutationResp,
} from '@openimis/fe-core';
import {
ERROR, REQUEST, SUCCESS,
} from './util/action-type';

export const ACTION_TYPE = {
MUTATION: 'MUTATION',
GET_DEDUPLICATION_SUMMARY: 'DEDUPLICATION_GET_DEDUPLICATION_SUMMARY',
CREATE_DEDUPLICATION_TASKS: 'CREATE_DEDUPLICATION_TASKS',
};

function reducer(
Expand Down Expand Up @@ -47,6 +50,8 @@ function reducer(
fetchingSummary: false,
errorSummary: formatServerError(action.payload),
};
case SUCCESS(ACTION_TYPE.CREATE_DEDUPLICATION_TASKS):
return dispatchMutationResp(state, 'createDeduplicationTasks', action);
default:
return state;
}
Expand Down
3 changes: 2 additions & 1 deletion src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
"deduplication.deduplicate.summary.title": "Deduplication Summary",
"deduplication.deduplicate.button.createDeduplicationReviewTask": "Create Deduplication Review Tasks",
"deduplication.deduplicationSummaryTable.group": "Group",
"deduplication.deduplicationSummaryTable.duplicates": "Duplicates"
"deduplication.deduplicationSummaryTable.duplicates": "Duplicates",
"deduplication.deduplicate.mutation.createTasks": "Deduplication tasks have been created."
}
Loading