-
Notifications
You must be signed in to change notification settings - Fork 22
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
BUGFIX/HCMPRE-1810:Resolving Code-Rabbit comments #2166
base: console
Are you sure you want to change the base?
Conversation
📝 WalkthroughWalkthroughThis pull request introduces a series of refactoring changes across multiple files in the microplan module. The modifications primarily focus on improving code clarity, simplifying status mapping logic, and enhancing the handling of search criteria and data processing. The changes span various components including UI customizations, search configurations, employee data handling, and project creation logic, with an emphasis on streamlining code structure and reducing complexity. Changes
Sequence DiagramsequenceDiagram
participant UI as User Interface
participant Config as Search Configuration
participant Service as Data Service
UI->>Config: Select Search Criteria
Config->>Config: Process Status Mapping
Config->>Service: Prepare Search Request
Service->>Service: Apply Filters
Service-->>UI: Return Filtered Results
Possibly related PRs
Suggested reviewers
Poem
✨ Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🔭 Outside diff range comments (9)
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/RoleTableComposer.js (1)
Line range hint
81-103
: Add null check for data.Employees array.The direct map call on
data?.Employees
could throw ifEmployees
is defined but not an array. Consider adding a null check or using a default empty array.- const resp = data?.Employees?.map((item, index) => { + const resp = (data?.Employees || []).map((item, index) => {health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/hooks/services/createUpdatePlanProject.js (8)
Line range hint
368-417
: Consider enhancing error messages for better user experience.The code is well-structured with proper validation and error handling. However, the error messages could be more specific.
Consider adding more descriptive error messages:
-setShowToast({ key: "error", label: "ERROR_MICROPLAN_NAME_ALREADY_EXISTS" }); +setShowToast({ key: "error", label: "ERROR_MICROPLAN_NAME_ALREADY_EXISTS", message: `A microplan with name "${totalFormData?.MICROPLAN_DETAILS?.microplanDetails?.microplanName}" already exists` });
Line range hint
420-533
: Remove arbitrary delay and handle API dependencies properly.The 5-second delay using
setTimeout
is a code smell that could lead to race conditions.Replace the arbitrary delay with proper API response handling:
-await new Promise((resolve) => setTimeout(resolve, 5000)); +const campaignResBoundaryResponse = await campaignResBoundary; +if (!campaignResBoundaryResponse?.CampaignDetails?.id) { + setShowToast({ key: "error", label: "ERR_CAMPAIGN_UPDATE_FAILED" }); + return; +}
Line range hint
535-606
: Clean up commented-out state updates.The code contains commented-out state updates that should be removed for better maintainability.
Remove the commented-out code:
-// setCurrentKey((prev) => prev + 1); -// setCurrentStep((prev) => prev + 1);
Line range hint
607-645
: Consider using a state management solution instead of window events.Using window events for state management can make the code harder to maintain and test.
Consider using React's Context API or a state management library like Redux for handling state updates:
// Create a context const MicroplanContext = React.createContext(); // Use context instead of window events const dispatch = useContext(MicroplanContext); dispatch({ type: 'LAST_STEP' });
Line range hint
646-676
: Add error handling for updatePlan call.The updatePlan call lacks error handling, which could lead to silent failures.
Add proper error handling:
-await updatePlan(upatedPlanObjSubHypothesis); -return; +try { + const response = await updatePlan(upatedPlanObjSubHypothesis); + if (!response?.PlanConfiguration?.[0]?.id) { + setShowToast({ key: "error", label: "ERR_SUB_HYPOTHESIS_UPDATE_FAILED" }); + } + return; +} catch (error) { + setShowToast({ key: "error", label: "ERR_SUB_HYPOTHESIS_UPDATE_FAILED" }); + throw error; +}
Line range hint
735-775
: Add error handling for updatePlan call.Similar to the SUB_HYPOTHESIS case, the updatePlan call lacks error handling.
Add proper error handling:
-await updatePlan(upatedPlanObjSubFormula); -return; +try { + const response = await updatePlan(upatedPlanObjSubFormula); + if (!response?.PlanConfiguration?.[0]?.id) { + setShowToast({ key: "error", label: "ERR_SUB_FORMULA_UPDATE_FAILED" }); + } + return; +} catch (error) { + setShowToast({ key: "error", label: "ERR_SUB_FORMULA_UPDATE_FAILED" }); + throw error; +}
Line range hint
863-925
: Add missing break statement to prevent fallthrough.The case block is missing a break statement, which could lead to unintended fallthrough.
Add the missing break statement:
}; } else { setShowToast({ key: "error", label: "ERR_FAILED_TO_COMPLETE_SETUP" }); } + break; }
Line range hint
925-953
: Consider using a state management solution instead of window events.Similar to the HYPOTHESIS case, using window events for state management can make the code harder to maintain and test.
Consider using React's Context API or a state management library like Redux for handling state updates:
// Create a context const MicroplanContext = React.createContext(); // Use context instead of window events const dispatch = useContext(MicroplanContext); dispatch({ type: 'LAST_STEP' });
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (6)
health/micro-ui/web/micro-ui-internals/example/src/UICustomizations.js
(1 hunks)health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/RoleTableComposer.js
(1 hunks)health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/UserAccess.js
(1 hunks)health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/configs/UICustomizations.js
(1 hunks)health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/hooks/services/createUpdatePlanProject.js
(12 hunks)health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/PopInbox.js
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/UserAccess.js (1)
Pattern **/*.js
: check
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/PopInbox.js (1)
Pattern **/*.js
: check
health/micro-ui/web/micro-ui-internals/example/src/UICustomizations.js (1)
Pattern **/*.js
: check
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/RoleTableComposer.js (1)
Pattern **/*.js
: check
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/hooks/services/createUpdatePlanProject.js (1)
Pattern **/*.js
: check
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/configs/UICustomizations.js (1)
Pattern **/*.js
: check
📓 Learnings (1)
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/PopInbox.js (1)
Learnt from: rachana-egov
PR: egovernments/DIGIT-Frontend#1847
File: health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/PlanInbox.js:308-314
Timestamp: 2024-11-18T04:35:51.535Z
Learning: In `PlanInbox.js`, the variable `planWithCensus?.StatusCount[selectedFilter]` is always defined in the given context, so null checks are unnecessary.
🪛 Biome (1.9.4)
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/hooks/services/createUpdatePlanProject.js
[error] 863-925: This case is falling through to the next case.
Add a break
or return
statement to the end of this case to prevent fallthrough.
(lint/suspicious/noFallthroughSwitchClause)
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/configs/UICustomizations.js
[error] 84-84: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.
The declaration is defined in this switch clause:
Unsafe fix: Wrap the declaration in a block.
(lint/correctness/noSwitchDeclarations)
[error] 85-85: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.
The declaration is defined in this switch clause:
Unsafe fix: Wrap the declaration in a block.
(lint/correctness/noSwitchDeclarations)
[error] 86-86: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.
The declaration is defined in this switch clause:
Unsafe fix: Wrap the declaration in a block.
(lint/correctness/noSwitchDeclarations)
[error] 94-107: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.
The declaration is defined in this switch clause:
Unsafe fix: Wrap the declaration in a block.
(lint/correctness/noSwitchDeclarations)
[error] 109-121: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.
The declaration is defined in this switch clause:
Unsafe fix: Wrap the declaration in a block.
(lint/correctness/noSwitchDeclarations)
[error] 174-174: Template literals are preferred over string concatenation.
Unsafe fix: Use a template literal.
(lint/style/useTemplate)
[error] 185-185: Template literals are preferred over string concatenation.
Unsafe fix: Use a template literal.
(lint/style/useTemplate)
[error] 196-196: Template literals are preferred over string concatenation.
Unsafe fix: Use a template literal.
(lint/style/useTemplate)
[error] 207-207: Template literals are preferred over string concatenation.
Unsafe fix: Use a template literal.
(lint/style/useTemplate)
[error] 111-111: Use Number.parseInt instead of the equivalent global.
ES2015 moved some globals into the Number namespace for consistency.
Safe fix: Use Number.parseInt instead.
(lint/style/useNumberNamespace)
🔇 Additional comments (9)
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/UserAccess.js (1)
304-307
: LGTM! Good UX improvement.The added effect hook that resets the search query when the category changes is a good practice. It prevents confusion by ensuring that search results are not filtered by stale search terms from a previous category.
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/RoleTableComposer.js (1)
Line range hint
192-252
: LGTM! Improved state management.The updated boundary change handling logic is more robust:
- Properly checks for existing rows before updates
- Maintains state consistency for both new and existing rows
- Preserves immutability in state updates
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/configs/UICustomizations.js (1)
51-78
: LGTM! Improved status mapping maintainability.The introduction of
MICROPLAN_STATUS_MAP
constant and simplified status handling inpreProcess
function improves code maintainability and readability.health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/PopInbox.js (1)
347-347
: LGTM! Simplified null check.The change from explicit null/undefined checks to using the logical OR operator is a cleaner approach that maintains the same functionality.
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/hooks/services/createUpdatePlanProject.js (4)
359-365
: LGTM! Clean and well-structured case block.The case block is properly enclosed in curly braces and handles the campaign details update correctly.
Line range hint
677-734
: LGTM! Well-structured formula configuration handling.The code includes proper validation, uses helper functions effectively, and has good error handling.
Line range hint
777-816
: LGTM! Well-structured file upload handling.The code properly handles file updates and includes good error handling.
Line range hint
818-861
: LGTM! Well-structured facility data upload handling.The code properly handles file updates and includes good error handling.
health/micro-ui/web/micro-ui-internals/example/src/UICustomizations.js (1)
770-793
: LGTM! Good refactoring of status mapping.The introduction of MICROPLAN_STATUS_MAP improves code maintainability by centralizing the status mapping logic. The mapping is clear and well-structured.
} | ||
|
||
case "MICROPLAN_STATUS": | ||
if (value && value != "NA") { | ||
return <p>{t(Digit.Utils.locale.getTransformedLocale("MICROPLAN_STATUS_" + value))}</p>; | ||
} else { | ||
return ( | ||
<div> | ||
<p>{t("NA")}</p> | ||
</div> | ||
); | ||
} | ||
|
||
case "CAMPAIGN_DISEASE": | ||
if (value && value != "NA") { | ||
return <p>{t(Digit.Utils.locale.getTransformedLocale("MICROPLAN_DISEASE_" + value))}</p>; | ||
} else { | ||
return ( | ||
<div> | ||
<p>{t("NA")}</p> | ||
</div> | ||
); | ||
} | ||
|
||
case "CAMPAIGN_TYPE": | ||
if (value && value != "NA") { | ||
return <p>{t(Digit.Utils.locale.getTransformedLocale("MICROPLAN_TYPE_" + value))}</p>; | ||
} else { | ||
return ( | ||
<div> | ||
<p>{t("NA")}</p> | ||
</div> | ||
); | ||
} | ||
|
||
case "DISTIRBUTION_STRATEGY": | ||
if (value && value != "NA") { | ||
return <p>{t(Digit.Utils.locale.getTransformedLocale("MICROPLAN_DISTRIBUTION_" + value))}</p>; | ||
} else { | ||
return ( | ||
<div> | ||
<p>{t("NA")}</p> | ||
</div> | ||
); | ||
); | ||
} else { | ||
return ( | ||
<div> | ||
<p>{t("NA")}</p> | ||
</div> | ||
); | ||
} | ||
|
||
case "MICROPLAN_STATUS": | ||
if (value && value != "NA") { | ||
return <p>{t(Digit.Utils.locale.getTransformedLocale("MICROPLAN_STATUS_" + value))}</p>; | ||
} else { | ||
return ( | ||
<div> | ||
<p>{t("NA")}</p> | ||
</div> | ||
); | ||
} | ||
|
||
case "CAMPAIGN_DISEASE": | ||
if (value && value != "NA") { | ||
return <p>{t(Digit.Utils.locale.getTransformedLocale("MICROPLAN_DISEASE_" + value))}</p>; | ||
} else { | ||
return ( | ||
<div> | ||
<p>{t("NA")}</p> | ||
</div> | ||
); | ||
} | ||
|
||
case "CAMPAIGN_TYPE": | ||
if (value && value != "NA") { | ||
return <p>{t(Digit.Utils.locale.getTransformedLocale("MICROPLAN_TYPE_" + value))}</p>; | ||
} else { | ||
return ( | ||
<div> | ||
<p>{t("NA")}</p> | ||
</div> | ||
); | ||
} | ||
|
||
case "DISTIRBUTION_STRATEGY": | ||
if (value && value != "NA") { | ||
return <p>{t(Digit.Utils.locale.getTransformedLocale("MICROPLAN_DISTRIBUTION_" + value))}</p>; | ||
} else { | ||
return ( | ||
<div> | ||
<p>{t("NA")}</p> | ||
</div> | ||
); | ||
} | ||
|
||
default: | ||
return null; // Handle any unexpected keys here if needed | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Wrap switch case declarations in blocks.
The switch case declarations should be wrapped in blocks to prevent variable hoisting issues.
case "ACTIONS":
+ {
const dummyFile = "c22a7676-d5d7-49b6-bcdb-83e9519f58df"
const microplanFileId = row?.campaignDetails?.additionalDetails?.microplanFileId || dummyFile;
let options = [];
// ... rest of the case
break;
+ }
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
switch (key) { | |
case "ACTIONS": | |
// TODO : Replace dummy file id with real file id when API is ready | |
const dummyFile = "c22a7676-d5d7-49b6-bcdb-83e9519f58df" | |
const microplanFileId = row?.campaignDetails?.additionalDetails?.microplanFileId || dummyFile; | |
let options = []; | |
if (row?.status == "DRAFT") { | |
options = [{ code: "1", name: "MP_ACTIONS_EDIT_SETUP" }]; | |
} else { | |
options = [{ code: "1", name: "MP_ACTIONS_VIEW_SUMMARY" }]; | |
} | |
const handleDownload = () => { | |
const files = row?.files; | |
const file = files.find((item) => item.templateIdentifier === "Population"); | |
const fileId = file?.filestoreId; | |
if (!fileId) { | |
console.error("Population template file not found"); | |
return; | |
} | |
const campaignName = row?.name || ""; | |
Digit.Utils.campaign.downloadExcelWithCustomName({ | |
fileStoreId: fileId, | |
customName: campaignName | |
}); | |
}; | |
const onActionSelect = (e) => { | |
if (e.name === "MP_ACTIONS_EDIT_SETUP") { | |
const key = parseInt(row?.additionalDetails?.key); | |
const resolvedKey = key === 8 ? 7 : key === 9 ? 10 : key || 2; | |
const url = `/${window.contextPath}/employee/microplan/setup-microplan?key=${resolvedKey}µplanId=${row.id}&campaignId=${row.campaignDetails.id}`; | |
window.location.href = url; | |
} | |
if (e.name == "MP_ACTIONS_VIEW_SUMMARY") { | |
window.location.href = `/${window.contextPath}/employee/microplan/setup-microplan?key=${10}µplanId=${row.id}&campaignId=${ | |
row.campaignDetails.id | |
}&setup-completed=true`; | |
} | |
}; | |
return ( | |
<div> | |
<ButtonNew style={{ width: "20rem" }} icon="DownloadIcon" onClick={handleDownload} label={t("WBH_DOWNLOAD_MICROPLAN")} title={t("WBH_DOWNLOAD_MICROPLAN")} /> | |
{microplanFileId && row?.status == "RESOURCE_ESTIMATIONS_APPROVED" ? ( | |
<div> | |
<ButtonNew style={{ width: "20rem" }} icon="DownloadIcon" onClick={handleDownload} label={t("WBH_DOWNLOAD_MICROPLAN")} title={t("WBH_DOWNLOAD_MICROPLAN")} /> | |
</div> | |
) : ( | |
<div className={"action-button-open-microplan"}> | |
<div style={{ position: "relative" }}> | |
<ButtonNew | |
type="actionButton" | |
variation="secondary" | |
label={t("MP_ACTIONS_FOR_MICROPLAN_SEARCH")} | |
title={t("MP_ACTIONS_FOR_MICROPLAN_SEARCH")} | |
options={options} | |
style={{ width: "20rem" }} | |
optionsKey="name" | |
showBottom={true} | |
isSearchable={false} | |
onOptionSelect={(item) => onActionSelect(item)} | |
/> | |
</div> | |
</div> | |
)} | |
</div> | |
) : ( | |
<div className={"action-button-open-microplan"}> | |
<div style={{ position: "relative" }}> | |
<ButtonNew | |
type="actionButton" | |
variation="secondary" | |
label={t("MP_ACTIONS_FOR_MICROPLAN_SEARCH")} | |
title={t("MP_ACTIONS_FOR_MICROPLAN_SEARCH")} | |
options={options} | |
style={{ width: "20rem" }} | |
optionsKey="name" | |
showBottom={true} | |
isSearchable={false} | |
onOptionSelect={(item) => onActionSelect(item)} | |
/> | |
); | |
case "NAME_OF_MICROPLAN": | |
if (value && value !== "NA") { | |
return ( | |
<div | |
style={{ | |
maxWidth: "15rem", // Set the desired maximum width | |
wordWrap: "break-word", // Allows breaking within words | |
whiteSpace: "normal", // Ensures text wraps normally | |
overflowWrap: "break-word", // Break long words at the edge | |
}} | |
> | |
<p>{t(value)}</p> | |
</div> | |
</div> | |
)} | |
</div> | |
); | |
case "NAME_OF_MICROPLAN": | |
if (value && value !== "NA") { | |
return ( | |
<div | |
style={{ | |
maxWidth: "15rem", // Set the desired maximum width | |
wordWrap: "break-word", // Allows breaking within words | |
whiteSpace: "normal", // Ensures text wraps normally | |
overflowWrap: "break-word", // Break long words at the edge | |
}} | |
> | |
<p>{t(value)}</p> | |
</div> | |
); | |
} else { | |
return ( | |
<div> | |
<p>{t("NA")}</p> | |
</div> | |
); | |
} | |
case "MICROPLAN_STATUS": | |
if (value && value != "NA") { | |
return <p>{t(Digit.Utils.locale.getTransformedLocale("MICROPLAN_STATUS_" + value))}</p>; | |
} else { | |
return ( | |
<div> | |
<p>{t("NA")}</p> | |
</div> | |
); | |
} | |
case "CAMPAIGN_DISEASE": | |
if (value && value != "NA") { | |
return <p>{t(Digit.Utils.locale.getTransformedLocale("MICROPLAN_DISEASE_" + value))}</p>; | |
} else { | |
return ( | |
<div> | |
<p>{t("NA")}</p> | |
</div> | |
); | |
} | |
case "CAMPAIGN_TYPE": | |
if (value && value != "NA") { | |
return <p>{t(Digit.Utils.locale.getTransformedLocale("MICROPLAN_TYPE_" + value))}</p>; | |
} else { | |
return ( | |
<div> | |
<p>{t("NA")}</p> | |
</div> | |
); | |
} | |
case "DISTIRBUTION_STRATEGY": | |
if (value && value != "NA") { | |
return <p>{t(Digit.Utils.locale.getTransformedLocale("MICROPLAN_DISTRIBUTION_" + value))}</p>; | |
} else { | |
return ( | |
<div> | |
<p>{t("NA")}</p> | |
</div> | |
); | |
); | |
} else { | |
return ( | |
<div> | |
<p>{t("NA")}</p> | |
</div> | |
); | |
} | |
case "MICROPLAN_STATUS": | |
if (value && value != "NA") { | |
return <p>{t(Digit.Utils.locale.getTransformedLocale("MICROPLAN_STATUS_" + value))}</p>; | |
} else { | |
return ( | |
<div> | |
<p>{t("NA")}</p> | |
</div> | |
); | |
} | |
case "CAMPAIGN_DISEASE": | |
if (value && value != "NA") { | |
return <p>{t(Digit.Utils.locale.getTransformedLocale("MICROPLAN_DISEASE_" + value))}</p>; | |
} else { | |
return ( | |
<div> | |
<p>{t("NA")}</p> | |
</div> | |
); | |
} | |
case "CAMPAIGN_TYPE": | |
if (value && value != "NA") { | |
return <p>{t(Digit.Utils.locale.getTransformedLocale("MICROPLAN_TYPE_" + value))}</p>; | |
} else { | |
return ( | |
<div> | |
<p>{t("NA")}</p> | |
</div> | |
); | |
} | |
case "DISTIRBUTION_STRATEGY": | |
if (value && value != "NA") { | |
return <p>{t(Digit.Utils.locale.getTransformedLocale("MICROPLAN_DISTRIBUTION_" + value))}</p>; | |
} else { | |
return ( | |
<div> | |
<p>{t("NA")}</p> | |
</div> | |
); | |
} | |
default: | |
return null; // Handle any unexpected keys here if needed | |
} | |
switch (key) { | |
case "ACTIONS": { | |
// TODO : Replace dummy file id with real file id when API is ready | |
const dummyFile = "c22a7676-d5d7-49b6-bcdb-83e9519f58df" | |
const microplanFileId = row?.campaignDetails?.additionalDetails?.microplanFileId || dummyFile; | |
let options = []; | |
if (row?.status == "DRAFT") { | |
options = [{ code: "1", name: "MP_ACTIONS_EDIT_SETUP" }]; | |
} else { | |
options = [{ code: "1", name: "MP_ACTIONS_VIEW_SUMMARY" }]; | |
} | |
const handleDownload = () => { | |
const files = row?.files; | |
const file = files.find((item) => item.templateIdentifier === "Population"); | |
const fileId = file?.filestoreId; | |
if (!fileId) { | |
console.error("Population template file not found"); | |
return; | |
} | |
const campaignName = row?.name || ""; | |
Digit.Utils.campaign.downloadExcelWithCustomName({ | |
fileStoreId: fileId, | |
customName: campaignName | |
}); | |
}; | |
const onActionSelect = (e) => { | |
if (e.name === "MP_ACTIONS_EDIT_SETUP") { | |
const key = parseInt(row?.additionalDetails?.key); | |
const resolvedKey = key === 8 ? 7 : key === 9 ? 10 : key || 2; | |
const url = `/${window.contextPath}/employee/microplan/setup-microplan?key=${resolvedKey}µplanId=${row.id}&campaignId=${row.campaignDetails.id}`; | |
window.location.href = url; | |
} | |
if (e.name == "MP_ACTIONS_VIEW_SUMMARY") { | |
window.location.href = `/${window.contextPath}/employee/microplan/setup-microplan?key=${10}µplanId=${row.id}&campaignId=${ | |
row.campaignDetails.id | |
}&setup-completed=true`; | |
} | |
}; | |
return ( | |
<div> | |
{microplanFileId && row?.status == "RESOURCE_ESTIMATIONS_APPROVED" ? ( | |
<div> | |
<ButtonNew style={{ width: "20rem" }} icon="DownloadIcon" onClick={handleDownload} label={t("WBH_DOWNLOAD_MICROPLAN")} title={t("WBH_DOWNLOAD_MICROPLAN")} /> | |
</div> | |
) : ( | |
<div className={"action-button-open-microplan"}> | |
<div style={{ position: "relative" }}> | |
<ButtonNew | |
type="actionButton" | |
variation="secondary" | |
label={t("MP_ACTIONS_FOR_MICROPLAN_SEARCH")} | |
title={t("MP_ACTIONS_FOR_MICROPLAN_SEARCH")} | |
options={options} | |
style={{ width: "20rem" }} | |
optionsKey="name" | |
showBottom={true} | |
isSearchable={false} | |
onOptionSelect={(item) => onActionSelect(item)} | |
/> | |
</div> | |
</div> | |
)} | |
</div> | |
); | |
} | |
case "NAME_OF_MICROPLAN": { | |
if (value && value !== "NA") { | |
return ( | |
<div | |
style={{ | |
maxWidth: "15rem", // Set the desired maximum width | |
wordWrap: "break-word", // Allows breaking within words | |
whiteSpace: "normal", // Ensures text wraps normally | |
overflowWrap: "break-word", // Break long words at the edge | |
}} | |
> | |
<p>{t(value)}</p> | |
</div> | |
); | |
} else { | |
return ( | |
<div> | |
<p>{t("NA")}</p> | |
</div> | |
); | |
} | |
} | |
case "MICROPLAN_STATUS": { | |
if (value && value != "NA") { | |
return <p>{t(Digit.Utils.locale.getTransformedLocale("MICROPLAN_STATUS_" + value))}</p>; | |
} else { | |
return ( | |
<div> | |
<p>{t("NA")}</p> | |
</div> | |
); | |
} | |
} | |
case "CAMPAIGN_DISEASE": { | |
if (value && value != "NA") { | |
return <p>{t(Digit.Utils.locale.getTransformedLocale("MICROPLAN_DISEASE_" + value))}</p>; | |
} else { | |
return ( | |
<div> | |
<p>{t("NA")}</p> | |
</div> | |
); | |
} | |
} | |
case "CAMPAIGN_TYPE": { | |
if (value && value != "NA") { | |
return <p>{t(Digit.Utils.locale.getTransformedLocale("MICROPLAN_TYPE_" + value))}</p>; | |
} else { | |
return ( | |
<div> | |
<p>{t("NA")}</p> | |
</div> | |
); | |
} | |
} | |
case "DISTIRBUTION_STRATEGY": { | |
if (value && value != "NA") { | |
return <p>{t(Digit.Utils.locale.getTransformedLocale("MICROPLAN_DISTRIBUTION_" + value))}</p>; | |
} else { | |
return ( | |
<div> | |
<p>{t("NA")}</p> | |
</div> | |
); | |
} | |
} | |
default: | |
return null; // Handle any unexpected keys here if needed | |
} |
🧰 Tools
🪛 Biome (1.9.4)
[error] 84-84: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.
The declaration is defined in this switch clause:
Unsafe fix: Wrap the declaration in a block.
(lint/correctness/noSwitchDeclarations)
[error] 85-85: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.
The declaration is defined in this switch clause:
Unsafe fix: Wrap the declaration in a block.
(lint/correctness/noSwitchDeclarations)
[error] 86-86: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.
The declaration is defined in this switch clause:
Unsafe fix: Wrap the declaration in a block.
(lint/correctness/noSwitchDeclarations)
[error] 94-107: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.
The declaration is defined in this switch clause:
Unsafe fix: Wrap the declaration in a block.
(lint/correctness/noSwitchDeclarations)
[error] 109-121: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.
The declaration is defined in this switch clause:
Unsafe fix: Wrap the declaration in a block.
(lint/correctness/noSwitchDeclarations)
[error] 174-174: Template literals are preferred over string concatenation.
Unsafe fix: Use a template literal.
(lint/style/useTemplate)
[error] 185-185: Template literals are preferred over string concatenation.
Unsafe fix: Use a template literal.
(lint/style/useTemplate)
[error] 196-196: Template literals are preferred over string concatenation.
Unsafe fix: Use a template literal.
(lint/style/useTemplate)
[error] 207-207: Template literals are preferred over string concatenation.
Unsafe fix: Use a template literal.
(lint/style/useTemplate)
[error] 111-111: Use Number.parseInt instead of the equivalent global.
ES2015 moved some globals into the Number namespace for consistency.
Safe fix: Use Number.parseInt instead.
(lint/style/useNumberNamespace)
BUGFIX/HCMPRE-1810:Resolving Code-Rabbit comments for merging to master
Summary by CodeRabbit
Bug Fixes
Refactor
Chores