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

Redirect to edit screen #1951

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

Redirect to edit screen #1951

wants to merge 11 commits into from

Conversation

abishekTa-egov
Copy link

@abishekTa-egov abishekTa-egov commented Dec 2, 2024

Redirect to edit screen

Summary by CodeRabbit

  • New Features

    • Introduced asynchronous configuration retrieval for microplan actions.
    • Added custom validation checks for phone numbers and date ranges.
    • Enhanced inbox module name retrieval and workflow creation processes.
    • Improved state synchronization in the Assumptions Form based on session data.
  • Bug Fixes

    • Improved error handling and state management in plan project updates.
  • Documentation

    • Updated method descriptions to reflect new functionalities and validations.

@abishekTa-egov abishekTa-egov requested a review from a team as a code owner December 2, 2024 07:26
Copy link
Contributor

coderabbitai bot commented Dec 2, 2024

Warning

Rate limit exceeded

@abishekTa-egov has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 18 minutes and 50 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 96cc22d and b0603a9.

📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request introduces several enhancements to the UICustomizations object across multiple files. Key additions include new methods for business service retrieval and validation checks, alongside updates to existing methods to improve workflow and data processing. Notably, asynchronous data fetching has been implemented for microplan configurations, and error handling has been standardized. These changes collectively aim to enhance the functionality, maintainability, and clarity of the codebase.

Changes

File Change Summary
health/micro-ui/web/micro-ui-internals/example/src/UICustomizations.js - Added getBusinessService(moduleCode) method.
- Updated getInboxModuleName(moduleCode) and updatePayload(applicationDetails, data, action, businessService) methods.
- Modified enableModalSubmit(businessService, action, setModalSubmit, data) method.
- Enhanced preProcess(data) and postProcess(responseArray, uiConfig) methods in AttendanceInboxConfig.
- Updated preProcess(data, additionalDetails) and added customValidationCheck(data) in SearchCampaign.
- Added customValidationCheck(data) in UserManagementConfig.
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/configs/UICustomizations.js - Added async searchPlanConfig(body) method.
- Updated preProcess(data, additionalDetails) and customValidationCheck(data) methods in UserManagementConfig.
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/hooks/services/createUpdatePlanProject.js - Updated const updatePlan = async (req) to include key extraction from query parameters. Minor formatting adjustments made for clarity.
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/AssumptionsForm.js - Introduced a new useEffect hook to synchronize state with sessionData for selectedDistributionProcess and selectedRegistrationProcess.

Possibly related PRs

  • Mp assumptions #1477: The customValidationCheck method in UserManagementConfig was updated to validate mobile numbers, which aligns with the changes made in the main PR regarding validation improvements.
  • Mp hypothesis #1501: The customValidationCheck method in UserManagementConfig was updated to include regex validation for mobile numbers, similar to the updates made in the main PR.
  • Microplansearch changes #1629: The customValidationCheck method in UserManagementConfig was enhanced to validate mobile numbers, reflecting the changes in the main PR.
  • MyMicroplan search change and user-access roles changes #1680: The customValidationCheck method in UserManagementConfig was updated to validate mobile numbers, which is consistent with the changes in the main PR.
  • ui fixes #1798: The additionalCustomizations method in FacilityMappingConfig was updated to include a new case for MICROPLAN_FACILITY_RESIDINGVILLAGE, which aligns with the enhancements made in the main PR regarding additional customizations.
  • Microplan name update #1821: The customValidationCheck method in UserManagementConfig was added to validate mobile numbers, which is consistent with the changes in the main PR.
  • Facility data fix #1829: The additionalCustomizations method in FacilityMappingConfig was updated to include a new case for MICROPLAN_FACILITY_SERVINGPOPULATION, which aligns with the enhancements made in the main PR regarding additional customizations.
  • updated code #1861: The customValidationCheck method in UserManagementConfig was updated to validate mobile numbers, which is consistent with the changes in the main PR.
  • added back button, redirected checklist success and fixed null issue … #1894: The changes in the CreateChecklist component include updates to the handling of user interactions, which may relate to the overall improvements in user management and validation in the main PR.
  • Edit Size button changed #1931: The changes to the button's style in UserAccessMgmtTableWrapper may relate to the overall UI enhancements made in the main PR.

Suggested reviewers

  • nipunarora-eGov

🐰 "In the code where changes bloom,
New methods dance and errors zoom.
With validations crisp and neat,
Our UIs now are quite a treat!
As plans unfold with each new line,
The rabbit hops, 'Oh, how divine!'" 🐇


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 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.

row.campaignDetails.id
}`;
}
const searchPlanConfig = async (body) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is wrong @abishekTa-egov directly access from row object you can't make any api calls here this is sync logic not async

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved

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: 3

🧹 Outside diff range comments (1)
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/configs/UICustomizations.js (1)

Line range hint 819-819: Provide user feedback when the download fails

In the handleDownload function, when the fileId is not found, it logs an error to the console but doesn't inform the user. To enhance user experience, consider displaying an error message to the user.

Apply this diff to provide user feedback:

 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");
+    // Display an error message to the user
+    Digit.Utils.toast.error(t("ERROR_POPULATION_TEMPLATE_NOT_FOUND"));
     return;
   }
   const campaignName = row?.name || "";
   Digit.Utils.campaign.downloadExcelWithCustomName({
     fileStoreId: fileId,
     customName: campaignName
   });
 };

Also applies to: 864-864

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between 652a965 and af6b34c.

📒 Files selected for processing (3)
  • health/micro-ui/web/micro-ui-internals/example/src/UICustomizations.js (3 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 (2 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
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

health/micro-ui/web/micro-ui-internals/example/src/UICustomizations.js (1)

Pattern **/*.js: check

🔇 Additional comments (2)
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/configs/UICustomizations.js (1)

Line range hint 828-851: Duplicate 'searchPlanConfig' function found

The searchPlanConfig function within the onActionSelect method is duplicated from earlier code (lines 111-119). Refactoring this function into a shared utility will prevent redundancy and simplify maintenance.

health/micro-ui/web/micro-ui-internals/example/src/UICustomizations.js (1)

819-819: Approve variable assignment

The assignment of campaignName with a default value is appropriate and follows best practices.

Comment on lines 111 to 119
const searchPlanConfig = async (body) => {
//assuming it will be success
const response = await Digit.CustomService.getResponse({
url: "/plan-service/config/_search",
useCache: false,
method: "POST",
userService: true,
body
});
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

Refactor 'searchPlanConfig' function to reduce code duplication

The searchPlanConfig function is defined within the onActionSelect method and is duplicated elsewhere in the code (see lines 828-851). To improve maintainability and reduce code duplication, consider extracting this function into a shared utility or moving it to a higher scope.

@@ -236,7 +238,7 @@ const createUpdatePlanProject = async (req) => {
//later this object must have an invalidation config which can be used to invalidate data such as files uploaded,assumptions,formulas etc...

const { totalFormData, state, setShowToast, setCurrentKey, setCurrentStep, config, invalidateConfig } = req;
const { microplanId, campaignId } = Digit.Hooks.useQueryParams();
const { microplanId, campaignId} = Digit.Hooks.useQueryParams();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Avoid calling hooks inside non-react functions

Similar to the previous comment, calling Digit.Hooks.useQueryParams() inside the createUpdatePlanProject function, which is not a React component or custom hook, can cause issues.

Pass microplanId and campaignId as parameters to the function instead:

-const createUpdatePlanProject = async (req) => {
+const createUpdatePlanProject = async (req, params) => {
   try {
     const { totalFormData, state, setShowToast, setCurrentKey, setCurrentStep, config, invalidateConfig } = req;
-    const { microplanId, campaignId } = Digit.Hooks.useQueryParams();
+    const { microplanId, campaignId } = params;

Ensure to pass the params when calling createUpdatePlanProject.

📝 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
const { microplanId, campaignId} = Digit.Hooks.useQueryParams();
const createUpdatePlanProject = async (req, params) => {
const { microplanId, campaignId } = params;

Comment on lines +225 to +226
const { key} = Digit.Hooks.useQueryParams();
req.additionalDetails.key=key;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Ensure 'useQueryParams' is called correctly

The Digit.Hooks.useQueryParams() hook should be called inside a React component or a custom hook. Using it directly within a non-react function (updatePlan) may lead to unexpected behavior.

Consider refactoring to pass key as a parameter to the updatePlan function:

-const updatePlan = async (req) => {
-  const { key } = Digit.Hooks.useQueryParams();
-  req.additionalDetails.key = key;
+const updatePlan = async (req, key) => {
+  req.additionalDetails.key = key;

And update the places where updatePlan is called to pass the key appropriately.

Committable suggestion skipped: line range outside the PR's diff.

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: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between af6b34c and 244799d.

📒 Files selected for processing (3)
  • health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/AssumptionsForm.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 (3 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/AssumptionsForm.js (1)

Pattern **/*.js: check

health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/configs/UICustomizations.js (1)

Pattern **/*.js: check

health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/hooks/services/createUpdatePlanProject.js (1)

Pattern **/*.js: check

🪛 Biome (1.9.4)
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/configs/UICustomizations.js

[error] 120-120: 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)

health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/hooks/services/createUpdatePlanProject.js

[error] 772-799: 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] 802-807: 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)

🔇 Additional comments (4)
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/configs/UICustomizations.js (1)

111-133: ⚠️ Potential issue

Avoid making asynchronous API calls inside synchronous action handlers

Making an asynchronous API call within the onActionSelect function can lead to unexpected behavior since this logic is expected to be synchronous. Consider accessing the required data directly from row or refactoring the function to handle asynchronous operations appropriately.

🧰 Tools
🪛 Biome (1.9.4)

[error] 120-120: 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)

health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/AssumptionsForm.js (1)

71-74: State synchronization looks good

The added useEffect correctly updates the state based on session data changes.

health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/hooks/services/createUpdatePlanProject.js (2)

225-226: ⚠️ Potential issue

Avoid calling React hooks inside non-React functions

Using Digit.Hooks.useQueryParams() inside updatePlan, which is not a React component or custom hook, can lead to unexpected behavior. React hooks should only be called at the top level of React components or custom hooks. Consider passing key as a parameter instead.


241-241: ⚠️ Potential issue

Avoid calling React hooks inside non-React functions

Using Digit.Hooks.useQueryParams() inside createUpdatePlanProject may cause issues since it's not a React component or custom hook. Consider passing microplanId and campaignId as parameters to the function instead.

userService: true,
body
});
window.location.href = `/${window.contextPath}/employee/microplan/setup-microplan?key=${String(parseInt(response?.PlanConfiguration[0]?.additionalDetails?.key || "0")+1)}&microplanId=${row.id}&campaignId=${
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Use Number.parseInt instead of global parseInt

ES2015 moved some globals into the Number namespace for consistency. Using Number.parseInt is preferred over the global parseInt.

Apply this diff to update the code:

-window.location.href = `/${window.contextPath}/employee/microplan/setup-microplan?key=${String(parseInt(response?.PlanConfiguration[0]?.additionalDetails?.key || "0")+1)}&microplanId=${row.id}&campaignId=${
+window.location.href = `/${window.contextPath}/employee/microplan/setup-microplan?key=${String(Number.parseInt(response?.PlanConfiguration[0]?.additionalDetails?.key || "0")+1)}&microplanId=${row.id}&campaignId=${
📝 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
window.location.href = `/${window.contextPath}/employee/microplan/setup-microplan?key=${String(parseInt(response?.PlanConfiguration[0]?.additionalDetails?.key || "0")+1)}&microplanId=${row.id}&campaignId=${
window.location.href = `/${window.contextPath}/employee/microplan/setup-microplan?key=${String(Number.parseInt(response?.PlanConfiguration[0]?.additionalDetails?.key || "0")+1)}&microplanId=${row.id}&campaignId=${
🧰 Tools
🪛 Biome (1.9.4)

[error] 120-120: 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)

Comment on lines 770 to 832
case "ROLE_ACCESS_CONFIGURATION":
// Function to run API validations
const searchAndUpdatePlanConfig = async (body) => {
try {
// Make the API call
const { key} = Digit.Hooks.useQueryParams();
const fetchedPlanConfig = await searchPlanConfig({
PlanConfigurationSearchCriteria: {
tenantId,
id: microplanId,
},
});

const response = await Digit.CustomService.getResponse({
url: "/plan-service/config/_update",
body: {
PlanConfiguration: {...fetchedPlanConfig,
additionalDetails:{...fetchedPlanConfig.additionalDetails,key:key
}},
},
});

// Process the response if necessary
console.log("API Response:", response);
return response; // Return the response for further usage if needed
} catch (error) {
console.error("Error in searchPlanConfig:", error);
throw error; // Rethrow error to handle it further up the chain if needed
}
};

// Request body for the API call
const reqBody = {
PlanConfigurationSearchCriteria: {
id: microplanId,
tenantId: Digit.ULBService.getCurrentTenantId(),
},
};

// Execute the API call
try {
const apiResponse = await searchAndUpdatePlanConfig(reqBody); // Wait for the API call to complete
console.log("API call completed successfully:", apiResponse);

// Proceed with the rest of the logic
setCurrentKey((prev) => prev + 1);
setCurrentStep((prev) => prev + 1);
window.dispatchEvent(new Event("isLastStep"));
Digit.Utils.microplanv1.updateUrlParams({ isLastVerticalStep: null });
Digit.Utils.microplanv1.updateUrlParams({ internalKey: null });

// Return as expected
return {
triggeredFrom,
};
} catch (error) {
console.error("Error during ROLE_ACCESS_CONFIGURATION flow:", error);
// Optionally handle the error here, e.g., show an error message to the user
return {
error: "API call failed. Please try again.",
};
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Wrap switch case body in braces to limit scope of declarations

Declaring functions and variables within a switch case without wrapping the case body in braces can cause scope leakage where other cases may access these declarations unexpectedly. Wrap the code inside the 'ROLE_ACCESS_CONFIGURATION' case with braces {} to ensure proper scoping.

Apply this diff to fix the scoping issue:

          case "ROLE_ACCESS_CONFIGURATION":
+           {
              // Function to run API validations
              const searchAndUpdatePlanConfig = async (body) => {
                  // code
              };
              // Request body for the API call
              const reqBody = {
                  // ...
              };
              // Execute the API call
              try {
                  // code
              } catch (error) {
                  // code
              }
+           }
📝 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
case "ROLE_ACCESS_CONFIGURATION":
// Function to run API validations
const searchAndUpdatePlanConfig = async (body) => {
try {
// Make the API call
const { key} = Digit.Hooks.useQueryParams();
const fetchedPlanConfig = await searchPlanConfig({
PlanConfigurationSearchCriteria: {
tenantId,
id: microplanId,
},
});
const response = await Digit.CustomService.getResponse({
url: "/plan-service/config/_update",
body: {
PlanConfiguration: {...fetchedPlanConfig,
additionalDetails:{...fetchedPlanConfig.additionalDetails,key:key
}},
},
});
// Process the response if necessary
console.log("API Response:", response);
return response; // Return the response for further usage if needed
} catch (error) {
console.error("Error in searchPlanConfig:", error);
throw error; // Rethrow error to handle it further up the chain if needed
}
};
// Request body for the API call
const reqBody = {
PlanConfigurationSearchCriteria: {
id: microplanId,
tenantId: Digit.ULBService.getCurrentTenantId(),
},
};
// Execute the API call
try {
const apiResponse = await searchAndUpdatePlanConfig(reqBody); // Wait for the API call to complete
console.log("API call completed successfully:", apiResponse);
// Proceed with the rest of the logic
setCurrentKey((prev) => prev + 1);
setCurrentStep((prev) => prev + 1);
window.dispatchEvent(new Event("isLastStep"));
Digit.Utils.microplanv1.updateUrlParams({ isLastVerticalStep: null });
Digit.Utils.microplanv1.updateUrlParams({ internalKey: null });
// Return as expected
return {
triggeredFrom,
};
} catch (error) {
console.error("Error during ROLE_ACCESS_CONFIGURATION flow:", error);
// Optionally handle the error here, e.g., show an error message to the user
return {
error: "API call failed. Please try again.",
};
}
case "ROLE_ACCESS_CONFIGURATION": {
// Function to run API validations
const searchAndUpdatePlanConfig = async (body) => {
try {
// Make the API call
const { key} = Digit.Hooks.useQueryParams();
const fetchedPlanConfig = await searchPlanConfig({
PlanConfigurationSearchCriteria: {
tenantId,
id: microplanId,
},
});
const response = await Digit.CustomService.getResponse({
url: "/plan-service/config/_update",
body: {
PlanConfiguration: {...fetchedPlanConfig,
additionalDetails:{...fetchedPlanConfig.additionalDetails,key:key
}},
},
});
// Process the response if necessary
console.log("API Response:", response);
return response; // Return the response for further usage if needed
} catch (error) {
console.error("Error in searchPlanConfig:", error);
throw error; // Rethrow error to handle it further up the chain if needed
}
};
// Request body for the API call
const reqBody = {
PlanConfigurationSearchCriteria: {
id: microplanId,
tenantId: Digit.ULBService.getCurrentTenantId(),
},
};
// Execute the API call
try {
const apiResponse = await searchAndUpdatePlanConfig(reqBody); // Wait for the API call to complete
console.log("API call completed successfully:", apiResponse);
// Proceed with the rest of the logic
setCurrentKey((prev) => prev + 1);
setCurrentStep((prev) => prev + 1);
window.dispatchEvent(new Event("isLastStep"));
Digit.Utils.microplanv1.updateUrlParams({ isLastVerticalStep: null });
Digit.Utils.microplanv1.updateUrlParams({ internalKey: null });
// Return as expected
return {
triggeredFrom,
};
} catch (error) {
console.error("Error during ROLE_ACCESS_CONFIGURATION flow:", error);
// Optionally handle the error here, e.g., show an error message to the user
return {
error: "API call failed. Please try again.",
};
}
}
🧰 Tools
🪛 Biome (1.9.4)

[error] 772-799: 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] 802-807: 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)

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: 3

🧹 Outside diff range comments (2)
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/configs/UICustomizations.js (2)

Line range hint 827-827: Use strict equality operator === instead of ==

For type-safe comparison, use === instead of == when comparing values.

Apply this diff to update the code:

- if (e.name == "MP_ACTIONS_EDIT_SETUP") { 
+ if (e.name === "MP_ACTIONS_EDIT_SETUP") { 
🧰 Tools
🪛 Biome (1.9.4)

[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)


Line range hint 832-832: Use strict equality operator === instead of ==

To ensure correct type comparison, use === instead of ==.

Apply this diff to update the code:

- if (e.name == "MP_ACTIONS_VIEW_SUMMARY") {
+ if (e.name === "MP_ACTIONS_VIEW_SUMMARY") {
🧰 Tools
🪛 Biome (1.9.4)

[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)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between 244799d and 45d8a23.

📒 Files selected for processing (2)
  • health/micro-ui/web/micro-ui-internals/example/src/UICustomizations.js (2 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/configs/UICustomizations.js (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/configs/UICustomizations.js (1)

Pattern **/*.js: check

health/micro-ui/web/micro-ui-internals/example/src/UICustomizations.js (1)

Pattern **/*.js: check

🪛 Biome (1.9.4)
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/configs/UICustomizations.js

[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)

health/micro-ui/web/micro-ui-internals/example/src/UICustomizations.js

[error] 828-828: 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 (4)
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/configs/UICustomizations.js (2)

111-111: Use Number.parseInt instead of global parseInt

ES2015 introduced Number.parseInt for consistency. Replace the global parseInt with Number.parseInt.

Apply this diff to update the code:

- window.location.href = `/${window.contextPath}/employee/microplan/setup-microplan?key=${String(parseInt(row?.additionalDetails?.key || '0') + 1)}&microplanId=${row.id}&campaignId=${
+ window.location.href = `/${window.contextPath}/employee/microplan/setup-microplan?key=${String(Number.parseInt(row?.additionalDetails?.key || '0') + 1)}&microplanId=${row.id}&campaignId=${
🧰 Tools
🪛 Biome (1.9.4)

[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)


Line range hint 828-828: Use Number.parseInt instead of global parseInt

Replace the global parseInt with Number.parseInt for consistency with ES2015 standards.

Apply this diff to update the code:

- window.location.href = `/${window.contextPath}/employee/microplan/setup-microplan?key=${String(parseInt(row?.additionalDetails?.key || '0') + 1)}&microplanId=${row.id}&campaignId=${
+ window.location.href = `/${window.contextPath}/employee/microplan/setup-microplan?key=${String(Number.parseInt(row?.additionalDetails?.key || '0') + 1)}&microplanId=${row.id}&campaignId=${
🧰 Tools
🪛 Biome (1.9.4)

[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)

health/micro-ui/web/micro-ui-internals/example/src/UICustomizations.js (2)

832-832: 🧹 Nitpick (assertive)

Use strict equality operator === instead of ==

For accurate type comparison, replace == with ===.

Apply this diff to update the code:

- if (e.name == "MP_ACTIONS_VIEW_SUMMARY") {
+ if (e.name === "MP_ACTIONS_VIEW_SUMMARY") {

Likely invalid or redundant comment.


828-828: 🧹 Nitpick (assertive)

Use strict equality operator === instead of ==

It's best practice to use === for strict equality comparisons in JavaScript.

Apply this diff to update the code:

- if (e.name == "MP_ACTIONS_EDIT_SETUP") { 
+ if (e.name === "MP_ACTIONS_EDIT_SETUP") { 

Likely invalid or redundant comment.

🧰 Tools
🪛 Biome (1.9.4)

[error] 828-828: 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)

row.campaignDetails.id
}`;
}
if (e.name == "MP_ACTIONS_EDIT_SETUP") {
Copy link
Contributor

@coderabbitai coderabbitai bot Dec 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Use strict equality operator === instead of ==

To ensure type-safe comparisons in JavaScript, it's recommended to use === instead of ==.

Apply this diff to update the code:

- if (e.name == "MP_ACTIONS_EDIT_SETUP") { 
+ if (e.name === "MP_ACTIONS_EDIT_SETUP") { 
📝 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
if (e.name == "MP_ACTIONS_EDIT_SETUP") {
if (e.name === "MP_ACTIONS_EDIT_SETUP") {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TAAbishek, thank you for resolving the issue!

(^‿^)/


If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!

Comment on lines 827 to 832
if (e.name == "MP_ACTIONS_EDIT_SETUP") {
window.location.href = `/${window.contextPath}/employee/microplan/setup-microplan?key=${String(parseInt(row?.additionalDetails?.key || '0') + 1)}&microplanId=${row.id}&campaignId=${
row.campaignDetails.id
}`;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Refactor 'onActionSelect' function to reduce code duplication

The onActionSelect function appears to be duplicated across different configurations. Consider extracting it into a shared utility to enhance maintainability.

🧰 Tools
🪛 Biome (1.9.4)

[error] 828-828: 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)

}`;
}
if (e.name == "MP_ACTIONS_EDIT_SETUP") {
window.location.href = `/${window.contextPath}/employee/microplan/setup-microplan?key=${String(parseInt(row?.additionalDetails?.key || '0') + 1)}&microplanId=${row.id}&campaignId=${
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

Use Number.parseInt instead of global parseInt

Replace the global parseInt with Number.parseInt for consistency and adherence to ES2015 standards.

Apply this diff to update the code:

- window.location.href = `/${window.contextPath}/employee/microplan/setup-microplan?key=${String(parseInt(row?.additionalDetails?.key || '0') + 1)}&microplanId=${row.id}&campaignId=${
+ window.location.href = `/${window.contextPath}/employee/microplan/setup-microplan?key=${String(Number.parseInt(row?.additionalDetails?.key || '0') + 1)}&microplanId=${row.id}&campaignId=${
📝 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
window.location.href = `/${window.contextPath}/employee/microplan/setup-microplan?key=${String(parseInt(row?.additionalDetails?.key || '0') + 1)}&microplanId=${row.id}&campaignId=${
window.location.href = `/${window.contextPath}/employee/microplan/setup-microplan?key=${String(Number.parseInt(row?.additionalDetails?.key || '0') + 1)}&microplanId=${row.id}&campaignId=${
🧰 Tools
🪛 Biome (1.9.4)

[error] 828-828: 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)

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between 45d8a23 and 96cc22d.

📒 Files selected for processing (4)
  • health/micro-ui/web/micro-ui-internals/example/src/UICustomizations.js (2 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/AssumptionsForm.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 (3 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/AssumptionsForm.js (1)

Pattern **/*.js: check

health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/configs/UICustomizations.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/example/src/UICustomizations.js (1)

Pattern **/*.js: check

🪛 Biome (1.9.4)
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/configs/UICustomizations.js

[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)


[error] 112-112: 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)

health/micro-ui/web/micro-ui-internals/example/src/UICustomizations.js

[error] 828-828: 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)


[error] 829-829: 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 (4)
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/configs/UICustomizations.js (1)

111-112: Use Number.parseInt instead of global parseInt

Replace the global parseInt with Number.parseInt for consistency and adherence to ES2015 standards.

Also applies to: 828-829

🧰 Tools
🪛 Biome (1.9.4)

[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)


[error] 112-112: 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)

health/micro-ui/web/micro-ui-internals/example/src/UICustomizations.js (1)

828-829: Use Number.parseInt instead of global parseInt

Replace the global parseInt with Number.parseInt for consistency and adherence to ES2015 standards.

🧰 Tools
🪛 Biome (1.9.4)

[error] 828-828: 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)


[error] 829-829: 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)

health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/hooks/services/createUpdatePlanProject.js (2)

263-264: ⚠️ Potential issue

Avoid calling hooks inside non-React functions

Hooks like useQueryParams should be called only within React components or custom hooks, not inside regular functions. Calling them here may lead to unexpected behavior.

Also applies to: 279-279


808-871: ⚠️ Potential issue

Avoid calling hooks inside non-React functions and wrap switch case body in braces

Calling useQueryParams inside a regular function within a switch case is not appropriate and can cause issues. Additionally, declaring functions inside a switch case without wrapping the case body in braces can lead to scope leakage.

Comment on lines +71 to +75
useEffect(()=>{
setSelectedDistributionProcess(props?.props?.sessionData?.ASSUMPTIONS_FORM?.assumptionsForm?.selectedDistributionProcess);
setSelectedRegistrationProcess(props?.props?.sessionData?.ASSUMPTIONS_FORM?.assumptionsForm?.selectedRegistrationProcess);
setSelectedRegistrationDistributionMode(props?.props?.sessionData?.ASSUMPTIONS_FORM?.assumptionsForm?.selectedRegistrationDistributionMode )
},[props?.props?.sessionData?.ASSUMPTIONS_FORM?.assumptionsForm])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Simplify state updates by destructuring props

To improve readability, consider destructuring props to avoid repetitive nested property access.

Apply this diff to simplify the code:

+ const { selectedDistributionProcess, selectedRegistrationProcess, selectedRegistrationDistributionMode } = props?.props?.sessionData?.ASSUMPTIONS_FORM?.assumptionsForm;

  useEffect(() => {
-   setSelectedDistributionProcess(props?.props?.sessionData?.ASSUMPTIONS_FORM?.assumptionsForm?.selectedDistributionProcess);
-   setSelectedRegistrationProcess(props?.props?.sessionData?.ASSUMPTIONS_FORM?.assumptionsForm?.selectedRegistrationProcess);
-   setSelectedRegistrationDistributionMode(props?.props?.sessionData?.ASSUMPTIONS_FORM?.assumptionsForm?.selectedRegistrationDistributionMode);
+   setSelectedDistributionProcess(selectedDistributionProcess);
+   setSelectedRegistrationProcess(selectedRegistrationProcess);
+   setSelectedRegistrationDistributionMode(selectedRegistrationDistributionMode);
  }, [props?.props?.sessionData?.ASSUMPTIONS_FORM?.assumptionsForm]);
📝 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
useEffect(()=>{
setSelectedDistributionProcess(props?.props?.sessionData?.ASSUMPTIONS_FORM?.assumptionsForm?.selectedDistributionProcess);
setSelectedRegistrationProcess(props?.props?.sessionData?.ASSUMPTIONS_FORM?.assumptionsForm?.selectedRegistrationProcess);
setSelectedRegistrationDistributionMode(props?.props?.sessionData?.ASSUMPTIONS_FORM?.assumptionsForm?.selectedRegistrationDistributionMode )
},[props?.props?.sessionData?.ASSUMPTIONS_FORM?.assumptionsForm])
const { selectedDistributionProcess, selectedRegistrationProcess, selectedRegistrationDistributionMode } = props?.props?.sessionData?.ASSUMPTIONS_FORM?.assumptionsForm;
useEffect(()=>{
setSelectedDistributionProcess(selectedDistributionProcess);
setSelectedRegistrationProcess(selectedRegistrationProcess);
setSelectedRegistrationDistributionMode(selectedRegistrationDistributionMode);
},[props?.props?.sessionData?.ASSUMPTIONS_FORM?.assumptionsForm])

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.

3 participants