Skip to content

Commit 7f129ec

Browse files
authored
Targets Merge Functionality Integration (#128)
1 parent cc8d6e9 commit 7f129ec

File tree

11 files changed

+963
-834
lines changed

11 files changed

+963
-834
lines changed

src/modules/SurveyInformation/Enumerators/EnumeratorsHome/EnumeratorsHome.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,8 @@ function EnumeratorsHome() {
254254
for (const key in originalData[0]) {
255255
if (
256256
Object.prototype.hasOwnProperty.call(originalData[0], key) &&
257-
key !== "custom_fields"
257+
key !== "custom_fields" &&
258+
!columnsToExclude.includes(key)
258259
) {
259260
columnMapping[key] = key;
260261
}

src/modules/SurveyInformation/Enumerators/EnumeratorsRemap/EnumeratorsRemap.tsx

Lines changed: 364 additions & 323 deletions
Large diffs are not rendered by default.

src/modules/SurveyInformation/Enumerators/EnumeratorsReupload/EnumeratorsReupload.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ function EnumeratorsReupload({ setScreenMode }: IEnumeratorsReupload) {
111111
{enumeratorColumnMapping !== null &&
112112
Object.keys(enumeratorColumnMapping).length > 0 && (
113113
<ul>
114-
{Object.keys(enumeratorColumnMapping).map((key) => (
115-
<li key={key}>{key}</li>
116-
))}
114+
{Object.keys(enumeratorColumnMapping).map(
115+
(key) => key !== "custom_fields" && <li key={key}>{key}</li>
116+
)}
117117
</ul>
118118
)}
119119
</DescriptionContainer>

src/modules/SurveyInformation/SurveyLocationAdd/SurveyLocationAdd.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ function SurveyLocationAdd() {
9595
}
9696
}
9797
};
98+
9899
const renderLocationFields = () => {
99100
const fields = Array.from({ length: numLocationFields }, (_, index) => {
100101
const geoLevel: {

src/modules/SurveyInformation/Targets/TargetsHome/TargetsHome.tsx

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ import {
1717
import { useEffect, useState } from "react";
1818
import RowEditingModal from "./RowEditingModal";
1919
import TargetsCountBox from "../../../../components/TargetsCountBox";
20-
import { setLoading } from "../../../../redux/targets/targetSlice";
20+
import {
21+
setLoading,
22+
setTargetsColumnMapping,
23+
} from "../../../../redux/targets/targetSlice";
2124
import { useAppDispatch, useAppSelector } from "../../../../redux/hooks";
2225
import { RootState } from "../../../../redux/store";
2326
import { getSurveyCTOForm } from "../../../../redux/surveyCTOInformation/surveyCTOInformationActions";
@@ -26,6 +29,7 @@ import FullScreenLoader from "../../../../components/Loaders/FullScreenLoader";
2629
import { useCSVDownloader } from "react-papaparse";
2730
import TargetsReupload from "../TargetsReupload";
2831
import TargetsRemap from "../TargetsRemap";
32+
import { includes } from "cypress/types/lodash";
2933

3034
function TargetsHome() {
3135
const navigate = useNavigate();
@@ -141,10 +145,6 @@ function TargetsHome() {
141145
setEditData(false);
142146
};
143147

144-
const moveToUpload = () => {
145-
navigate(`/survey-information/targets/upload/${survey_uid}/${form_uid}`);
146-
};
147-
148148
const handleFormUID = async () => {
149149
if (form_uid == "" || form_uid == undefined || form_uid == "undefined") {
150150
try {
@@ -176,10 +176,47 @@ function TargetsHome() {
176176
setTargetsCount(originalData.length);
177177

178178
if (originalData.length == 0) {
179+
navigate(
180+
`/survey-information/targets/upload/${survey_uid}/${form_uid}`
181+
);
179182
return;
180183
}
181184

182-
const columnsToExclude = ["target_uid", "target_locations"];
185+
const columnsToExclude = [
186+
"target_uid",
187+
"target_locations",
188+
"completed_flag",
189+
"last_attempt_survey_status",
190+
"last_attempt_survey_status_label",
191+
"num_attempts",
192+
"refusal_flag",
193+
"revisit_sections",
194+
"target_assignable",
195+
"webapp_tag_color",
196+
];
197+
//set targets column mapping
198+
199+
if (originalData[0]?.custom_fields?.column_mapping) {
200+
dispatch(
201+
setTargetsColumnMapping(
202+
originalData[0]?.custom_fields?.column_mapping
203+
)
204+
);
205+
} else {
206+
const columnMapping: any = {};
207+
208+
for (const key in originalData[0]) {
209+
if (
210+
Object.prototype.hasOwnProperty.call(originalData[0], key) &&
211+
key !== "custom_fields" &&
212+
!columnsToExclude.includes(key)
213+
) {
214+
columnMapping[key] = key;
215+
}
216+
}
217+
218+
dispatch(setTargetsColumnMapping(columnMapping));
219+
}
183220

184221
// Define column mappings
185222
let columnMappings = Object.keys(originalData[0])

src/modules/SurveyInformation/Targets/TargetsMap/TargetsMap.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,7 @@ function TargetsMap() {
273273

274274
setHasError(false);
275275
//route to manage
276-
navigate(
277-
`/survey-information/targets/manage/${survey_uid}/${form_uid}`
278-
);
276+
navigate(`/survey-information/targets/${survey_uid}/${form_uid}`);
279277
} else {
280278
message.error("Failed to upload kindly check and try again");
281279
setHasError(true);
@@ -404,6 +402,8 @@ function TargetsMap() {
404402
}
405403
}
406404

405+
console.log("lowestGeoLevel", lowestGeoLevel);
406+
407407
return lowestGeoLevel;
408408
};
409409

@@ -427,6 +427,8 @@ function TargetsMap() {
427427

428428
const locationData = locationRes?.payload;
429429

430+
console.log("locationData", locationData);
431+
430432
const lowestGeoLevel = findLowestGeoLevel(locationData);
431433

432434
if (lowestGeoLevel?.geo_level_name) {

0 commit comments

Comments
 (0)