-
Notifications
You must be signed in to change notification settings - Fork 42
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
base: console
Are you sure you want to change the base?
Feature/hcmpre 2588 #2314
Conversation
📝 WalkthroughWalkthroughThis 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
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
Possibly related PRs
Suggested reviewers
Poem
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 suggestionOptimized 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 associatedfetchData
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
⛔ 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 readabilityThe function signature has been reformatted with proper spacing after commas for better readability and consistency.
27-33
: Enhanced readability of conditional expressionThe 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 formattingThe TextInput closing tag is now on a separate line, improving readability and maintaining consistent formatting style.
53-57
: Simplified Tab configurationThe Tab component implementation has been simplified by using a no-op function for
onTabClick
which is appropriate since the actual tab handling is done throughsetActiveLink
.
62-69
: Filtering out empty messages in DataTableThe 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 optimizationThe 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 cycleDataThe component now uses
useMemo
to computecycleData
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 cycleDataThe useEffect hook that was previously setting the
cycleData
state has been commented out, which is appropriate since the component now usesuseMemo
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 referenceThe 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 textThe 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 questionsThe
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 translationsThe 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 processingThe 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 presentLocaleThe 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 referenceThe 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 referenceThe 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 hookThe
useSearchLocalisation
hook now includes arefetch
method, which enables refreshing the data when needed, particularly after successful updates.
330-367
: New function to filter locale entries based on active questionsThe
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 statesThe
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 processingThe 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 updateThe 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 UXThe 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> |
There was a problem hiding this comment.
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.
<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)
staleTime: Infinity, | ||
cacheTime: Infinity, |
There was a problem hiding this comment.
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.
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)
// 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]); |
There was a problem hiding this comment.
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.
// 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]; | |
} |
// const schemaCode = useMemo(() => | ||
// showAttribute?.valuesSchema, [showAttribute?.valuesSchema]); | ||
|
||
const schemaCode = useMemo(() => { | ||
const code = showAttribute?.valuesSchema; | ||
// fetchStructureConfig(code); | ||
return code; | ||
}, [showAttribute]); |
There was a problem hiding this comment.
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.
// 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], |
There was a problem hiding this comment.
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.
// schemaCodes: [schemaCode], | |
tenantId: tenantId, | |
"moduleDetails": [ |
|
||
const AddDeliveryRuleWrapper = ({}) => { | ||
const AddDeliveryRuleWrapper = React.memo(({}) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
const AddDeliveryRuleWrapper = React.memo(({}) => { | |
const AddDeliveryRuleWrapper = React.memo(() => { |
🧰 Tools
🪛 Biome (1.9.4)
[error] 610-610: Unexpected empty object pattern.
(lint/correctness/noEmptyPattern)
Summary by CodeRabbit
New Features
Refactor