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 and Actions being cut #1874

Merged
merged 2 commits into from
Nov 21, 2024
Merged

Localizations and Actions being cut #1874

merged 2 commits into from
Nov 21, 2024

Conversation

abishekTa-egov
Copy link
Collaborator

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

Localizations and Actions being cut

Summary by CodeRabbit

  • New Features

    • Updated stylesheet for the health UI to version 0.1.39, enhancing visual elements.
    • Introduced new configurations for search and user management, improving search functionality and validation processes.
    • Enhanced FacilityPopup component with localization for village information and improved assignment logic.
  • Bug Fixes

    • Improved error handling and user feedback in the FacilityPopup component.
  • Style

    • Added CSS rules for better dropdown positioning in the UI.
  • Documentation

    • Updated translation methods for clarity and consistency in the MicroplanSearch component.

@abishekTa-egov abishekTa-egov requested a review from a team as a code owner November 21, 2024 13:56
Copy link
Contributor

coderabbitai bot commented Nov 21, 2024

📝 Walkthrough

Walkthrough

The changes in this pull request involve updates to various components of the health micro-UI. Notably, the stylesheet version in two HTML files has been updated from 0.1.38 to 0.1.39. Additionally, enhancements have been made to the UICustomizations object, including new configurations and improved logic for handling search parameters and validations. Modifications to the FacilityPopup component and CSS rules for dropdown elements have also been introduced, improving localization and layout control.

Changes

File Change Summary
health/micro-ui/web/micro-ui-internals/example/public/index.html Updated stylesheet link from version 0.1.38 to 0.1.39.
health/micro-ui/web/micro-ui-internals/packages/css/src/components/microplan.scss Added new CSS rule for tbody tr:last-child td:last-child .digit-dropdown-employee-select-wrap .digit-dropdown-options-card with position: relative;.
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/FacilityPopup.js Enhanced FacilityPopup with a new custom renderer for residingVillage, improved assignment logic, and refined state management.
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/configs/UICustomizations.js Introduced new methods and updated existing ones in UICustomizations, including logic for handling actions and validations.
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/MicroplanSearch.js Updated Header component to use translation function directly with a template string for search label rendering.
health/micro-ui/web/public/index.html Updated stylesheet link from version 0.1.38 to 0.1.39.

Possibly related PRs

Suggested reviewers

  • nipunarora-eGov

🐰 In the garden, changes bloom,
Styles updated, making room.
Configs enhanced, logic refined,
A better UI, all aligned.
With every hop, we celebrate,
Health micro-UI, looking great! 🌼


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 (11)
health/micro-ui/web/micro-ui-internals/example/public/index.html (1)

Line range hint 17-20: Clean up commented code

There are multiple commented-out CSS inclusions that appear to be outdated or unused. Consider removing these comments to improve code maintainability.

-  <!-- added below css for hcm-workbench module inclusion-->
-  <!-- <link rel="stylesheet" href="https://unpkg.com/@egovernments/[email protected]/dist/index.css" /> -->
-
-  <!-- <link rel="stylesheet" href="https://unpkg.com/@egovernments/digit-ui-css/dist/index.css"/> -->
health/micro-ui/web/public/index.html (1)

Let me analyze the results and generate a final response.

Remove the commented globalConfigs.js reference

The commented globalConfigs.js script appears in multiple index.html files across the codebase, all in the same commented state. Given that:

  1. The repository has numerous dedicated configuration files for different modules
  2. There's a robust configuration system in place (e.g., configUtils.js, mergeConfig.js)
  3. The S3-hosted configuration approach appears to be deprecated across all instances

This commented code should be removed as it represents technical debt and may cause confusion about the current configuration approach.

🔗 Analysis chain

Line range hint 18-18: Review the commented globalConfigs.js implementation

There's a commented reference to globalConfigs.js from S3. Consider:

  1. If this configuration is still needed, implement it properly
  2. If not needed, remove the commented code
  3. If needed but implemented differently, update the comment to explain why
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if globalConfigs.js is referenced elsewhere

# Search for other references to globalConfigs.js
echo "Checking for other references to globalConfigs.js"
rg "globalConfigs\.js"

# Check if there are alternative config implementations
echo "Checking for alternative config implementations"
fd -t f "config" | grep -i "config"

Length of output: 10375

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

Line range hint 1-46: Consider implementing defensive programming practices

The component could benefit from several robustness improvements:

  1. Add validation for the URL tab parameter
  2. Implement error boundaries
  3. Add null checks for TabSearchconfig access
  4. Consider adding loading states

Here's a suggested implementation:

 const MicroplanSearch = () => {
   const { t } = useTranslation();
   const [defaultValues, setDefaultValues] = useState(defaultSearchValues);
-  const [config, setConfig] = useState(TabSearchconfig?.TabSearchconfig?.[0]);
+  const [config, setConfig] = useState(() => {
+    if (!TabSearchconfig?.TabSearchconfig?.length) {
+      console.error('Invalid or empty TabSearchconfig');
+      return {};
+    }
+    return TabSearchconfig.TabSearchconfig[0];
+  });
   
   const [tabData, setTabData] = useState(
-    TabSearchconfig?.TabSearchconfig?.map((configItem, index) => ({
+    TabSearchconfig?.TabSearchconfig?.length ? TabSearchconfig.TabSearchconfig.map((configItem, index) => ({
       key: index,
       label: configItem.label,
       active: index === 0 ? true : false
-    }))
+    })) : []
   );

   const onTabChange = (n) => {
+    // Validate tab index
+    if (n < 0 || n >= (TabSearchconfig?.TabSearchconfig?.length || 0)) {
+      console.error('Invalid tab index:', n);
+      return;
+    }
     
     setTabData((prev) => prev.map((i, c) => ({ ...i, active: c === n ? true : false })));
     const url = new URL(window.location.href);
     url.searchParams.set("tabId", `${n}`);
     window.history.replaceState({}, "", url);
   };
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/configs/UICustomizations.js (2)

Line range hint 117-125: Refactor navigation to use React Router's history

It's recommended to use React Router's history object for navigation instead of directly manipulating window.location.href. This approach maintains SPA behavior and ensures proper history management within your React application.

To implement this, you can modify your code as follows:

First, obtain the history object using the useHistory hook:

import { useHistory } from "react-router-dom";

const history = useHistory();

Then, update your select function:

select={(e) => {
- if (e.name ==  "MP_ACTIONS_EDIT_SETUP") {
-   window.location.href = `/${window.contextPath}/employee/microplan/setup-microplan?key=${1}&microplanId=${row.id}&campaignId=${row.campaignDetails.id}`;
- }
- if (e.name == "MP_ACTIONS_VIEW_SUMMARY") {
-   window.location.href = `/${window.contextPath}/employee/microplan/setup-microplan?key=${10}&microplanId=${row.id}&campaignId=${row.campaignDetails.id}&setup-completed=true`;
- }
+ if (e.name === "MP_ACTIONS_EDIT_SETUP") {
+   history.push(`/${window.contextPath}/employee/microplan/setup-microplan?key=1&microplanId=${row.id}&campaignId=${row.campaignDetails.id}`);
+ }
+ if (e.name === "MP_ACTIONS_VIEW_SUMMARY") {
+   history.push(`/${window.contextPath}/employee/microplan/setup-microplan?key=10&microplanId=${row.id}&campaignId=${row.campaignDetails.id}&setup-completed=true`);
+ }
}}

This change leverages React Router's navigation capabilities and keeps the navigation consistent within your application's routing context.

Note: Ensure that useHistory is called within a functional component. If additionalCustomizations is not a component, you might need to pass the history object as a prop or adjust your code structure accordingly.


Line range hint 117-125: Ensure consistency between selected value and options

The selected prop in your Dropdown component is set to { code: "1", name: "MP_ACTIONS_FOR_MICROPLAN_SEARCH" }, which does not match any of the entries in your options array. This could lead to unexpected behavior or the dropdown displaying an incorrect default value.

Consider updating the selected prop to match one of the entries in the options array or adjust your options array to include the selected value. For example:

Option 1: Update the selected prop to match an option:

selected={
- { code: "1", name: "MP_ACTIONS_FOR_MICROPLAN_SEARCH" }
+ options[0]
}

Option 2: Include the selected value in your options array:

if (row?.status == "DRAFT") {
- options = [{ code: "1", name: "MP_ACTIONS_EDIT_SETUP" }];
+ options = [
+   { code: "1", name: "MP_ACTIONS_FOR_MICROPLAN_SEARCH" },
+   { code: "2", name: "MP_ACTIONS_EDIT_SETUP" }
+ ];
}

Ensure that the selected value corresponds to an option to prevent any inconsistencies in the dropdown's behavior.

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

Line range hint 834-844: Use Strict Equality Operators (===) Instead of Loose Equality Operators (==)

To prevent unintended type coercion, it's recommended to use strict equality operators (===) when comparing values in JavaScript.

Suggested changes:

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

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

Line range hint 542-544: Avoid Using React Hooks Inside Non-Component Functions

React hooks like useLocation and useParams should only be used within React function components or custom hooks, not inside regular functions.

To fix this, consider passing location and masterName as parameters to the preProcess function or refactoring the function into a custom hook.


Line range hint 878-882: Avoid Using React Hooks Inside Non-Component Functions

The Digit.Hooks.useQueryParams() hook is used inside a regular function preProcess. Hooks should only be called within React function components or custom hooks.

To resolve this, pass tabId as a parameter to the preProcess function or restructure the code to comply with React hooks rules.


Line range hint 890-908: Use React Router's useHistory Hook for Navigation

For consistent navigation handling in React applications, it's recommended to use the useHistory hook from react-router-dom instead of directly manipulating window.history.

Suggested refactor:

+ import { useHistory } from "react-router-dom";
+ const history = useHistory();

const onActionSelect = (key, row) => {
  switch (key) {
    case "START":
-     window.history.pushState(
-       {
-         microplanId: row?.id,
-         campaignId: row?.campaignId,
-       },
-       "",
-       `/${window.contextPath}/employee/microplan/select-activity?microplanId=${row?.id}&campaignId=${row?.campaignId}`
-     );
-     const navEvent = new PopStateEvent("popstate");
-     window.dispatchEvent(navEvent);
+     history.push(`/${window.contextPath}/employee/microplan/select-activity?microplanId=${row?.id}&campaignId=${row?.campaignId}`);
      break;
    case "EDIT":
      // Similar changes for the EDIT case
      break;
    case "DOWNLOAD":
      handleFileDownload();
      break;
    default:
      console.log(value);
      break;
  }
};

Line range hint 910-912: Ensure rolesCodes is Defined Before Mapping

There's a potential for rolesCodes to be undefined, which would cause a runtime error when calling map. It's important to handle this case to prevent crashes.

Suggested fix:

- const rolesCodes = Digit.Hooks.useSessionStorage("User", {})[0]?.info?.roles;
+ const rolesCodes = Digit.Hooks.useSessionStorage("User", {})[0]?.info?.roles || [];
const roles = rolesCodes.map((item) => item.code);

Line range hint 1305-1316: Avoid Using React Hooks Inside Non-Component Functions

The Digit.Hooks.useQueryParams() hook is used inside the getFacilitySearchRequest function, which is not a React component or custom hook. Hooks should only be used within React function components or custom hooks.

To fix this, pass campaignId as a parameter to the getFacilitySearchRequest function or refactor the function into a custom hook.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between a4f03f5 and 2f2126f.

⛔ Files ignored due to path filters (1)
  • health/micro-ui/web/micro-ui-internals/packages/css/package.json is excluded by !**/*.json
📒 Files selected for processing (7)
  • health/micro-ui/web/micro-ui-internals/example/public/index.html (1 hunks)
  • health/micro-ui/web/micro-ui-internals/example/src/UICustomizations.js (1 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/css/src/components/microplan.scss (1 hunks)
  • 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/configs/UICustomizations.js (1 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/MicroplanSearch.js (1 hunks)
  • health/micro-ui/web/public/index.html (1 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/FacilityPopup.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/pages/employee/MicroplanSearch.js (1)

Pattern **/*.js: check

🔇 Additional comments (3)
health/micro-ui/web/public/index.html (1)

13-13: Verify the CSS package version and potential breaking changes

The health CSS package version has been updated from 0.1.38 to 0.1.39. Let's ensure this is the latest stable version and check for any breaking changes.

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

36-36: Improved translation handling approach

The modification to wrap the entire template string in the translation function is a better approach. It allows for more natural translations where the word order might differ across languages.


Line range hint 4-4: Verify TabSearchconfig structure

Let's ensure the configuration file maintains the expected structure for proper component functionality.

✅ Verification successful

The search results provide clear evidence of the TabSearchconfig structure and its usage. Let me generate the final response:

TabSearchconfig structure is properly defined and used consistently

The configuration follows a well-defined structure across the codebase:

  • Defined in MicroplanSearchConfig.js with expected properties: showTab and TabSearchconfig array
  • Each tab config item contains required fields: label, type, and apiDetails
  • Used consistently in both MicroplanSearch.js and MyMicroplans.js with proper null checks
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check TabSearchconfig structure in the codebase

# Search for TabSearchconfig definition
ast-grep --pattern 'const TabSearchconfig = {
  TabSearchconfig: $_
}'

# Look for any other usage of this config
rg "TabSearchconfig" -A 5

Length of output: 8555

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