From 67e96192867b33b864952432e3b2d0e596762de2 Mon Sep 17 00:00:00 2001 From: siddhant-nawale-egov <162107530+siddhant-nawale-egov@users.noreply.github.com> Date: Thu, 27 Jun 2024 21:06:00 +0530 Subject: [PATCH] microplan handling same sheet name --- .../MicroplanPreviewHelperCompoenents.js | 2 +- .../hcm-microplanning/src/components/Upload.js | 6 +++--- .../src/utils/microplanPreviewUtils.js | 2 +- .../hcm-microplanning/src/utils/uploadUtils.js | 15 +++++++++++++-- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/health/micro-ui/web/micro-ui-internals/packages/modules/hcm-microplanning/src/components/MicroplanPreviewHelperCompoenents.js b/health/micro-ui/web/micro-ui-internals/packages/modules/hcm-microplanning/src/components/MicroplanPreviewHelperCompoenents.js index e92335d6581..43d945e19f4 100644 --- a/health/micro-ui/web/micro-ui-internals/packages/modules/hcm-microplanning/src/components/MicroplanPreviewHelperCompoenents.js +++ b/health/micro-ui/web/micro-ui-internals/packages/modules/hcm-microplanning/src/components/MicroplanPreviewHelperCompoenents.js @@ -18,7 +18,7 @@ export const HypothesisValues = memo(({ boundarySelections, hypothesisAssumption setToast({ state: "error", message: t("ERROR_HYPOTHESIS_VALUE_SHOULD_NOT_BE_ZERO") }); return; } - if (Object.keys(boundarySelections).length !== 0 && Object.values(boundarySelections)?.every((item) => item?.length !== 0)) + if (Object.keys(boundarySelections).length !== 0 && Object.values(boundarySelections)?.some((item) => item?.length !== 0)) return setToast({ state: "error", message: t("HYPOTHESIS_CAN_BE_ONLY_APPLIED_ON_ADMIN_LEVEL_ZORO") }); setHypothesisAssumptionsList(tempHypothesisList); }; diff --git a/health/micro-ui/web/micro-ui-internals/packages/modules/hcm-microplanning/src/components/Upload.js b/health/micro-ui/web/micro-ui-internals/packages/modules/hcm-microplanning/src/components/Upload.js index 9e0ed13d39b..2977de6d1f0 100644 --- a/health/micro-ui/web/micro-ui-internals/packages/modules/hcm-microplanning/src/components/Upload.js +++ b/health/micro-ui/web/micro-ui-internals/packages/modules/hcm-microplanning/src/components/Upload.js @@ -707,12 +707,12 @@ const Upload = ({ const boundaryDataAgainstBoundaryCode = (await boundaryDataGeneration(schemaData, campaignData, t)) || {}; const mappedToList = resourceMappingData.map((item) => item.mappedTo); - if (hierarchy.every((item) => !mappedToList.includes(t(item)))) { + if (!schemaData.doHierarchyCheckInUploadedData && hierarchy.some((item) => !mappedToList.includes(t(item)))) { data.features.forEach((feature) => { - const boundaryCode = feature.properties.boundaryCode; + const boundaryCode = feature?.properties?.boundaryCode; const additionalDetails = {}; for (let i = 0; i < hierarchy.length; i++) { - if (boundaryDataAgainstBoundaryCode[boundaryCode]?.[i] || boundaryDataAgainstBoundaryCode[boundaryCode]?.[i] === "") { + if (boundaryDataAgainstBoundaryCode?.[boundaryCode]?.[i] || boundaryDataAgainstBoundaryCode?.[boundaryCode]?.[i] === "") { additionalDetails[hierarchy[i]] = boundaryDataAgainstBoundaryCode[boundaryCode][i]; } else { additionalDetails[hierarchy[i]] = ""; diff --git a/health/micro-ui/web/micro-ui-internals/packages/modules/hcm-microplanning/src/utils/microplanPreviewUtils.js b/health/micro-ui/web/micro-ui-internals/packages/modules/hcm-microplanning/src/utils/microplanPreviewUtils.js index ff5cd55208f..6b659e7e2a6 100644 --- a/health/micro-ui/web/micro-ui-internals/packages/modules/hcm-microplanning/src/utils/microplanPreviewUtils.js +++ b/health/micro-ui/web/micro-ui-internals/packages/modules/hcm-microplanning/src/utils/microplanPreviewUtils.js @@ -136,7 +136,7 @@ export const useHypothesis = (tempHypothesisList, hypothesisAssumptionsList) => // Handles the change in hypothesis value const valueChangeHandler = (e, setTempHypothesisList, boundarySelections, setToast, t) => { // Checks it the boundary filters at at root level ( given constraints ) - if (Object.keys(boundarySelections).length !== 0 && Object.values(boundarySelections)?.every((item) => item?.length !== 0)) + if (Object.keys(boundarySelections).length !== 0 && Object.values(boundarySelections)?.some((item) => item?.length !== 0)) return setToast({ state: "error", message: t("HYPOTHESIS_CAN_BE_ONLY_APPLIED_ON_ADMIN_LEVEL_ZORO") }); // validating user input diff --git a/health/micro-ui/web/micro-ui-internals/packages/modules/hcm-microplanning/src/utils/uploadUtils.js b/health/micro-ui/web/micro-ui-internals/packages/modules/hcm-microplanning/src/utils/uploadUtils.js index 32935edba93..c1f158b3283 100644 --- a/health/micro-ui/web/micro-ui-internals/packages/modules/hcm-microplanning/src/utils/uploadUtils.js +++ b/health/micro-ui/web/micro-ui-internals/packages/modules/hcm-microplanning/src/utils/uploadUtils.js @@ -384,10 +384,21 @@ export const colorHeaders = async (workbook, headerList1, headerList2, headerLis } }; +const addUniqueWorksheet = (workbook, sheetName) => { + let uniqueSheetName = sheetName; + let counter = 1; + while (workbook.getWorksheet(uniqueSheetName)) { + uniqueSheetName = `${sheetName} (${counter})`; + counter++; + } + return workbook.addWorksheet(uniqueSheetName); +}; + export const formatTemplate = (template, workbook, t) => { template.forEach(({ sheetName, data }) => { - // Create a new worksheet with properties - const worksheet = workbook.addWorksheet(sheetName); + // Create a new worksheet with properties and unique name + const worksheet = addUniqueWorksheet(workbook, sheetName); + let commonColumnIndex = -1; data?.forEach((row, index) => { const worksheetRow = worksheet.addRow(row);