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

BUGFIX/HCMPRE-1810:Resolving Code-Rabbit comments #2166

Open
wants to merge 3 commits into
base: console
Choose a base branch
from

Conversation

abishekTa-egov
Copy link
Contributor

@abishekTa-egov abishekTa-egov commented Jan 28, 2025

BUGFIX/HCMPRE-1810:Resolving Code-Rabbit comments for merging to master

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of employee search and status filtering across multiple components
    • Simplified status mapping logic in microplan configurations
    • Enhanced search query reset mechanism when changing categories
  • Refactor

    • Streamlined code structure in microplan-related components
    • Improved control flow in project creation and update processes
    • Simplified status property assignments
  • Chores

    • Updated comments and code clarity in various microplan modules
    • Consolidated status mapping approaches

@abishekTa-egov abishekTa-egov requested a review from a team as a code owner January 28, 2025 07:00
Copy link
Contributor

coderabbitai bot commented Jan 28, 2025

📝 Walkthrough

Walkthrough

This 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

File Change Summary
micro-ui-internals/example/src/UICustomizations.js Replaced dic object with MICROPLAN_STATUS_MAP, removed unused name variable, updated status mapping logic
packages/modules/microplan/src/components/RoleTableComposer.js Removed optional chaining before map method, updated handleBoundaryChange to improve state management
packages/modules/microplan/src/components/UserAccess.js Added effect to reset search query when category changes
packages/modules/microplan/src/configs/UICustomizations.js Refactored preProcess and additionalCustomizations functions, simplified status mapping and rendering logic
packages/modules/microplan/src/hooks/services/createUpdatePlanProject.js Added curly braces to case blocks, enhanced control flow and error handling
packages/modules/microplan/src/pages/employee/PopInbox.js Simplified status property assignment using logical OR operator

Sequence Diagram

sequenceDiagram
    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
Loading

Possibly related PRs

Suggested reviewers

  • nipunarora-eGov

Poem

🐰 A Rabbit's Refactoring Tale 🔧

In lines of code, we dance and play,
Mapping statuses the cleaner way,
With constants bright and logic neat,
Our microplan's now a coding treat!

Hop, hop, hurray! The changes shine! 🌟

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 if Employees 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

📥 Commits

Reviewing files that changed from the base of the PR and between bf3a7f0 and 4ba33a0.

📒 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 in preProcess 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.

Comment on lines +81 to 218
}

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
}
Copy link
Contributor

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.

Suggested change
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}&microplanId=${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}&microplanId=${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}&microplanId=${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}&microplanId=${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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant