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

Popup for userAccess boundary area and toast message for assign unassign #1831

Merged
merged 5 commits into from
Nov 14, 2024

Conversation

abishekTa-egov
Copy link
Collaborator

@abishekTa-egov abishekTa-egov commented Nov 14, 2024

Popup for userAccess boundary area and toast message for assign unassign

Summary by CodeRabbit

Release Notes

  • New Features

    • Added success toast notifications for facility assignment updates, enhancing user feedback.
    • Introduced a new popup feature in the User Access component, improving interaction with data table rows.
  • User Interface Changes

    • Updated labels for the microplan name fields in search configurations, providing clearer user guidance.

These enhancements aim to improve user experience through better feedback and clearer interface elements.

@abishekTa-egov abishekTa-egov requested a review from a team as a code owner November 14, 2024 12:09
Copy link
Contributor

coderabbitai bot commented Nov 14, 2024

📝 Walkthrough

Walkthrough

The changes in this pull request involve updates to several components within the microplan module. Key modifications include the addition of success toast notifications in the FacilityPopup.js component to enhance user feedback during facility assignment. In the UserAccess.js component, a new state variable is introduced to manage popup visibility based on row IDs. Additionally, the labels for the microplanName field are updated in both MicroplanSearchConfig.js and MyMicroplanSearchConfig.js, altering the user interface without affecting the underlying logic.

Changes

File Change Summary
.../FacilityPopup.js Added success toast notifications in handleAssignUnassign for facility assignment status updates, including conditional success messages based on the action performed.
.../UserAccess.js Introduced chipPopUpRowId state variable for controlling popup visibility based on specific row IDs; removed previous boolean state and related commented-out code for clarity.
.../MicroplanSearchConfig.js Changed label for microplanName field from "Name of the microplan" to "MP_NAME_OF_MICROPLAN_OPEN_MICROPLANS" in the search configuration.
.../MyMicroplanSearchConfig.js Updated label for microplanName field from "Name of the microplan" to "MP_NAME_OF_MICROPLAN_MY_MICROPLANS" in the search configuration.

Possibly related PRs

  • Facility mapper #1590: Enhancements to the handleAssignUnassign function in FacilityPopup.js, related to user feedback updates.
  • Demo2 issue fixes #1663: Modifications in FacilityPopup.js focusing on error handling and toast notifications, aligning with the main PR's changes.
  • Changes regarding facility catchment popup #1741: Addition of the updateDetails prop in FacilityPopup.js, relevant to the management of facility details.
  • Facility data fix #1829: Introduction of a new case for MICROPLAN_FACILITY_SERVINGPOPULATION in UICustomizations.js, enhancing data handling related to facilities.

Suggested reviewers

  • nipunarora-eGov

🐇 In the meadow where bunnies play,
New popups hop in a joyful way.
Toasts of success, bright and clear,
Celebrate changes, bring us cheer!
Labels updated, all is bright,
In our microplan, everything's right! 🌼


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

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

Line range hint 1-89: Consider enhancing the search configuration structure.

While the current implementation works, there are several opportunities for improvement:

  1. The commented code should be removed to improve maintainability
  2. The validation pattern for microplanName is commented out but might be useful to prevent invalid inputs
  3. The custom hook name could be moved to a constants file for better maintainability

Consider applying these improvements:

- // THIS CONFIG FOR SUPERVISOR TAGGED USER 
+ // Configuration for supervisor-tagged users
  const defaultSearchValues = {
    microplanName: "",
  };
  
- // {
-   //   label: "Phone number",
-   //   isMandatory: false,
-   //   key: "Phone number",
-   //   type: "number",
-   //   disable: false,
-   //   populators: { name: "mobileNumber", error: "sample error message", validation: { min: 0, max: 999999999 } },
- // },

Also, consider adding input validation:

  populators: {
    name: "microplanName",
+   validation: { pattern: /^[a-zA-Z0-9\s-_]+$/i },
+   error: "MP_INVALID_MICROPLAN_NAME",
  },
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/UserAccess.js (2)

Line range hint 233-239: Consider adding debounce and minimum length validation to search

The current implementation might trigger unnecessary API calls as it lacks:

  1. Minimum length validation for search queries
  2. Debouncing to prevent rapid consecutive API calls

Consider implementing these improvements:

+ const debouncedSearch = Digit.Utils.debounce((query) => {
+   if (query?.length >= 2 || !query) {
+     setSearchQuery(query);
+   }
+ }, 500);

  const handleSearch = (query) => {
-   setSearchQuery(query);
+   debouncedSearch(query);
  };

Line range hint 1-324: Consider architectural improvements for better maintainability

The component handles multiple responsibilities (API calls, state management, UI rendering). Consider these architectural improvements:

  1. Extract API-related logic into a custom hook:
const useUserAccessAPI = (params) => {
  // Move API calls and related state here
  return { data, loading, error, actions };
};
  1. Create a separate component for the data table configuration:
const UserAccessTable = ({ data, onRowAction }) => {
  // Move columns and table-related logic here
  return <DataTable {...props} />;
};

This would improve maintainability and make the code more testable.

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

Line range hint 287-292: Enhance error handling implementation

The current error handling uses a generic message and doesn't utilize the error details from the API response. Consider implementing more specific error handling:

 onError: async (result) => {
-  // setDownloadError(true);
   setSelectedRows([]);
-  setShowToast({ key: "error", label: t("ERROR_WHILE_UPDATING_PLANFACILITY"), transitionTime: 5000 });
+  const errorMessage = result?.response?.data?.error?.message || t("ERROR_WHILE_UPDATING_PLANFACILITY");
+  console.error("Plan facility update failed:", result);
+  setShowToast({ 
+    key: "error", 
+    label: errorMessage,
+    transitionTime: 5000 
+  });
 },

Line range hint 391-428: Enhance accessibility for facility assignment actions

The selection and assignment actions could be made more accessible to screen reader users and keyboard navigation:

 <div className="selection-state-wrapper">
   <div className="svg-state-wrapper">
-    <SVG.DoneAll width={"1.5rem"} height={"1.5rem"} fill={"#C84C0E"}></SVG.DoneAll>
+    <SVG.DoneAll 
+      width={"1.5rem"} 
+      height={"1.5rem"} 
+      fill={"#C84C0E"}
+      aria-hidden="true"
+    />
     <div className={"selected-state"}>{`${selectedRows.length} ${
       selectedRows?.length === 1 
         ? t("MICROPLAN_SELECTED") 
         : t("MICROPLAN_SELECTED_PLURAL")
     }`}</div>
   </div>
   <div className={`table-actions-wrapper`}>
     <Button
       className={"campaign-type-alert-button"}
       variation="secondary"
       label={
         facilityAssignedStatus
           ? `${t("MICROPLAN_UNASSIGN_FACILITY")} ${details?.additionalDetails?.facilityName}`
           : `${t("MICROPLAN_ASSIGN_FACILITY")} ${details?.additionalDetails?.facilityName}`
       }
       type="button"
       onClick={handleAssignUnassign}
       size={"large"}
       icon={facilityAssignedStatus ? "Close" : "AddIcon"}
+      aria-label={
+        facilityAssignedStatus
+          ? t("ARIA_UNASSIGN_SELECTED_FACILITIES")
+          : t("ARIA_ASSIGN_SELECTED_FACILITIES")
+      }
     />
   </div>
 </div>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between aa672b1 and baf12f7.

📒 Files selected for processing (4)
  • health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/FacilityPopup.js (1 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/UserAccess.js (3 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/configs/MicroplanSearchConfig.js (1 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/configs/MyMicroplanSearchConfig.js (1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/FacilityPopup.js (1)

Pattern **/*.js: check

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/configs/MicroplanSearchConfig.js (1)

Pattern **/*.js: check

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

Pattern **/*.js: check

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

Line range hint 39-45: LGTM! Field configuration is properly structured

The search field configuration is well-structured with all necessary properties (label, key, type, and populators) properly defined.


39-39: Verify the translation key exists

The label has been changed to use the translation key "MP_NAME_OF_MICROPLAN_OPEN_MICROPLANS". Let's ensure this key is properly defined in the translation files to prevent missing translations.

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

44-44: LGTM: Improved state management for row-specific popups

The introduction of chipPopUpRowId state is a good improvement over the previous boolean state, as it enables better control over popup visibility for individual rows.

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

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

Line range hint 233-239: Optimize search functionality

The commented-out length check has been removed, which could lead to excessive API calls. Consider implementing debouncing:

+const [debouncedSearchQuery, setDebouncedSearchQuery] = useState(null);
+
+useEffect(() => {
+  const timer = setTimeout(() => {
+    setDebouncedSearchQuery(searchQuery);
+  }, 300);
+  return () => clearTimeout(timer);
+}, [searchQuery]);
+
 const handleSearch = (query) => {
-  setSearchQuery(query);
+  if (query?.length >= 2 || query === '') {
+    setSearchQuery(query);
+  }
 };
📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between baf12f7 and f539b2f.

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

Pattern **/*.js: check

🔇 Additional comments (1)
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/UserAccess.js (1)

44-44: LGTM: Clean state management implementation

The new state variable follows React best practices and provides clear intent for managing row-specific popups.

@nipunarora-eGov nipunarora-eGov merged commit 4c1e42f into console Nov 14, 2024
3 checks passed
@nipunarora-eGov nipunarora-eGov deleted the abi-14-11 branch November 14, 2024 17:16
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