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

MyMicroplan search change and user-access roles changes #1680

Merged
merged 6 commits into from
Oct 27, 2024

Conversation

abishekTa-egov
Copy link
Collaborator

@abishekTa-egov abishekTa-egov commented Oct 26, 2024

Microplan search working
Ui customization updated
User-access role doesn't show country for other than national roles

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced search functionality with new properties for more specific queries.
    • Role-based access control introduced for user actions.
    • Improved localization for displayed text to ensure consistency.
  • Bug Fixes

    • Custom validation for mobile numbers added in user management.
  • Refactor

    • Updated button components for improved interaction.
    • Refined filtering logic in the RoleTableComposer for better hierarchy selection.
  • Chores

    • Cleaned up preprocessing logic to ensure data integrity in requests.

@abishekTa-egov abishekTa-egov requested a review from a team as a code owner October 26, 2024 05:51
Copy link
Contributor

coderabbitai bot commented Oct 26, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request introduces significant modifications to the UICustomizations module and related components, enhancing functionalities like role-based access control, localization, and custom validation. Key changes include new properties and methods in MyMicroplanSearchConfig and UserManagementConfig, updates to button components, and adjustments to the filtering logic in RoleTableComposer. Additionally, the API request structures in searchSavedPlansWithCampaign.js have been altered. Overall, these changes aim to improve the maintainability and user experience of the application.

Changes

File Change Summary
health/micro-ui/web/micro-ui-internals/example/src/UICustomizations.js - Added new properties and methods to MyMicroplanSearchConfig and UserManagementConfig.
- Introduced role-checking mechanisms.
- Updated button components to ButtonNew.
- Improved localization with consistent use of t() function.
- Added custom validation for mobile numbers.
- Refined preprocessing logic to ensure clean data.
- Expanded additionalCustomizations method for handling new keys.
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/RoleTableComposer.js - Adjusted filtering logic for Dropdown to exclude "Village" and "Country" boundary types.
- Refactored handleHierarchyChange and handleBoundaryChange functions for better row handling.
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/configs/UICustomizations.js - Updated preProcess and additionalCustomizations methods to include role checks and improved data handling.
- Enhanced localization for several keys using t().
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/hooks/services/searchSavedPlansWithCampaign.js - Removed employeeId from request payload.
- Added name to the response body for responsePlan API call.
- Maintained error handling logic.

Possibly related PRs

  • Vertical stepper implemenetation #1441: The changes in the RoleTableComposer component may relate to the role-based access control introduced in the main PR, as both involve handling user roles and permissions.
  • User download changes #1568: The updates to the UICustomizations.js file, particularly regarding the UserManagementConfig, align with the role-based access control and validation logic changes in the main PR.
  • added new hook for microplans search screen #1587: The modifications in MyMicroplanSearchConfig regarding status mapping and action handling are relevant to the changes in the main PR that enhance search functionalities and user interactions.
  • Microplansearch changes #1629: The updates to the MicroplanSearchConfig and MyMicroplanSearchConfig configurations in this PR reflect similar enhancements in data handling and user interface customization as seen in the main PR.
  • Summary-screen changes and localization #1672: The changes in the summary screen and localization improvements may relate to the overall enhancements in user experience and interface consistency introduced in the main PR.

Suggested reviewers

  • nipunarora-eGov

Poem

🐰 In the garden of code, changes bloom bright,
New buttons and roles, a wonderful sight.
With validation and searches, we hop with delight,
Localization sings, making everything right.
So let’s celebrate, with a joyful cheer,
For each little change brings us all near! 🌼


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.

@abishekTa-egov abishekTa-egov changed the title Abi 25 10 MIcroplan-search and user-access roles changes Oct 26, 2024
@abishekTa-egov abishekTa-egov changed the title MIcroplan-search and user-access roles changes MyMicroplan search change and user-access roles changes Oct 26, 2024
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: 7

🧹 Outside diff range comments (3)
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/hooks/services/searchSavedPlansWithCampaign.js (1)

Line range hint 22-91: Consider enhancing error handling and documentation

The function handles complex operations across multiple APIs but could benefit from the following improvements:

  1. Add JSDoc documentation specifying the expected shape of the body parameter
  2. Provide more specific error messages for different failure scenarios (API failures, validation errors, etc.)
  3. Consider using a try-catch block for the nested API calls

Example documentation:

/**
 * Searches for saved plans and merges them with campaign details
 * @param {Object} body - The search criteria
 * @param {Object} body.PlanConfigurationSearchCriteria - Plan search parameters
 * @param {string} body.PlanConfigurationSearchCriteria.name - Name to search for
 * @param {string} body.PlanConfigurationSearchCriteria.status - Status filter
 * @returns {Promise<{PlanConfiguration: Array}>} Merged plan and campaign details
 * @throws {Error} When API calls fail or validation errors occur
 */
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/RoleTableComposer.js (2)

Line range hint 346-355: Add error handling and loading state to the Dropdown

The Dropdown implementation could be more robust with the following improvements:

  1. Add null checking for state?.boundaryHierarchy
  2. Include a loading state while hierarchy data is being fetched

Consider updating the implementation:

 <Dropdown
   className="roleTableCell"
   selected={rowData?.find((item) => item?.rowIndex === row?.rowIndex)?.selectedHierarchy || null}
   disabled={nationalRoles?.includes(category) ? true : false}
   isMandatory={true}
-  option={state?.boundaryHierarchy.filter((item) => !(item.boundaryType === "Village" || item.boundaryType==="Country"))}
+  option={state?.boundaryHierarchy?.filter((item) => !(item.boundaryType === "Village" || item.boundaryType==="Country")) || []}
+  isLoading={!state?.boundaryHierarchy}
   select={(value) => {
     row.selectedHeirarchy = value;
     handleHierarchyChange(value, row);
   }}
   optionKey="boundaryType"
   t={t}
 />
🧰 Tools
🪛 Biome

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


Line range hint 1-607: Consider architectural improvements for better performance and maintainability

The component could benefit from several architectural improvements:

  1. Debounce the search form submission to prevent excessive API calls
  2. Memoize row handlers to optimize re-renders
  3. Consider extracting the toast management into a custom hook

Here's an example implementation of these improvements:

// Create a custom hook for toast management
const useToast = () => {
  const [toast, setToast] = useState(null);
  
  const showToast = useCallback((message) => {
    setToast(message);
    setTimeout(() => setToast(null), 1000);
  }, []);
  
  return [toast, showToast];
};

// Memoize row handlers
const handleAssignEmployee = useCallback((row) => {
  // existing implementation
}, [/* dependencies */]);

// Debounce search
const debouncedSearch = useMemo(
  () => debounce((searchParams) => {
    setFilters(searchParams);
  }, 300),
  []
);

Additionally, consider splitting the component into smaller, more focused components:

  • SearchForm
  • EmployeeTable
  • RoleAssignment

This would improve maintainability and make the code easier to test.

🧰 Tools
🪛 Biome

[error] 346-346: 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 9e0708d and 5c657b0.

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

Pattern **/*.js: check

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

Pattern **/*.js: check

🔇 Additional comments (5)
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/hooks/services/searchSavedPlansWithCampaign.js (1)

38-38: Security Concern: Verify the removal of employee-based filtering

The removal of the employeeId filter means that the API will return all plans regardless of employee assignment. This could potentially expose plans to unauthorized users.

✅ Verification successful

Removal of employeeId filter is intentional and safe

The removal of employeeId filter in searchSavedPlansWithCampaign.js is safe because:

  • This specific endpoint is used only for searching saved plans with campaign details
  • The codebase shows proper employee-based filtering in all other critical endpoints:
    • FacilityCatchmentMapping.js
    • PopInbox.js
    • PlanInbox.js
    • viewVillage.js
  • The filterUniqueByPlanConfig: true parameter ensures deduplication at plan configuration level
  • The search is still scoped by tenantId which provides tenant-level isolation
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if there are any other access controls in place
echo "Checking for alternative access controls..."
rg -A 5 "PlanEmployeeAssignmentSearchCriteria" 
rg -A 5 "employeeId.*uuid" 

# Check if this is handled at the API level
echo "Checking API endpoints for access controls..."
rg -A 10 "/plan-service/employee/_search"

Length of output: 19595

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

135-135: LGTM: Proper translation handling implemented

The translation implementation for microplan name is consistent with the application's localization approach.


227-231: LGTM: Proper role-based access control implemented

The implementation correctly checks for required roles using session storage and applies appropriate access restrictions.

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

348-348: LGTM: Boundary type filtering implemented correctly

The filtering logic correctly excludes both "Village" and "Country" boundary types from the hierarchy dropdown options, which aligns with the requirement to hide country information for non-national roles.

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

922-922: ⚠️ Potential issue

Potential Duplicate Assignment of name Property

At line 922, data.body.PlanConfigurationSearchCriteria.name is being reassigned to data?.state?.searchForm?.microplanName after previously assigning it to name. This may unintentionally overwrite the initial value. Please verify if both assignments are necessary and ensure the correct value is being used.

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