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

localizations for user management and user tag #1950

Merged
merged 2 commits into from
Dec 2, 2024
Merged

Conversation

abishekTa-egov
Copy link

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

localizations for user management and user tag

Summary by CodeRabbit

  • New Features

    • Enhanced user role display with updated key in user management.
    • Improved search functionality with additional criteria and pagination handling.
    • New validation checks for mobile numbers in user management.
  • Bug Fixes

    • Resolved issues with undefined values in rendering logic for various fields.
  • Documentation

    • Updated button labels for clarity in user interface actions.
  • Refactor

    • Enhanced mapping logic for statuses based on selected tabs in search configurations.

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

coderabbitai bot commented Dec 2, 2024

📝 Walkthrough

Walkthrough

The changes in this pull request involve significant modifications to the UICustomizations object and related components in the micro UI framework. Key updates include changing the key for user roles in UserManagementConfig, enhancing search configurations with new preprocessing methods, and refining button labels in the RoleTableComposer. Additionally, the configurations now include improved validation checks and more detailed rendering logic for various fields. These adjustments aim to enhance data handling and user interface clarity across several components.

Changes

File Path Change Summary
health/micro-ui/web/micro-ui-internals/example/src/UICustomizations.js Updated UserManagementConfig key from "Role" to "MP_USER_MANAGEMENT_ROLE"; enhanced SearchCampaign with new preProcess method; refined MicroplanSearchConfig and MyMicroplanSearchConfig with additional search criteria.
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/RoleTableComposer.js Updated button labels from t("Clear") to t("MP_USER_TAG_CLEAR") and t("Search") to t("MP_USER_TAG_SEARCH").
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/configs/UICustomizations.js Updated UserManagementConfig key; refined preProcess functions in search configs; added validation for mobile numbers.
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/configs/UserManagementConfig.js Renamed labels in searchResult and filter sections to include module-specific prefixes.

Possibly related PRs

Suggested reviewers

  • nipunarora-eGov

🐰 In the land of code so bright,
Changes made to bring delight.
Roles now clear, labels refined,
A user-friendly path we find.
With every tweak, the UI sings,
Enhancing joy that coding brings! 🌟


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

Line range hint 72-146: Consider refactoring repeated localization patterns

The switch cases for handling localizations follow similar patterns that could be refactored into a reusable helper function to reduce code duplication.

Consider creating a helper function like this:

const renderLocalizedField = (value, prefix = "", options = {}) => {
  if (value && value !== "NA") {
    return (
      <div style={options.style}>
        <p>{t(prefix ? Digit.Utils.locale.getTransformedLocale(prefix + value) : value)}</p>
      </div>
    );
  }
  return <div><p>{t("NA")}</p></div>;
};

Then use it in the switch cases:

case "CAMPAIGN_DISEASE":
  return renderLocalizedField(value, "MICROPLAN_DISEASE_");
case "CAMPAIGN_TYPE":
  return renderLocalizedField(value, "MICROPLAN_TYPE_");

Line range hint 297-374: Standardize "NA" text keys across the file

There's inconsistent usage of NA text keys ("NA" vs "ES_COMMON_NA"). This should be standardized for better maintainability.

Standardize to use "ES_COMMON_NA" consistently:

-<p>{t("NA")}</p>
+<p>{t("ES_COMMON_NA")}</p>

Extract common styles to a constant

The text wrapping styles are duplicated across multiple cases.

Consider extracting the common styles:

const TEXT_WRAP_STYLES = {
  maxWidth: "15rem",
  wordWrap: "break-word",
  whiteSpace: "normal",
  overflowWrap: "break-word"
};

// Then use it in the render methods:
<div style={TEXT_WRAP_STYLES}>

Line range hint 392-408: Consider extracting validation regex to constants

The mobile number validation regex should be extracted to a named constant for better maintainability and reusability.

+const MOBILE_NUMBER_REGEX = /^[0-9]{10}$/;

 customValidationCheck: (data) => {
   const { phone } = data;
-  const mobileRegex = /^[0-9]{10}$/;

   if (!phone || phone.trim() === "") {
     return false;
   }

-  if (!mobileRegex.test(phone)) {
+  if (!MOBILE_NUMBER_REGEX.test(phone)) {
     return { error: true, label: "INVALID_MOBILE_NUMBER" };
   }

   return false;
 }

Line range hint 589-604: Remove commented debug code

There's a commented line for debugging popup functionality that should be removed.

-// removed this because due to popup crashing on dev
-// onClick={() => console.log("temp action")}
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/RoleTableComposer.js (1)

Line range hint 1-644: Consider performance optimizations.

The component could benefit from several performance optimizations:

  1. Memoize callback functions using useCallback
  2. Memoize derived state using useMemo
  3. Debounce search input changes

Example optimizations:

// Memoize callbacks
const handleSearchSubmit = useCallback((e) => {
  if (number?.length > 0 && number?.length !== 10) {
    setShowToast({ key: "error", label: t("INVALID_MOBILE_NUMBER_LENGTH") });
    return;
  }
  setCurrentPage(1);
  setFilters({
    name: name,
    number: number,
  });
}, [number, name]);

// Memoize derived state
const columns = useMemo(() => [
  // ... column definitions
], [t]); // Only re-create when translations change

// Debounce search input
const debouncedSetName = useCallback(
  debounce((value) => setName(value), 300),
  []
);
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/configs/UserManagementConfig.js (1)

Line range hint 1-179: Consider localizing remaining static strings.

Several strings in the configuration are still using static text instead of localization keys:

  • Search fields: "NAME", "CONTACT_NUMBER"
  • Filter section: "ROLES"
  • Button labels: "Search"

Consider updating these to follow the same localization pattern for consistency across the application.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between 7aef8f2 and 8eedb56.

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

Pattern **/*.js: check

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

Pattern **/*.js: check

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

Pattern **/*.js: check

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

Line range hint 531-544: Role localization implementation looks good

The implementation correctly uses the "MP_ROLE_" prefix for localizing role codes, which aligns with the PR objectives.

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

Line range hint 1248-1256: Ensure consistent use of the updated key 'MP_USER_MANAGEMENT_ROLE'

Please verify that all references to the key "Role" have been updated to "MP_USER_MANAGEMENT_ROLE" throughout the codebase to maintain consistency and prevent potential issues.

Run the following script to identify any remaining occurrences of the key "Role":

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

85-100: LGTM! Verify localization keys exist in translation files.

The column labels have been properly updated with consistent 'MP_USER_MANAGEMENT_' prefixes, which aligns with localization best practices.

Let's verify these localization keys exist in the translation files:

@nipunarora-eGov nipunarora-eGov merged commit 652a965 into console Dec 2, 2024
3 checks passed
@nipunarora-eGov nipunarora-eGov deleted the abi-2-12 branch December 2, 2024 05:52
@coderabbitai coderabbitai bot mentioned this pull request Dec 3, 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