Skip to content

Feature/hcmpre 2588 #2314

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 2 commits into
base: console
Choose a base branch
from
Open

Feature/hcmpre 2588 #2314

wants to merge 2 commits into from

Conversation

Bhavya-egov
Copy link
Contributor

@Bhavya-egov Bhavya-egov commented Apr 8, 2025

Summary by CodeRabbit

  • New Features

    • Enhanced localization filtering in checklists ensures only valid entries are displayed, improving clarity and consistency.
    • Improved popup interactivity allows users to easily close dialogs, streamlining navigation.
  • Refactor

    • Optimized component performance using memoization and caching, reducing unnecessary re-renders.
    • Refined formatting and data filtering for a cleaner, more responsive interface.

@Bhavya-egov Bhavya-egov requested a review from a team as a code owner April 8, 2025 13:09
Copy link
Contributor

coderabbitai bot commented Apr 8, 2025

📝 Walkthrough

Walkthrough

This pull request updates several components within the campaign-manager module. In the localization editor, formatting changes and filtering enhancements ensure that empty or whitespace-only messages are removed. Both checklist pages now include new functions and constants to filter locale entries and manage localization data—one even triggering a data refetch post-update. The deliveryRule components have been refactored: functional components are now memoized for performance, and asynchronous API calls replace prior hook-based data fetching. Additionally, the cycleData computation is now memoized with caching adjustments.

Changes

File(s) Change Summary
.../components/LocalisationEditorPopup.js Reformatted function signature and updated props; enhanced the DataTable's data prop to filter out rows with empty or whitespace-only messages.
.../pages/employee/CreateChecklist.js,
.../pages/employee/UpdateChecklist.js
Added new constants (presentLocale, module) and functions (getFilteredLocaleEntries; additionally freshMessage in UpdateChecklist); updated onSubmit logic to filter out empty localization entries and, in UpdateChecklist, to trigger a refetch; updated component props to consistently use the active locale.
.../pages/employee/deliveryRule/AddDeliverycontext.js Converted several functional components to memoized versions using React.memo; replaced MDMS hook-based fetching with an asynchronous API call (fetchStructureConfig); updated useEffect dependencies.
.../pages/employee/deliveryRule/index.js Replaced state-based management of cycleData with a memoized value using useMemo; changed caching parameters (staleTime and cacheTime) in the MDMS hook to Infinity with prior state logic commented out.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Checklist
    participant LocalizationFilter as getFilteredLocaleEntries
    participant LocalizationEditor as LocalisationEditorPopup
    participant API

    User->>Checklist: Submit checklist data
    Checklist->>LocalizationFilter: Filter locale entries
    LocalizationFilter-->>Checklist: Return filtered entries
    Checklist->>LocalizationEditor: Update with new locale data
    alt For Update Checklist Flow
        Checklist->>API: Trigger refetch() after update
        API-->>Checklist: Provide updated localization data
    end
    Checklist->>User: Confirm submission
Loading

Possibly related PRs

Suggested reviewers

  • jagankumar-egov
  • nipunarora-eGov

Poem

I’m a little rabbit, hopping through the code,
Trimming empty messages down a narrow road.
Memoized magic for a faster sprint,
Localization refined—every detail’s a hint.
With async leaps and refetch delight,
I celebrate these changes in the soft moonlight.
Happy coding, from my burrow so bright!

✨ 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
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: 6

🔭 Outside diff range comments (2)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/deliveryRule/AddDeliverycontext.js (2)

36-328: 🛠️ Refactor suggestion

Optimized component with React.memo, but needs error handling for API calls.

The component has been effectively memoized to prevent unnecessary re-renders, and the data fetching approach has been changed from hook-based to direct API calls. However, there's no error handling for the API request.

Add error handling to the fetchStructureConfig function and the associated fetchData function to handle API failures gracefully:

const fetchStructureConfig = async (schemaCode) => {
+  try {
    const data = await Digit.CustomService.getResponse({
      url: `/egov-mdms-service/v1/_search`,
      body: {
        MdmsCriteria: {
          tenantId: tenantId,
          "moduleDetails": [
            {
              "moduleName": schemaCode?.split(".")?.[0],
              "masterDetails": [
                {
                  "name": schemaCode?.split(".")?.[1]
                }
              ]
            }
          ]
        },
      },
    });
    const moduleName = schemaCode?.split(".")?.[0];
    const schemaName = schemaCode?.split(".")?.[1];
    return data?.MdmsRes?.[moduleName]?.[schemaName];
+  } catch (error) {
+    console.error("Error fetching structure config:", error);
+    return [];
+  }
}

useEffect(() => {
  if (schemaCode) {
    const fetchData = async () => {
+      try {
        const fetch = await fetchStructureConfig(schemaCode);
        if (fetch?.length > 0) {
          setDropdownOption(fetch);
        } else setDropdownOption([]);
+      } catch (error) {
+        console.error("Error in fetchData:", error);
+        setDropdownOption([]);
+      }
    };
    
    fetchData();
  }
}, [schemaCode, tenantId]);
🧰 Tools
🪛 Biome (1.9.4)

[error] 221-221: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 222-222: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


650-652: 🧹 Nitpick (assertive)

Consider memoizing this calculated value.

The selectedStructureCodes calculation is potentially expensive as it's flattening nested arrays and could be recalculated unnecessarily on each render.

Use useMemo to cache this calculation:

-  const selectedStructureCodes = campaignData?.flatMap((cycle) =>
-    cycle?.deliveries?.flatMap((delivery) => delivery?.deliveryRules?.flatMap((rule) => rule?.attributes.map((attribute) => attribute?.value)))
-  );
+  const selectedStructureCodes = useMemo(() => {
+    return campaignData?.flatMap((cycle) =>
+      cycle?.deliveries?.flatMap((delivery) => 
+        delivery?.deliveryRules?.flatMap((rule) => 
+          rule?.attributes.map((attribute) => attribute?.value)
+        )
+      )
+    );
+  }, [campaignData]);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d90dac4 and 21b3a2e.

⛔ Files ignored due to path filters (6)
  • health/micro-ui/web/console/package.json is excluded by !**/*.json
  • health/micro-ui/web/core/package.json is excluded by !**/*.json
  • health/micro-ui/web/micro-ui-internals/example/package.json is excluded by !**/*.json
  • health/micro-ui/web/microplan/package.json is excluded by !**/*.json
  • health/micro-ui/web/package.json is excluded by !**/*.json
  • health/micro-ui/web/workbench/package.json is excluded by !**/*.json
📒 Files selected for processing (5)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/LocalisationEditorPopup.js (2 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/CreateChecklist.js (6 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/UpdateChecklist.js (8 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/deliveryRule/AddDeliverycontext.js (6 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/deliveryRule/index.js (4 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.js`: check

**/*.js: check

  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/deliveryRule/index.js
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/LocalisationEditorPopup.js
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/CreateChecklist.js
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/UpdateChecklist.js
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/deliveryRule/AddDeliverycontext.js
🧬 Code Definitions (4)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/deliveryRule/index.js (8)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/CreateChecklist.js (1)
  • config (39-39)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/UpdateChecklist.js (1)
  • config (26-26)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/ViewChecklist.js (1)
  • config (25-25)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/SetupCampaign.js (1)
  • config (944-944)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/BoundaryHome.js (1)
  • config (7-9)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/UpdateCampaign.js (1)
  • config (796-796)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/MyCampaign.js (1)
  • config (18-18)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/ConfigureApp.js (1)
  • config (89-89)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/CreateChecklist.js (3)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/UpdateChecklist.js (4)
  • presentLocale (33-33)
  • Digit (34-34)
  • Digit (98-98)
  • currentLocales (49-49)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/ViewChecklist.js (1)
  • Digit (61-61)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/LocalisationEditorPopup.js (1)
  • LocalisationEditorPopup (7-93)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/UpdateChecklist.js (1)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/CreateChecklist.js (3)
  • module (36-36)
  • presentLocale (56-56)
  • Digit (44-44)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/deliveryRule/AddDeliverycontext.js (26)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/deliveryRule/index.js (1)
  • tenantId (25-25)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/Module.js (2)
  • tenantId (70-70)
  • moduleName (71-71)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/SetupCampaign.js (2)
  • tenantId (30-30)
  • Digit (42-42)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/AddProductField.js (1)
  • tenantId (11-11)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/BulkUpload.js (1)
  • tenantId (26-26)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/CampaignSummary.js (3)
  • tenantId (153-153)
  • data (44-44)
  • Digit (369-671)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/TimelineComponent.js (1)
  • tenantId (36-36)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/deliveryRule/AddProductscontext.js (2)
  • tenantId (21-21)
  • data (40-40)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/UploadData.js (1)
  • tenantId (22-22)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/configs/UICustomizations.js (15)
  • tenantId (91-91)
  • tenantId (172-172)
  • tenantId (233-233)
  • tenantId (366-366)
  • tenantId (396-396)
  • data (368-368)
  • data (369-369)
  • data (552-552)
  • data (553-553)
  • data (687-687)
  • data (688-688)
  • data (874-874)
  • data (875-875)
  • data (968-968)
  • data (969-969)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/UpdateDatesWithBoundaries.js (1)
  • tenantId (14-14)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/DeliveryDetailsSummary.js (2)
  • data (41-41)
  • Digit (227-302)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/CycleConfiguration.js (1)
  • data (10-32)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/utils/setupCampaignValidators.js (1)
  • data (5-5)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/CreateChecklist.js (1)
  • Digit (44-44)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/UpdateChecklist.js (2)
  • Digit (34-34)
  • Digit (98-98)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/ViewChecklist.js (1)
  • Digit (61-61)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/fetchFromMicroplan.js (1)
  • Digit (31-31)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/UploadDataMapping.js (1)
  • Digit (471-481)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/BoundarySummary.js (1)
  • Digit (62-104)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/CampaignDetailsSummary.js (1)
  • Digit (54-106)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/CampaignUpdateSummary.js (1)
  • Digit (185-366)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/DataUploadSummary.js (1)
  • Digit (148-247)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/BoundaryHome.js (1)
  • Digit (53-53)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/BoundaryRelationCreate.js (1)
  • Digit (41-46)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/DSSCard.js (1)
  • moduleName (28-28)
🪛 Biome (1.9.4)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/deliveryRule/index.js

[error] 33-33: Use Number.POSITIVE_INFINITY instead of the equivalent global.

ES2015 moved some globals into the Number namespace for consistency.
Safe fix: Use Number.POSITIVE_INFINITY instead.

(lint/style/useNumberNamespace)


[error] 34-34: Use Number.POSITIVE_INFINITY instead of the equivalent global.

ES2015 moved some globals into the Number namespace for consistency.
Safe fix: Use Number.POSITIVE_INFINITY instead.

(lint/style/useNumberNamespace)

health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/LocalisationEditorPopup.js

[error] 50-50: JSX elements without children should be marked as self-closing. In JSX, it is valid for any element to be self-closing.

Unsafe fix: Use a SelfClosingElement instead

(lint/style/useSelfClosingElements)

health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/deliveryRule/AddDeliverycontext.js

[error] 610-610: Unexpected empty object pattern.

(lint/correctness/noEmptyPattern)

🔇 Additional comments (22)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/LocalisationEditorPopup.js (5)

7-7: Improved function signature readability

The function signature has been reformatted with proper spacing after commas for better readability and consistency.


27-33: Enhanced readability of conditional expression

The conditional expression in the TextInput's value prop has been reformatted for better readability while maintaining the same logic. This makes the nested conditional easier to understand.


41-42: Consistent component formatting

The TextInput closing tag is now on a separate line, improving readability and maintaining consistent formatting style.


53-57: Simplified Tab configuration

The Tab component implementation has been simplified by using a no-op function for onTabClick which is appropriate since the actual tab handling is done through setActiveLink.


62-69: Filtering out empty messages in DataTable

The DataTable now filters out rows where the message property is empty or consists solely of whitespace. This is a good improvement that prevents displaying empty entries to users.

health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/deliveryRule/index.js (3)

1-1: Added useMemo import for performance optimization

The import of useMemo is a good addition, as it will be used to optimize performance by memoizing computed values.


18-21: Replaced useState with useMemo for cycleData

The component now uses useMemo to compute cycleData instead of storing it in state. This is a good performance optimization that prevents unnecessary re-renders when the dependency remains the same.


44-46: Removed redundant useEffect for cycleData

The useEffect hook that was previously setting the cycleData state has been commented out, which is appropriate since the component now uses useMemo instead. This eliminates redundant state updates.

health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/CreateChecklist.js (6)

56-57: Added presentLocale for consistent locale reference

The new presentLocale constant retrieves the current locale from session storage, ensuring that the current locale is consistently referenced throughout the component.


242-242: Improved default message handling for empty help text

The default message for help text is now an empty string instead of a period when no help text is provided, which is a more appropriate default value.


359-395: New function to filter locale entries based on active questions

The getFilteredLocaleEntries function is a well-implemented utility that filters locale entries based on active question titles, options, help texts, and sub-question titles. This function helps maintain cleaner localization data by focusing only on active elements.


525-525: Filter out empty translations

The localizations array is now filtered to exclude entries with empty messages, which prevents storing unnecessary data and aligns with the filtering in the LocalisationEditorPopup component.


650-652: Improved localization data processing

The code now uses the new getFilteredLocaleEntries function to process localization data before setting it, ensuring that only relevant entries are included in the popup.


741-743: Updated LocalisationEditorPopup props to use presentLocale

The props for the LocalisationEditorPopup component now use presentLocale consistently, and filter languages and locales to exclude the current locale, providing a better user experience by focusing on translations that need to be added.

health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/UpdateChecklist.js (8)

13-13: Added module constant for consistent reference

The addition of a module constant set to "hcm-checklist" ensures consistent reference throughout the component, reducing the risk of typos or inconsistencies.


33-33: Added presentLocale for consistent locale reference

The new presentLocale constant retrieves the current locale from session storage, ensuring that the current locale is consistently referenced throughout the component.


160-160: Added refetch capability to useSearchLocalisation hook

The useSearchLocalisation hook now includes a refetch method, which enables refreshing the data when needed, particularly after successful updates.


330-367: New function to filter locale entries based on active questions

The getFilteredLocaleEntries function is a well-implemented utility that filters locale entries based on active question titles, options, help texts, and sub-question titles. This mirrors the same function in CreateChecklist.js, maintaining consistency across components.


369-385: Added utility function to compare localization data states

The freshMessage function effectively compares current localization data with enriched data to update the localization state appropriately, ensuring that only relevant entries are included.


636-638: Enhanced localization data processing

The code now uses the new functions to process and filter localization data before displaying it in the popup, ensuring a cleaner and more focused user experience.


540-540: Added data refetch after successful update

The code now calls refetch() after a successful checklist update, ensuring that the latest localization data is fetched and the UI stays in sync with the backend.


703-703: Added onOverlayClick handler for improved UX

The PopUp component now includes an onOverlayClick handler that closes the localization popup when clicking outside of it, providing a more intuitive user experience.

),
width: "55%",
},
];


return (
<div style={{ minWidth: "min-content" }}>
<div style={{ display: "flex", justifyContent: "space-between", marginBottom: "1rem" }}></div>
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Use self-closing JSX elements for elements without children

The current implementation has an empty div with opening and closing tags.

-<div style={{ display: "flex", justifyContent: "space-between", marginBottom: "1rem" }}></div>
+<div style={{ display: "flex", justifyContent: "space-between", marginBottom: "1rem" }} />
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<div style={{ display: "flex", justifyContent: "space-between", marginBottom: "1rem" }}></div>
<div style={{ display: "flex", justifyContent: "space-between", marginBottom: "1rem" }} />
🧰 Tools
🪛 Biome (1.9.4)

[error] 50-50: JSX elements without children should be marked as self-closing. In JSX, it is valid for any element to be self-closing.

Unsafe fix: Use a SelfClosingElement instead

(lint/style/useSelfClosingElements)

Comment on lines +33 to +34
staleTime: Infinity,
cacheTime: Infinity,
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Set staleTime and cacheTime to Infinity

The staleTime and cacheTime are now set to Infinity instead of 0, which prevents the data from being considered stale and from expiring from the cache. This is appropriate for configuration data that doesn't change frequently.

According to static analysis, it's better to use Number.POSITIVE_INFINITY instead of the global Infinity. Apply this improvement:

-  staleTime: Infinity,
-  cacheTime: Infinity,
+  staleTime: Number.POSITIVE_INFINITY,
+  cacheTime: Number.POSITIVE_INFINITY,
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
staleTime: Infinity,
cacheTime: Infinity,
staleTime: Number.POSITIVE_INFINITY,
cacheTime: Number.POSITIVE_INFINITY,
🧰 Tools
🪛 Biome (1.9.4)

[error] 33-33: Use Number.POSITIVE_INFINITY instead of the equivalent global.

ES2015 moved some globals into the Number namespace for consistency.
Safe fix: Use Number.POSITIVE_INFINITY instead.

(lint/style/useNumberNamespace)


[error] 34-34: Use Number.POSITIVE_INFINITY instead of the equivalent global.

ES2015 moved some globals into the Number namespace for consistency.
Safe fix: Use Number.POSITIVE_INFINITY instead.

(lint/style/useNumberNamespace)

Comment on lines +83 to +131
// const { data: structureConfig } = Digit.Hooks.useCustomMDMS(
// tenantId,
// schemaCode?.split(".")?.[0] || "", // Provide a fallback to avoid errors
// schemaCode ? [{ name: schemaCode?.split(".")?.[1] }] : [], // Run only if schemaCode is defined
// {
// enabled: !!schemaCode, // Enable the hook only if schemaCode is defined
// select: (data) => {
// console.log("data" , data);
// if (!schemaCode) return null;
// const moduleName = schemaCode?.split(".")?.[0];
// const schemaName = schemaCode?.split(".")?.[1];
// return data?.[moduleName]?.[schemaName];
// },
// }, // Pass null if schemaCode is undefined
// schemaCode ? { schemaCode } : null // Include schemaCode only if it's defined
// );

const fetchStructureConfig = async (schemaCode) => {
const data = await Digit.CustomService.getResponse({
url: `/egov-mdms-service/v1/_search`,
body: {
MdmsCriteria: {
tenantId: tenantId,
// schemaCodes: [schemaCode],
"moduleDetails": [
{
"moduleName": schemaCode?.split(".")?.[0],
"masterDetails": [
{
"name": schemaCode?.split(".")?.[1]
}
]
}
]
},
},
});
const moduleName = schemaCode?.split(".")?.[0];
const schemaName = schemaCode?.split(".")?.[1];
return data?.MdmsRes?.[moduleName]?.[schemaName];
}

// useEffect(() => {
// if (showAttribute) {
// if (structureConfig?.length > 0) {
// setDropdownOption(structureConfig);
// } else setDropdownOption([]);
// }
// }, [showAttribute, structureConfig, attributeConfig]);
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Remove large blocks of commented code.

Maintaining large blocks of commented code makes the file harder to read and maintain. Since you've implemented a new approach to fetch the data, the old code should be removed.

Remove all commented out code blocks to improve readability:

-  // const { data: structureConfig } = Digit.Hooks.useCustomMDMS(
-  //   tenantId,
-  //   schemaCode?.split(".")?.[0] || "", // Provide a fallback to avoid errors
-  //   schemaCode ? [{ name: schemaCode?.split(".")?.[1] }] : [], // Run only if schemaCode is defined
-  //   {
-  //     enabled: !!schemaCode, // Enable the hook only if schemaCode is defined
-  //     select: (data) => {
-  //       console.log("data" , data);
-  //       if (!schemaCode) return null;
-  //       const moduleName = schemaCode?.split(".")?.[0];
-  //       const schemaName = schemaCode?.split(".")?.[1];
-  //       return data?.[moduleName]?.[schemaName];
-  //     },
-  //   }, // Pass null if schemaCode is undefined
-  //   schemaCode ? { schemaCode } : null // Include schemaCode only if it's defined
-  // );

// ... (keep the new fetchStructureConfig function)

-  // useEffect(() => {
-  //   if (showAttribute) {
-  //     if (structureConfig?.length > 0) {
-  //       setDropdownOption(structureConfig);
-  //     } else setDropdownOption([]);
-  //   }
-  // }, [showAttribute, structureConfig, attributeConfig]);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// const { data: structureConfig } = Digit.Hooks.useCustomMDMS(
// tenantId,
// schemaCode?.split(".")?.[0] || "", // Provide a fallback to avoid errors
// schemaCode ? [{ name: schemaCode?.split(".")?.[1] }] : [], // Run only if schemaCode is defined
// {
// enabled: !!schemaCode, // Enable the hook only if schemaCode is defined
// select: (data) => {
// console.log("data" , data);
// if (!schemaCode) return null;
// const moduleName = schemaCode?.split(".")?.[0];
// const schemaName = schemaCode?.split(".")?.[1];
// return data?.[moduleName]?.[schemaName];
// },
// }, // Pass null if schemaCode is undefined
// schemaCode ? { schemaCode } : null // Include schemaCode only if it's defined
// );
const fetchStructureConfig = async (schemaCode) => {
const data = await Digit.CustomService.getResponse({
url: `/egov-mdms-service/v1/_search`,
body: {
MdmsCriteria: {
tenantId: tenantId,
// schemaCodes: [schemaCode],
"moduleDetails": [
{
"moduleName": schemaCode?.split(".")?.[0],
"masterDetails": [
{
"name": schemaCode?.split(".")?.[1]
}
]
}
]
},
},
});
const moduleName = schemaCode?.split(".")?.[0];
const schemaName = schemaCode?.split(".")?.[1];
return data?.MdmsRes?.[moduleName]?.[schemaName];
}
// useEffect(() => {
// if (showAttribute) {
// if (structureConfig?.length > 0) {
// setDropdownOption(structureConfig);
// } else setDropdownOption([]);
// }
// }, [showAttribute, structureConfig, attributeConfig]);
const fetchStructureConfig = async (schemaCode) => {
const data = await Digit.CustomService.getResponse({
url: `/egov-mdms-service/v1/_search`,
body: {
MdmsCriteria: {
tenantId: tenantId,
// schemaCodes: [schemaCode],
"moduleDetails": [
{
"moduleName": schemaCode?.split(".")?.[0],
"masterDetails": [
{
"name": schemaCode?.split(".")?.[1]
}
]
}
]
},
},
});
const moduleName = schemaCode?.split(".")?.[0];
const schemaName = schemaCode?.split(".")?.[1];
return data?.MdmsRes?.[moduleName]?.[schemaName];
}

Comment on lines +61 to 68
// const schemaCode = useMemo(() =>
// showAttribute?.valuesSchema, [showAttribute?.valuesSchema]);

const schemaCode = useMemo(() => {
const code = showAttribute?.valuesSchema;
// fetchStructureConfig(code);
return code;
}, [showAttribute]);
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Clean up commented code and optimize useMemo logic.

There are redundant commented sections and a potentially unnecessary useMemo implementation.

Remove commented code and simplify the useMemo implementation:

-  // const schemaCode = useMemo(() => 
-  //   showAttribute?.valuesSchema, [showAttribute?.valuesSchema]);

const schemaCode = useMemo(() => {
  const code = showAttribute?.valuesSchema;
-  // fetchStructureConfig(code);
  return code;
}, [showAttribute]);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// const schemaCode = useMemo(() =>
// showAttribute?.valuesSchema, [showAttribute?.valuesSchema]);
const schemaCode = useMemo(() => {
const code = showAttribute?.valuesSchema;
// fetchStructureConfig(code);
return code;
}, [showAttribute]);
const schemaCode = useMemo(() => {
const code = showAttribute?.valuesSchema;
return code;
}, [showAttribute]);

body: {
MdmsCriteria: {
tenantId: tenantId,
// schemaCodes: [schemaCode],
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Remove commented code that provides no value.

Commented code that serves no documentation purpose should be removed.

Remove this commented line:

          tenantId: tenantId,
-          // schemaCodes: [schemaCode],
          "moduleDetails": [
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// schemaCodes: [schemaCode],
tenantId: tenantId,
"moduleDetails": [


const AddDeliveryRuleWrapper = ({}) => {
const AddDeliveryRuleWrapper = React.memo(({}) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix the empty object pattern in React.memo component.

The AddDeliveryRuleWrapper component has an empty object pattern which is flagged by static analysis.

Fix the empty object pattern by removing the empty curly braces:

-const AddDeliveryRuleWrapper = React.memo(({}) => {
+const AddDeliveryRuleWrapper = React.memo(() => {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const AddDeliveryRuleWrapper = React.memo(({}) => {
const AddDeliveryRuleWrapper = React.memo(() => {
🧰 Tools
🪛 Biome (1.9.4)

[error] 610-610: Unexpected empty object pattern.

(lint/correctness/noEmptyPattern)

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.

1 participant