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

Finalise Action for Facility Catchment + Validations #1642

Merged
merged 3 commits into from
Oct 23, 2024

Conversation

rachana-egov
Copy link
Contributor

@rachana-egov rachana-egov commented Oct 23, 2024

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced error handling and user feedback in multiple components, including WorkflowCommentPopUp, AccessibilityPopUp, EditVillagePopulationPopUp, and SecurityPopUp, with dynamic toast notifications for better error reporting.
    • Introduced a new route for handling success responses related to village operations in the application.
  • Bug Fixes

    • Improved robustness in the PopInbox component by refining conditions for API calls to prevent potential runtime errors.
  • Improvements

    • Added role verification and action management in the FacilityCatchmentMapping component, enhancing user interaction based on permissions.

@rachana-egov rachana-egov requested a review from a team as a code owner October 23, 2024 09:44
Copy link
Contributor

coderabbitai bot commented Oct 23, 2024

Caution

Review failed

The head commit changed during the review from 9e3f147 to dcc6cd8.

📝 Walkthrough
📝 Walkthrough

Walkthrough

This pull request introduces several modifications across multiple components within the microplan module. Key changes include enhancements to error handling and user feedback mechanisms in the WorkflowCommentPopUp, AccessibilityPopUp, EditVillagePopulationPopUp, and SecurityPopUp components by adding onSuccess props and toast notifications. The FacilityCatchmentMapping component has been updated to include user role verification and improved data fetching logic. Additionally, the PopInbox component has been refined to prevent runtime errors and enhance action visibility. A new route for handling success responses has also been added in the index.js file.

Changes

File Change Summary
.../WorkflowCommentPopUp.js Modified error handling in handleSave to dynamically retrieve error messages from API response.
.../accessbilityPopUP.js Added onSuccess prop, improved error handling with toast notifications, and modified rendering logic for toast visibility.
.../editVillagePopulationPopUP.js Introduced onSuccess prop, added toast notifications for error handling, and updated mutation handling with new state variables and useEffect hooks.
.../securityPopUp.js Added onSuccess prop, updated handleSave for improved error handling and toast notifications, and modified button state management.
.../employee/FacilityCatchmentMapping.js Enhanced functionality with user role verification, added local state for action bar visibility, and improved data fetching logic with custom hooks.
.../employee/PopInbox.js Updated jurisdiction state handling with optional chaining and introduced actionsToHide to filter out specific actions.
.../employee/index.js Added a new route for PrivateRoute to handle success responses for village-related operations.

Possibly related PRs

  • Component for bulk comment update workflow #1612: The WorkflowCommentPopUp component introduced in this PR is directly related to the changes in the main PR, which also modifies the WorkflowCommentPopUp component to enhance its functionality for submitting comments within a workflow interface.
  • Added action bar for pop inbox screen #1622: The modifications in the PopInbox component to integrate the WorkflowCommentPopUp for handling comments on workflow actions are related to the changes in the main PR, which focuses on the comment submission functionality.
  • added jurisdictions in facility serach and updated popinbox #1602: The updates to the PopInbox component to manage the visibility of the workflow comment popup are relevant as they enhance the interaction model for submitting comments, which aligns with the changes in the main PR.
  • planInbox console #1623: The changes in the PopInbox component to improve user interaction and manage the workflow comment popup are related to the enhancements made in the main PR regarding comment submission within workflows.

Suggested reviewers

  • nipunarora-eGov
  • nabeelmd-eGov

Poem

🐰 In the garden of code, where changes bloom,
Toasts of success chase away the gloom.
With props that sing and states that dance,
Each popup now gives users a chance.
Error messages clear, like stars in the night,
Hopping along, our features take flight! 🌟


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.

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

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

Line range hint 17-23: Improve null safety with optional chaining.

The access to nested properties could be safer with optional chaining.

-  if (census?.additionalDetails?.accessibilityDetails) {
-    setDropdown1Value(census.additionalDetails.accessibilityDetails.roadCondition);
-    setDropdown2Value(census.additionalDetails.accessibilityDetails.terrain);
-    setDropdown3Value(census.additionalDetails.accessibilityDetails.transportationMode);
+  if (census?.additionalDetails?.accessibilityDetails) {
+    setDropdown1Value(census?.additionalDetails?.accessibilityDetails?.roadCondition);
+    setDropdown2Value(census?.additionalDetails?.accessibilityDetails?.terrain);
+    setDropdown3Value(census?.additionalDetails?.accessibilityDetails?.transportationMode);
   }
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/editVillagePopulationPopUP.js (1)

Line range hint 9-28: Add validation for population input values.

The population values are stored as strings without validation. Consider:

  1. Adding numeric validation
  2. Preventing negative values
  3. Ensuring the confirmed population doesn't exceed reasonable limits
 const [confirmedTotalPopulation, setConfirmedTotalPopulation] = useState("");
 const [confirmedTargetPopulation, setConfirmedTargetPopulation] = useState("");
+const [errors, setErrors] = useState({});
+
+const validatePopulation = (value, field) => {
+  const num = Number(value);
+  if (isNaN(num)) return `${field} must be a number`;
+  if (num < 0) return `${field} cannot be negative`;
+  if (num > 1000000000) return `${field} exceeds maximum limit`;
+  return null;
+};
+
+const handlePopulationChange = (value, field) => {
+  const error = validatePopulation(value, field);
+  setErrors(prev => ({ ...prev, [field]: error }));
+  if (field === 'totalPopulation') setConfirmedTotalPopulation(value);
+  if (field === 'targetPopulation') setConfirmedTargetPopulation(value);
+};
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/WorkflowCommentPopUp.js (2)

Line range hint 13-83: Consider adding unit tests for the payload transformation logic.

The setCommentInPayloadForList function handles complex nested object transformations. To ensure reliability and catch potential edge cases, consider adding unit tests for this function.

Would you like me to help generate unit test cases for the payload transformation scenarios?

🧰 Tools
🪛 Biome

[error] 113-113: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


Line range hint 1-7: Add PropTypes validation for component props.

The component accepts several important props (onClose, heading, submitLabel, etc.) but lacks PropTypes validation. Consider adding proper prop validation to improve component reliability and documentation.

Example implementation:

+import PropTypes from 'prop-types';

 const WorkflowCommentPopUp = ({ onClose, heading, submitLabel, url, requestPayload, commentPath, onSuccess, onError }) => {
   // ... component implementation ...
 };
+
+WorkflowCommentPopUp.propTypes = {
+  onClose: PropTypes.func.isRequired,
+  heading: PropTypes.string.isRequired,
+  submitLabel: PropTypes.string.isRequired,
+  url: PropTypes.string.isRequired,
+  requestPayload: PropTypes.object.isRequired,
+  commentPath: PropTypes.string.isRequired,
+  onSuccess: PropTypes.func,
+  onError: PropTypes.func
+};
🧰 Tools
🪛 Biome

[error] 113-113: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/index.js (1)

Line range hint 198-203: Remove extra empty lines.

There are multiple consecutive empty lines after the route definition. Consider keeping just one empty line for better code organization.

Apply this diff:

        <PrivateRoute path={`${path}/village-finalise-success`} component={() => <Response />} />

-
-
-
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/PopInbox.js (1)

Line range hint 169-170: Document the purpose of filtering EDIT actions.

Add a comment explaining why EDIT actions are being filtered out from the workflow actions. This will help future maintainers understand the business logic behind this decision.

+ // Filter out EDIT actions as they are not applicable in the current workflow state
  const actionsToHide = actionsMain?.filter(action => action.action.includes("EDIT"))?.map(action => action.action);
🧰 Tools
🪛 Biome

[error] 175-175: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between a9a655f and 8b7db14.

📒 Files selected for processing (7)
  • health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/WorkflowCommentPopUp.js (1 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/accessbilityPopUP.js (3 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/editVillagePopulationPopUP.js (3 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/securityPopUp.js (4 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/FacilityCatchmentMapping.js (1 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/PopInbox.js (2 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/index.js (1 hunks)
🧰 Additional context used
📓 Path-based instructions (7)
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/WorkflowCommentPopUp.js (1)

Pattern **/*.js: check

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

Pattern **/*.js: check

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

Pattern **/*.js: check

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

Pattern **/*.js: check

health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/FacilityCatchmentMapping.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/packages/modules/microplan/src/pages/employee/index.js (1)

Pattern **/*.js: check

🪛 Biome
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/accessbilityPopUP.js

[error] 76-76: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 91-91: Avoid passing children using a prop

The canonical way to pass children in React is to use JSX elements

(lint/correctness/noChildrenProp)


[error] 129-136: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)


[error] 137-145: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/editVillagePopulationPopUP.js

[error] 66-66: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 81-81: Avoid passing children using a prop

The canonical way to pass children in React is to use JSX elements

(lint/correctness/noChildrenProp)


[error] 125-132: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)


[error] 133-141: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/securityPopUp.js

[error] 62-62: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 79-79: Avoid passing children using a prop

The canonical way to pass children in React is to use JSX elements

(lint/correctness/noChildrenProp)

health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/FacilityCatchmentMapping.js

[error] 56-56: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)


[error] 104-106: JSX elements without children should be marked as self-closing. In JSX, it is valid for any element to be self-closing.

Unsafe fix: Use a SelfClosingElement instead

(lint/style/useSelfClosingElements)


[error] 112-112: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/PopInbox.js

[error] 175-175: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)

🔇 Additional comments (4)
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/securityPopUp.js (2)

1-6: LGTM: Clean imports and proper prop additions

The component signature and imports have been updated appropriately to support the new error handling functionality.


74-146: LGTM: Well-structured UI with proper error handling

The PopUp and Toast components are well integrated with appropriate positioning and state management. The button states are handled correctly during loading.

🧰 Tools
🪛 Biome

[error] 79-79: Avoid passing children using a prop

The canonical way to pass children in React is to use JSX elements

(lint/correctness/noChildrenProp)

health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/index.js (1)

198-198: Verify the navigation to this success route.

The new route for handling village finalization success looks good. However, ensure that components triggering this route (likely the village finalization form/action) correctly navigate to this path.

Let's verify the usage of this route:

✅ Verification successful

The search results show that the village-finalise-success route is properly integrated with the system. It's being navigated to from the FacilityCatchmentMapping component using history.push() with appropriate success message and navigation parameters.

Let me verify the Response component usage to ensure it can handle these parameters:


Let me check the implementation of the Response component specifically in the microplan module:


Based on the verification results, I can now provide the final response:

The success route is properly integrated with the Response component

The Response component is correctly implemented to handle the success state passed from the FacilityCatchmentMapping component. It:

  • Receives state via useLocation() hook
  • Renders success message and description from the state
  • Provides proper back navigation with configurable back link and label
  • Uses PanelCard to show success status with proper styling
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find components that might navigate to this success route
# Test: Search for navigation or redirect logic to village-finalise-success
rg -A 3 "village-finalise-success" --type js

Length of output: 1254


Script:

#!/bin/bash
# Check the Response component implementation
ast-grep --pattern 'const Response = $_' -l js

Length of output: 85715


Script:

#!/bin/bash
# Find the Response component implementation in the microplan module
cat health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/Response.js

Length of output: 2490

health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/PopInbox.js (1)

Line range hint 392-399: Address TODO comment and hardcoded values in success navigation.

The success navigation contains a TODO comment and hardcoded values that need attention:

  1. The filename is marked as needing an update when the API is successful
  2. The success message and navigation paths are hardcoded

Let's verify if these values should be dynamic:

Would you like help implementing a more dynamic success navigation that derives values from the API response?

🧰 Tools
🪛 Biome

[error] 175-175: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)

coderabbitai[bot]
coderabbitai bot previously approved these changes Oct 23, 2024
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.

2 participants