Skip to content

Libraries changes and cleanup (#245) #246

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

Open
wants to merge 1 commit into
base: develop-webpack
Choose a base branch
from

Conversation

jagankumar-egov
Copy link
Collaborator

  • SVG Components cleanup

  • ui-components cleanup

  • react-components changes

  • libraries cleanup and changes

* SVG Components cleanup

* ui-components cleanup

* react-components changes

* libraries cleanup and changes
Copy link
Contributor

coderabbitai bot commented Apr 11, 2025

Walkthrough

This update revises several library modules. The useStore hook now calls useQuery with an object parameter instead of positional arguments. In the main library initialization, a new service, StoreService, is imported and integrated while the previous hooks setup is disabled. Updates to the Localization and MDMS services include explicit window referencing and default parameter values respectively. The StoreService’s digitInitData method now provides a default state code and adds try-catch error handling. Additionally, a conditional callback check was added in the translations initialization.

Changes

File(s) Change Summary
webpack/libraries/src/hooks/store.js Updated useStore: changed useQuery invocation from positional arguments to an object format; commented out legacy options parameter.
webpack/libraries/src/index.js Added import for StoreService from ./services/molecules/Store/service; integrated via setupLibraries("StoreServiceLib", StoreService); commented out previous hooks setup.
webpack/libraries/src/services/elements/Localization/service.js Revised updateResources: replaced i18next.addResources with window.i18next.addResources.
webpack/libraries/src/services/elements/MDMS.js Modified signatures: added default parameters (tenantId="mz" in getCriteria and stateCode="mz" in init).
webpack/libraries/src/services/molecules/Store/service.js Updated digitInitData: added default stateCode="mz" and wrapped localization fetch in a try-catch block for error logging.
webpack/libraries/src/translations/index.js Added a conditional check before invoking the callback in initI18n.

Sequence Diagram(s)

sequenceDiagram
    participant SS as StoreService (digitInitData)
    participant LS as LocalizationService
    participant C as Console

    SS->>LS: getLocale()
    alt Successful retrieval
        LS-->>SS: locale data
    else Error encountered
        LS-->>SS: throw error
        SS->>C: log(error)
    end
Loading
sequenceDiagram
    participant I as initI18n
    participant i18n as i18next
    participant CB as Callback

    I->>i18n: initialize i18next
    i18n-->>I: initialization complete
    alt If callback exists
        I->>CB: invoke callback
    end
Loading

Poem

Hop, hop, I’m a rabbit so spry,
Crunching code carrots as updates fly.
Defaults and try-catch make my heart beat fast,
Each new line a leap into changes vast.
With ASCII hops and joyful glee,
I celebrate revisions—oh code, come dance with me! 🐇✨

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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
Collaborator Author

@jagankumar-egov jagankumar-egov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@purepiyush can u check them

@@ -89,7 +89,7 @@ export const StoreService = {
uiHomePage: uiHomePage,
};
},
digitInitData: async (stateCode, enabledModules, modulePrefix) => {
digitInitData: async (stateCode="mz", enabledModules, modulePrefix) => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we cant have hardcoded @purepiyush

@@ -1471,7 +1471,7 @@ const debouncedCall = ({ serviceName, url, data, useCache, params }, resolve, re
};

export const MdmsService = {
init: (stateCode) =>
init: (stateCode="mz") =>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here as well

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

🧹 Nitpick comments (4)
webpack/libraries/src/services/elements/Localization/service.js (1)

62-62: Consistent use of global i18next instance

Explicitly referencing window.i18next ensures that the globally initialized instance is used, which aligns with how it's set up in translations/index.js (line 58) and prevents potential conflicts with multiple i18next instances.

Note that line 88 in this same file still uses i18next.changeLanguage(locale) without the window. prefix. For consistency, consider updating that line too.

-    i18next.changeLanguage(locale);
+    window.i18next.changeLanguage(locale);
webpack/libraries/src/hooks/store.js (1)

7-13: Updated useQuery implementation to use object parameter style

The change from positional arguments to an object parameter style aligns with modern React Query API patterns, making the code more maintainable and self-documenting.

However, the commented-out empty object and inconsistent spacing in the code are unnecessary and could be cleaned up:

  return useQuery({
    queryKey : ['store', stateCode, moduleCode, language, modulePrefix], // queryKey
    queryFn : () => StoreService.defaultData(stateCode, moduleCode, language, modulePrefix), // query function
-    // {
-    //   // You can add other options here if needed, such as `enabled`, `staleTime`, etc.
-    // }
  }
webpack/libraries/src/index.js (2)

7-9: Unnecessary comment separators

The comment separators (// ---) don't add value and aren't standard practice. Consider removing them for cleaner code.

-// ---
 import { StoreService } from "./services/molecules/Store/service";
-// ---

88-90: Empty comments and StoreService integration

The empty comments (//) don't provide any value and should be removed. Additionally, ensure that the newly integrated StoreService is properly documented for other developers.

-  //
   setupLibraries("StoreServiceLib", StoreService);
-  //
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f1f22c4 and 39173ae.

⛔ Files ignored due to path filters (1)
  • webpack/libraries/package.json is excluded by !**/*.json
📒 Files selected for processing (6)
  • webpack/libraries/src/hooks/store.js (1 hunks)
  • webpack/libraries/src/index.js (2 hunks)
  • webpack/libraries/src/services/elements/Localization/service.js (1 hunks)
  • webpack/libraries/src/services/elements/MDMS.js (2 hunks)
  • webpack/libraries/src/services/molecules/Store/service.js (3 hunks)
  • webpack/libraries/src/translations/index.js (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
webpack/libraries/src/hooks/store.js (1)
webpack/libraries/src/services/molecules/Store/service.js (2)
  • StoreService (40-217)
  • StoreService (40-217)
webpack/libraries/src/services/elements/MDMS.js (7)
webpack/libraries/src/hooks/pgr/useComplaintStatusWithCount.js (1)
  • tenantId (7-7)
webpack/libraries/src/hooks/pgr/useComplaintStatus.js (1)
  • tenantId (7-7)
webpack/libraries/src/services/elements/Complaint.js (1)
  • tenantId (18-18)
webpack/libraries/src/services/elements/DSS.js (1)
  • tenantId (26-26)
webpack/libraries/src/services/molecules/Ulb/index.js (2)
  • tenantId (42-42)
  • tenantId (79-79)
webpack/libraries/src/services/elements/WorkFlow.js (1)
  • tenantId (22-22)
webpack/libraries/src/utils/index.js (1)
  • tenantId (195-195)
webpack/libraries/src/services/elements/Localization/service.js (2)
webpack/libraries/src/hooks/pgr/useComplaintDetails.js (1)
  • window (31-31)
webpack/libraries/src/utils/pdf.js (2)
  • locale (160-160)
  • locale (239-239)
🔇 Additional comments (6)
webpack/libraries/src/translations/index.js (1)

59-59: Good defensive programming practice added

Adding a conditional check before invoking the callback improves function robustness by preventing potential runtime errors when the callback isn't provided.

webpack/libraries/src/index.js (1)

97-97: Verify exports are consistent with changes

The Hooks module is still being exported even though its setup has been commented out. This could be misleading for consumers of this library. Consider removing Hooks from the exports or documenting that it's being phased out.

-export { initLibraries, Enums, Hooks, subFormRegistry ,Request};
+export { initLibraries, Enums, subFormRegistry, Request, StoreService };
webpack/libraries/src/services/molecules/Store/service.js (2)

92-92: Good addition of default state code.

Adding a default value for stateCode parameter improves robustness by ensuring the function works even when called without this parameter. The "mz" default is consistent with similar changes in other files.


180-188: Excellent error handling improvement.

Adding try-catch error handling around the LocalizationService call prevents the application from crashing if localization data fetching fails. This makes the initialization process more robust and improves user experience by allowing the application to continue running even if translations can't be loaded.

webpack/libraries/src/services/elements/MDMS.js (2)

67-67: Good addition of default tenant ID.

Adding a default value for the tenantId parameter improves code reliability and reduces potential errors when this function is called without the parameter. The "mz" default is consistent with other changes in the codebase.


1474-1474: Good addition of default state code to init method.

Adding a default value for the stateCode parameter in the MDMS init method is consistent with the other changes and provides a fallback value when the parameter is not provided. This maintains consistency throughout the codebase.

@@ -76,12 +79,15 @@ const initLibraries = () => {
setupLibraries("InboxGeneral", InboxGeneral);
setupLibraries("ShareFiles", ShareFiles);
setupLibraries("Contexts", Contexts);
setupLibraries("Hooks", Hooks);
// setupLibraries("Hooks", Hooks);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Hooks setup disabled

The Hooks setup has been commented out, which seems to be part of the architectural change moving to StoreService. Ensure that all functionality previously handled by Hooks is now properly handled by StoreService or document this change as a potential breaking change.

Recommended checks:

  1. Verify if any existing components are still trying to use functionality from the Hooks module
  2. Confirm that StoreService covers all relevant functionality

🏁 Script executed:

#!/bin/bash
# Find components that might be importing or using Hooks directly
rg "import.*Hooks.*from" --type js --type jsx --type ts --type tsx
rg "Digit\.Hooks\." --type js --type jsx --type ts --type tsx

Length of output: 188


I'll generate new shell scripts that explicitly add file types for JSX/TSX so we can verify if any components still import or reference the Hooks module. Please run the following scripts and share the output to confirm if any references remain:

Once you run these commands, please verify whether any output is returned. If no references are found, it likely indicates that the Hooks module is indeed no longer in use. If there are references, you'll need to ensure that either those components are updated to use StoreService or the change is documented properly as a potential breaking change.


🏁 Script executed:

#!/bin/bash
# Adding custom file types for jsx and tsx before searching for Hooks references.

# Search for imports of Hooks (works with .js, .jsx, .ts, .tsx files)
rg --type-add 'jsx:*.jsx' --type-add 'tsx:*.tsx' -e "import.*Hooks.*from" .

# Search for explicit usage of Digit.Hooks (works with .js, .jsx, .ts, .tsx files)
rg --type-add 'jsx:*.jsx' --type-add 'tsx:*.tsx' -e "Digit\.Hooks\." .

Length of output: 25779


Action: Address Incomplete Hooks Migration

The Hooks setup in webpack/libraries/src/index.js is now disabled (see the commented out code), but our repository search reveals that many components continue to import and actively use Digit.Hooks (e.g., useCustomAPIHook, useQueryParams, useCustomMDMS, etc.) across various modules. This indicates that the architectural migration to StoreService may be incomplete.

Please ensure one of the following:

  • Fully migrate Hooks functionality: Update all components using Digit.Hooks to use StoreService where applicable.
  • Document the change as a breaking change: Clearly document which Hooks functionalities are deprecated and how their absence is handled or should be manually addressed by downstream consumers.

Key Points:

  • The file webpack/libraries/src/index.js (Line 82) contains the disabled setup:
      // setupLibraries("Hooks", Hooks);
  • Numerous components in both the React and Webpack directories still reference Digit.Hooks.*.

Please review all Hooks usage to confirm coverage by StoreService and update or document accordingly.

@jagankumar-egov
Copy link
Collaborator Author

@purepiyush remove this logs

webpack/ui-components/src/hoc/FieldController.js

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