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-420: Added updated upload with validations #57

Merged
merged 13 commits into from
Jan 12, 2024
Merged
2 changes: 1 addition & 1 deletion src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const UPLOAD_HISTORY_FULL_PROJECTION = () => [
'id',
'uuid',
'workflow',
'dataUpload {dateCreated, dateUpdated, sourceName, sourceType, status, error }',
'dataUpload {uuid, dateCreated, dateUpdated, sourceName, sourceType, status, error }',
];

const BENEFICIARY_FULL_PROJECTION = () => [
Expand Down
6 changes: 6 additions & 0 deletions src/components/BenefitPlanTabPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
BENEFIT_PLAN_BENEFICIARIES_LIST_TAB_VALUE,
BENEFIT_PLAN_TABS_LABEL_CONTRIBUTION_KEY,
BENEFIT_PLAN_TABS_PANEL_CONTRIBUTION_KEY,
DEDUPLICATION_SELECT_FIELD_DIALOG_CONTRIBUTION_KEY,
} from '../constants';
import BenefitPlanBeneficiariesUploadDialog from '../dialogs/BenefitPlanBeneficiariesUploadDialog';
import BenefitPlanBeneficiariesUploadHistoryDialog from '../dialogs/BenefitPlanBeneficiariesUploadHistoryDialog';
Expand Down Expand Up @@ -59,6 +60,11 @@ function BenefitPlanTabPanel({
/>
</div>
<div style={{ float: 'right', paddingRight: '16px' }}>
<Contributions
contributionKey={DEDUPLICATION_SELECT_FIELD_DIALOG_CONTRIBUTION_KEY}
intl={intl}
benefitPlan={benefitPlan}
/>
<BenefitPlanBeneficiariesUploadDialog
benefitPlan={benefitPlan}
/>
Expand Down
5 changes: 5 additions & 0 deletions src/components/tasks/ValidateImportValidItems.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const ValidateImportValidItemsTaskTableHeaders = () => [];

const ValidateImportValidItemsItemFormatters = () => [];

export { ValidateImportValidItemsTaskTableHeaders, ValidateImportValidItemsItemFormatters };
11 changes: 11 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const BENEFIT_PLAN_BENEFICIARIES_GRADUATED_TAB_VALUE = 'benefitPlanBenefi
export const BENEFIT_PLAN_BENEFICIARIES_SUSPENDED_TAB_VALUE = 'benefitPlanBeneficiariesSuspendedTab';
export const BENEFIT_PLAN_TABS_LABEL_CONTRIBUTION_KEY = 'benefitPlan.TabPanel.label';
export const BENEFIT_PLAN_TABS_PANEL_CONTRIBUTION_KEY = 'benefitPlan.TabPanel.panel';
export const DEDUPLICATION_SELECT_FIELD_DIALOG_CONTRIBUTION_KEY = 'deduplication.deduplicationFieldSelectionDialog';

export const BENEFIT_PACKAGE_MEMBERS_TAB_VALUE = 'benefitPackageMembersTab';
export const BENEFIT_PACKAGE_PAYMENTS_TAB_VALUE = 'benefitPackagePaymentsTab';
Expand Down Expand Up @@ -71,6 +72,16 @@ export const FIELD_TYPES = {
STRING: 'string',
};

export const UPLOAD_STATUS = {
PENDING: 'PENDING',
TRIGGERED: 'TRIGGERED',
IN_PROGRESS: 'IN_PROGRESS',
SUCCESS: 'SUCCESS',
PARTIAL_SUCCESS: 'PARTIAL_SUCCESS',
WAITING_FOR_VERIFICATION: 'WAITING_FOR_VERIFICATION',
FAIL: 'FAIL',
};

export const MODULE_NAME = 'social_protection';
export const SOCIAL_PROTECTION_MODULE = 'socialProtection';
export const BENEFIT_PLAN_LABEL = 'BenefitPlan';
Expand Down
23 changes: 23 additions & 0 deletions src/dialogs/BenefitPlanBeneficiariesUploadHistoryDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import CollapsableErrorList from '../components/CollapsableErrorList';
import { fetchUploadHistory } from '../actions';
import downloadInvalidItems from '../util/export';
import { UPLOAD_STATUS } from '../constants';

const styles = (theme) => ({
item: theme.paper.item,
Expand All @@ -52,6 +54,10 @@ function BenefitPlanBeneficiariesUploadHistoryDialog({
setIsOpen(false);
};

const downloadInvalidItemsFromUpload = (uploadId) => {
downloadInvalidItems(uploadId);
};

useEffect(() => {
if (isOpen) {
const params = [`benefitPlan_Id:"${benefitPlan.id}"`];
Expand Down Expand Up @@ -174,6 +180,23 @@ function BenefitPlanBeneficiariesUploadHistoryDialog({
<TableCell>
<CollapsableErrorList errors={item.dataUpload.error} />
</TableCell>
<TableCell>
{[
UPLOAD_STATUS.WAITING_FOR_VERIFICATION,
UPLOAD_STATUS.PARTIAL_SUCCESS].includes(item.dataUpload.status) && (
<Button
onClick={() => downloadInvalidItemsFromUpload(item.dataUpload.uuid)}
variant="outlined"
autoFocus
style={{
margin: '0 16px',
marginBottom: '15px',
}}
>
Download Invalid Items
</Button>
)}
</TableCell>
</TableRow>
))}
</TableBody>
Expand Down
10 changes: 10 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ import {
CalculationSocialProtectionItemFormatters,
CalculationSocialProtectionTableHeaders,
} from './components/tasks/CalculationSocialProtectionTasks';
import {
ValidateImportValidItemsItemFormatters,
ValidateImportValidItemsTaskTableHeaders,
} from './components/tasks/ValidateImportValidItems';

const ROUTE_BENEFIT_PLANS = 'benefitPlans';
const ROUTE_BENEFIT_PLAN = 'benefitPlans/benefitPlan';
Expand Down Expand Up @@ -124,6 +128,12 @@ const DEFAULT_CONFIG = {
tableHeaders: CalculationSocialProtectionTableHeaders,
itemFormatters: CalculationSocialProtectionItemFormatters,
taskSource: ['calcrule_social_protection'],
},
{
text: <FormattedMessage module="socialProtection" id="validation_import_valid_items.tasks.title" />,
tableHeaders: ValidateImportValidItemsTaskTableHeaders,
itemFormatters: ValidateImportValidItemsItemFormatters,
taskSource: ['import_valid_items'],
}],
};

Expand Down
3 changes: 2 additions & 1 deletion src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,6 @@
"socialProtection.beneficiary.task.individual.id": "Individual",
"socialProtection.beneficiary.task.benefitPlan.id": "Benefit Plan",
"socialProtection.calculation.tasks.title": "Payment Verification Tasks",
"socialProtection.BenefitPlanPicker.placeholder": "Please select a Benefit Plan"
"socialProtection.BenefitPlanPicker.placeholder": "Please select a Benefit Plan",
"socialProtection.validation_import_valid_items.tasks.title": "Import Valid Items Task"
}
20 changes: 20 additions & 0 deletions src/util/export.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { baseApiUrl } from '@openimis/fe-core';

export default function downloadInvalidItems(uploadId) {
const url = new URL(
`${window.location.origin}${baseApiUrl}/social_protection/download_invalid_items/?upload_id=${uploadId}`,
);
fetch(url)
.then((response) => response.blob())
.then((blob) => {
const link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.download = 'invalid_items.csv';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
})
.catch((error) => {
console.error('Export failed, reason: ', error);
});
}