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

Feature/hcmpre 1903 #2183

Open
wants to merge 10 commits into
base: console
Choose a base branch
from
Open

Feature/hcmpre 1903 #2183

wants to merge 10 commits into from

Conversation

suryansh-egov
Copy link
Contributor

@suryansh-egov suryansh-egov commented Jan 31, 2025

Choose the appropriate template for your PR:

Feature PR

Feature Request

JIRA ID

Module

Description

Related Issues


Bugfix PR

Bugfix Request

JIRA ID

Module

Description

Root Cause

Related Issues


Release PR

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced campaign management with dynamic project type filtering based on employee hierarchy.
    • Added loading states to improve user experience during data fetching.
    • Introduced a new hook for managing employee hierarchy data.
  • Improvements

    • Refined boundary selection process with more precise hierarchy data retrieval.
    • Updated campaign configuration to support more comprehensive employee and hierarchy information.
    • Streamlined data fetching processes for hierarchy management.
  • User Experience Enhancements

    • Added toast notifications to inform users about project type availability and authorization status.
    • Improved button states based on user authorization and data presence.

@suryansh-egov suryansh-egov requested a review from a team as a code owner January 31, 2025 11:05
Copy link
Contributor

coderabbitai bot commented Jan 31, 2025

📝 Walkthrough

Walkthrough

The pull request introduces enhancements to the campaign management module, focusing on improving data filtering, loading state management, and component configuration. Changes span multiple files in the campaign manager, including CampaignType.js, SelectingBoundariesDuplicate.js, CampaignConfig.js, and SetupCampaign.js. The modifications primarily involve adding loading states, implementing hierarchy-based filtering for project types, updating API request configurations, and passing additional parameters to components to support more dynamic and context-aware functionality.

Changes

File Change Summary
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/CampaignType.js - Added loading state for managing loading indicator
- Introduced filteredProjectTypes state for hierarchy-based filtering
- Implemented getGroupsFromMatchingHierarchies function
- Updated project type dropdown to use filtered types
- Added showToast state for error messaging
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/SelectingBoundariesDuplicate.js - Added Loader component
- Introduced manual hierarchy data fetching
- Added loading and boundaryHierarchyData states
- Created fetchBoundaryHierarchy method
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/configs/CampaignConfig.js - Updated function signature to include allHierarchy and employeeDetails
- Modified customProps to pass new parameters to components
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/BoundaryHome.js - Added disButton state for button control
- Updated button disabling logic based on data and user role
- Introduced Toast components for user feedback
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/SetupCampaign.js - Removed HierarchySchema fetching logic
- Introduced HRMS_CONTEXT_PATH constant
- Added new API hook for employee hierarchy types
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/Module.js - Updated data fetching logic to utilize new hooks
- Modified moduleCode to include new hierarchy data
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/hooks/useBoundaryHome.js - Removed generateFile function
- Updated fetching logic to use new hierarchy data endpoint
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/hooks/useEmployeeHierarchyType.js - Introduced new hook for managing employee hierarchy data
- Implemented loading and error handling
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/UpdateCampaign.js - Removed HierarchySchema logic
- Introduced new logic to derive lowestHierarchy from BOUNDARY_HIERARCHY_TYPE
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/SelectingBoundaryComponent.js - Added use to the list of imported React hooks
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/UpdateBoundaryWrapper.js - Removed custom hook for HierarchySchema and updated logic to use useEmployeeHierarchyType

Possibly related PRs

  • fixed targetvalidation and added no results in boundary #1768: The changes in the main PR are related to those in the retrieved PR as both involve modifications to state management and the introduction of new components for handling loading and no results scenarios, specifically within the context of campaign management.
  • added popup for boundary summary #1525: The changes in the main PR and the retrieved PR are related through the introduction of the showPopUp state variable in both the CampaignType.js and BoundaryDetailsSummary.js components, indicating a shared focus on managing popup visibility.
  • fixed HCMPRE-1090 #1677: The changes in the main PR are related to the modifications in the CampaignType.js file, specifically regarding the introduction of new state management and logic for handling project types, which aligns with the updates made to the CampaignUpdateSummary.js file that also involve handling hierarchy data.

Poem

🐰 Hopping through code with glee,
Filtering types, setting data free!
Loading states dance, hierarchies align,
Campaign magic, line by line!
Rabbit's code brings joy so bright! 🚀

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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: 12

🔭 Outside diff range comments (2)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/SelectingBoundaries.js (1)

Line range hint 16-24: Consider implementing state management library.

The component uses multiple useState hooks and complex state interactions. Consider using a state management library (e.g., Redux, Zustand) to:

  • Centralize state management
  • Improve code maintainability
  • Reduce prop drilling
  • Make state changes more predictable
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/CampaignType.js (1)

Line range hint 7-30: Consider destructuring props for better readability.

Instead of accessing props through nested objects, consider destructuring them at the component level for cleaner code.

-const CampaignSelection = ({ onSelect, formData, formState, ...props }) => {
+const CampaignSelection = ({ 
+  onSelect, 
+  formData, 
+  formState, 
+  props: { 
+    sessionData,
+    employeeDetails,
+    allHierarchy,
+    isSubmitting 
+  } 
+}) => {
🧰 Tools
🪛 Biome (1.9.4)

[error] 25-25: Use Number.parseInt instead of the equivalent global.

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

(lint/style/useNumberNamespace)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6c84b84 and 113eefd.

📒 Files selected for processing (7)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/CampaignType.js (4 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/SelectingBoundaries.js (1 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/SelectingBoundariesDuplicate.js (2 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/configs/CampaignConfig.js (3 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/hooks/useBoundaryHome.js (3 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/BoundaryHome.js (1 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/SetupCampaign.js (3 hunks)
🧰 Additional context used
📓 Path-based instructions (7)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/BoundaryHome.js (1)

Pattern **/*.js: check

health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/hooks/useBoundaryHome.js (1)

Pattern **/*.js: check

health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/SelectingBoundaries.js (1)

Pattern **/*.js: check

health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/SelectingBoundariesDuplicate.js (1)

Pattern **/*.js: check

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

Pattern **/*.js: check

health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/configs/CampaignConfig.js (1)

Pattern **/*.js: check

health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/CampaignType.js (1)

Pattern **/*.js: check

🪛 Biome (1.9.4)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/SelectingBoundariesDuplicate.js

[error] 183-204: 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)


[error] 213-213: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

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

[error] 186-202: Enforce to have the onClick mouse event with the onKeyUp, the onKeyDown, or the onKeyPress keyboard event.

Actions triggered using mouse events should have corresponding keyboard events to account for keyboard-only navigation.

(lint/a11y/useKeyWithClickEvents)


[error] 230-270: 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)


[error] 236-236: Template literals are preferred over string concatenation.

Unsafe fix: Use a template literal.

(lint/style/useTemplate)


[error] 234-234: Avoid passing children using a prop

The canonical way to pass children in React is to use JSX elements

(lint/correctness/noChildrenProp)


[error] 235-235: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)


[error] 246-256: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)


[error] 257-267: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

⏰ Context from checks skipped due to timeout of 10000ms (1)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (6)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/configs/CampaignConfig.js (1)

104-106: LGTM! Good improvement in prop passing pattern.

The changes correctly move away from global state (window object) to proper React props, improving the component's predictability and testability.

Also applies to: 213-215

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

68-68: LGTM! Well-structured configuration retrieval.

The constant is properly defined with a fallback value, following the codebase's configuration management pattern.


246-247: LGTM! Proper dependency management.

The campaign configuration correctly updates when hierarchy or employee data changes, with all dependencies properly declared in the dependency array.

health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/CampaignType.js (1)

Line range hint 119-124: Review the necessity of executionCount effect.

The current implementation has a potential issue:

  1. The effect runs on every render without dependencies
  2. The count limit of 5 seems arbitrary
  3. The effect updates the parent state which could cause unnecessary re-renders

Consider using a more deterministic approach or removing this if not necessary.

Would you like me to suggest an alternative implementation?

health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/SelectingBoundariesDuplicate.js (2)

6-6: LGTM! Good improvements to state management.

The changes improve the component's state management and user experience by:

  • Adding loading state for better UX
  • Centralizing hierarchy data management
  • Moving away from hook-based data fetching to more controlled data fetching

Also applies to: 14-27


166-167: LGTM! Good loading state handling.

The loading state implementation improves user experience by showing a loading indicator during data fetching and preventing content flash.

Also applies to: 225-225

coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 31, 2025
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: 27

🔭 Outside diff range comments (6)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/SelectingBoundaryComponent.js (4)

292-295: Missing Lodash Import for _.isEqual Usage

The code uses _.isEqual in several places (e.g., within the handleBoundaryChange function and in the state updater callback) to perform deep comparisons. However, lodash isn’t imported as _—only merge is imported from lodash on line 10. This will lead to runtime errors. You can fix this by either importing the entire lodash library as _ or by importing isEqual explicitly. For example:

- import { merge } from "lodash";
+ import _ from "lodash";

Alternatively, if you prefer a more modular approach:

- // No additional import needed for isEqual
+ import isEqual from "lodash/isEqual";

…and then update all calls from _.isEqual(...) to isEqual(...).

Also applies to: 321-332, 359-363


416-424: Include onSelect in useEffect Dependencies

The useEffect from lines 416–424 uses the onSelect prop inside the setTimeout callback but does not include onSelect in its dependency array. If onSelect might change, including it will prevent stale closures. Consider updating the dependency array to include onSelect.


443-608: React List Rendering: Missing key Props

Both the multi-select branch (lines ~443–573) and the dropdown branch (lines ~574–608) involve mapping over lists of boundary items without setting a unique key prop on the rendered elements (e.g., on the <LabelFieldPair> components). Adding a unique key (such as an ID or a combination of unique attributes) is recommended to help React efficiently update the list during re-renders.

🧰 Tools
🪛 Biome (1.9.4)

[error] 466-466: Template literals are preferred over string concatenation.

Unsafe fix: Use a template literal.

(lint/style/useTemplate)


[error] 506-506: Template literals are preferred over string concatenation.

Unsafe fix: Use a template literal.

(lint/style/useTemplate)


[error] 584-584: Template literals are preferred over string concatenation.

Unsafe fix: Use a template literal.

(lint/style/useTemplate)


[error] 464-464: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)


[error] 504-504: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)


[error] 582-582: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)


483-485: Cleanup: Remove Commented-out onSelect Handler

In the JSX for the multi-select dropdown (around lines 483–485), there’s a commented-out line for the onSelect handler. If this code is not needed, please remove it to reduce clutter and improve readability.

health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/CampaignType.js (1)

23-53: Consider consolidating related state variables.

The component has multiple related state variables that could be consolidated into a single state object for better state management.

-  const [showToast, setShowToast] = useState(false);
-  const [loading, setLoading] = useState(true);
-  const [filteredProjectTypes, setFilteredProjectTypes] = useState([]);
+  const [state, setState] = useState({
+    showToast: false,
+    loading: true,
+    filteredProjectTypes: []
+  });
🧰 Tools
🪛 Biome (1.9.4)

[error] 33-33: Useless rename.

Safe fix: Remove the renaming.

(lint/complexity/noUselessRename)


[error] 26-26: Use Number.parseInt instead of the equivalent global.

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

(lint/style/useNumberNamespace)

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

251-442: Refactor large useEffect for better maintainability.

The large useEffect block handling API calls should be broken down into smaller, more focused functions.

+const handleCreatePayload = (draftData, totalFormData, hierarchyType) => {
+  let payloadData = { ...draftData };
+  payloadData.hierarchyType = hierarchyType;
+  // ... rest of payload preparation
+  return payloadData;
+};
+
+const handleAPICall = async (payloadData, isCreate = false) => {
+  const mutateFunction = isCreate ? mutate : updateCampaign;
+  await mutateFunction(payloadData, {
+    onError: handleError,
+    onSuccess: handleSuccess,
+    onSettled: () => setIsDataCreating(false)
+  });
+};
+
 useEffect(async () => {
   if (shouldUpdate === true) {
-    if (filteredConfig?.[0]?.form?.[0]?.body?.[0]?.skipAPICall && !id) {
-      return;
-    } else if (filteredConfig?.[0]?.form?.[0]?.isLast) {
-      const reqCreate = async () => {
-        let payloadData = { ...draftData };
-        // ... rest of the effect
+    if (!shouldMakeAPICall()) return;
+    
+    const payloadData = handleCreatePayload(draftData, totalFormData, hierarchyType);
+    if (compareIdentical(draftData, payloadData)) {
+      setCurrentKey(currentKey + 1);
+      return;
+    }
+    
+    await handleAPICall(payloadData, !id);
   }
   setShouldUpdate(false);
 }, [shouldUpdate]);
🧰 Tools
🪛 Biome (1.9.4)

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

(lint/performance/noDelete)


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

(lint/performance/noDelete)


[error] 257-257: This let declares a variable that is only assigned once.

'payloadData' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


[error] 322-322: This let declares a variable that is only assigned once.

'payloadData' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


[error] 380-380: This let declares a variable that is only assigned once.

'payloadData' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)

♻️ Duplicate comments (2)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/SetupCampaign.js (1)

122-136: 🛠️ Refactor suggestion

Add error handling for MDMS API response.

While the request configuration is well-structured, consider adding error handling for potential API failures.

Add error handling by wrapping the API call in try-catch blocks:

 const { data: allHierarchy } = Digit.Hooks.useCustomAPIHook(reqAllHierarchy);
+const { data: allHierarchy, error: hierarchyError } = Digit.Hooks.useCustomAPIHook(reqAllHierarchy);
+
+useEffect(() => {
+  if (hierarchyError) {
+    setShowToast({ 
+      key: "error", 
+      label: t("ES_ERROR_LOADING_HIERARCHY_DATA")
+    });
+  }
+}, [hierarchyError]);
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/hooks/useBoundaryHome.js (1)

45-65: 🧹 Nitpick (assertive)

Consider rethrowing or returning a structured error object instead of an empty array.

While returning [] ensures the code doesn’t break at higher levels, it may mask underlying errors. Also, consider a proper logging utility rather than using console.error.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a27768b and b9b80d9.

📒 Files selected for processing (11)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/Module.js (3 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/CampaignType.js (4 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/SelectingBoundariesDuplicate.js (3 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/SelectingBoundaryComponent.js (1 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/UpdateBoundaryWrapper.js (1 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/hooks/index.js (2 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/hooks/useBoundaryHome.js (3 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/hooks/useEmployeeHierarchyType.js (1 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/BoundaryHome.js (2 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/SetupCampaign.js (2 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/UpdateCampaign.js (1 hunks)
👮 Files not reviewed due to content moderation or server errors (3)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/BoundaryHome.js
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/CampaignType.js
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/UpdateCampaign.js
🧰 Additional context used
📓 Path-based instructions (11)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/hooks/index.js (1)

Pattern **/*.js: check

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

Pattern **/*.js: check

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

Pattern **/*.js: check

health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/hooks/useEmployeeHierarchyType.js (1)

Pattern **/*.js: check

health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/SelectingBoundaryComponent.js (1)

Pattern **/*.js: check

health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/Module.js (1)

Pattern **/*.js: check

health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/CampaignType.js (1)

Pattern **/*.js: check

health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/UpdateBoundaryWrapper.js (1)

Pattern **/*.js: check

health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/hooks/useBoundaryHome.js (1)

Pattern **/*.js: check

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

Pattern **/*.js: check

health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/SelectingBoundariesDuplicate.js (1)

Pattern **/*.js: check

📓 Learnings (1)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/Module.js (1)
Learnt from: siddhant-nawale-egov
PR: egovernments/DIGIT-Frontend#741
File: micro-ui/web/micro-ui-internals/packages/modules/hcm-microplanning/src/Module.js:15-15
Timestamp: 2024-11-10T20:01:49.000Z
Learning: When adding a new module code like "campaignmanager" to `moduleCode`, ensure that it is properly handled in all relevant conditional checks and function parameters across the codebase.
🪛 Biome (1.9.4)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/BoundaryHome.js

[error] 93-93: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)


[error] 94-94: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)


[error] 95-95: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

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

[error] 70-70: Useless rename.

Safe fix: Remove the renaming.

(lint/complexity/noUselessRename)

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

[error] 33-33: Useless rename.

Safe fix: Remove the renaming.

(lint/complexity/noUselessRename)


[error] 26-26: Use Number.parseInt instead of the equivalent global.

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

(lint/style/useNumberNamespace)


[error] 204-220: Enforce to have the onClick mouse event with the onKeyUp, the onKeyDown, or the onKeyPress keyboard event.

Actions triggered using mouse events should have corresponding keyboard events to account for keyboard-only navigation.

(lint/a11y/useKeyWithClickEvents)


[error] 261-261: Template literals are preferred over string concatenation.

Unsafe fix: Use a template literal.

(lint/style/useTemplate)


[error] 259-259: Avoid passing children using a prop

The canonical way to pass children in React is to use JSX elements

(lint/correctness/noChildrenProp)


[error] 260-260: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)


[error] 271-281: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)


[error] 282-292: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

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

[error] 34-34: Useless rename.

Safe fix: Remove the renaming.

(lint/complexity/noUselessRename)

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

[error] 85-85: Useless rename.

Safe fix: Remove the renaming.

(lint/complexity/noUselessRename)

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

[error] 25-25: Useless rename.

Safe fix: Remove the renaming.

(lint/complexity/noUselessRename)


[error] 167-178: 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)


[error] 187-187: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

⏰ Context from checks skipped due to timeout of 10000ms (1)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (47)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/SetupCampaign.js (3)

82-88: LGTM! The hook implementation is well-structured.

The useEmployeeHierarchyType hook correctly handles hierarchy data fetching with proper loading state management.

🧰 Tools
🪛 Biome (1.9.4)

[error] 85-85: Useless rename.

Safe fix: Remove the renaming.

(lint/complexity/noUselessRename)


91-93: LGTM! Efficient memoization of lowestHierarchy.

The code correctly memoizes the lowestHierarchy value from rawData with proper dependency tracking.


68-80: Verify the HRMS context path configuration.

The code correctly defines the HRMS_CONTEXT_PATH constant with a fallback value. The removal of the MDMS-based hierarchy schema fetching aligns with the new approach.

Run this script to verify the constant's usage:

✅ Verification successful

HRMS context configuration verified.

The HRMS context constant is correctly defined with a fallback value and is consistently used across multiple files. The removal of the MDMS-based hierarchy schema fetching is aligned with the new approach.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for HRMS_CONTEXT_PATH usage in the codebase.
rg -A 5 'HRMS_CONTEXT_PATH'

Length of output: 12335

health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/hooks/useBoundaryHome.js (7)

22-22: Prefer a structured logging approach instead of console.error.

This repeats a previous recommendation to replace console-based logging with a consistent and configurable logging utility.


40-40: Prefer a structured logging approach instead of console.error.

This repeats a previous recommendation to replace console-based logging with a consistent and configurable logging utility.


71-72: Validate empty hierarchy responses.

If fetchHierarchies returns an empty array (due to an error or no data), ensure subsequent logic accounts for this case to avoid unexpected behavior.


95-95: Prefer a structured logging approach instead of console.error.

This repeats a previous recommendation to replace console-based logging with a consistent and configurable logging utility.


101-101: Query key looks appropriate.

Using ["boundaryData", hierarchyType, userName, tenantId] as the key is a clear approach for caching and refetching boundaries.


113-113: Good practice returning isFetching.

Exposing isFetching alongside isLoading helps distinguish between initial load and subsequent background refetches.


117-117: Export statement looks fine.

No issues found. The hook is properly exported as the default.

health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/UpdateBoundaryWrapper.js (1)

89-120: Implementation looks good!

The component implementation:

  • Properly handles boundary selection state
  • Provides clear user feedback about boundary removal restrictions
  • Maintains good separation of concerns
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/SelectingBoundariesDuplicate.js (8)

6-6: Import of new component looks good.

No issues spotted. The import statement is well-structured and consistent with the existing style.


30-34: Good use of useMemo.

The memoization to compute lowestHierarchy and hierarchyType helps avoid redundant recomputations. No issues found here.


36-38: State initialization is clear.

Declaring separate state variables for boundaryHierarchyData and loading improves code clarity. Good job.


66-66: Fetching mail configuration appears consistent.

Leveraging Digit.Hooks.useCustomMDMS is aligned with the existing pattern in this codebase. No concerns raised.


95-95: Invocation of onSelect is appropriate.

Passing the updated boundary parameters ensures global state synchronization. The implementation is straightforward.


150-160: Loader logic and conditional rendering look correct.

The conditional check between loading and non-loading states is well-implemented, preventing partial renders.


167-178: Use a self-closing element when no children are rendered.

This was previously flagged. If <Wrapper> has no child elements, consider making it self-closing for cleaner JSX syntax.

-              ></Wrapper>
+              />
🧰 Tools
🪛 Biome (1.9.4)

[error] 167-178: 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)


180-198: Add a key prop for array elements.

This was previously noted. When passing elements as an array to the additionalElements prop, each item requires a unique key to help React identify changes.

- additionalElements={[
-   <span style={{ color: "#505A5F" }}>
+ additionalElements={[
+   <span key="boundary-info" style={{ color: "#505A5F" }}>
      {t("HCM_BOUNDARY_INFO")}
      ...
   </span>,
 ]}
🧰 Tools
🪛 Biome (1.9.4)

[error] 187-187: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/SelectingBoundaryComponent.js (2)

218-222: Dependency Array Enhancement in useEffect

In the useEffect starting on line 218, the callback depends on boundaryOptions[parentRoot] but does not explicitly list parentRoot as a dependency. To ensure the effect runs properly when parentRoot changes, consider adding it explicitly to the dependency array.


1-1: 🧹 Nitpick (assertive)

Questionable Import: Unused use Hook from React

The import statement on line 1 includes use, which is not a standard React hook and isn’t used anywhere in this file. If this was added unintentionally or is meant for future implementation, please either remove it now or add a clarifying comment. A suggested change is:

-import React, { useState, useEffect, Fragment, useRef, useMemo, use } from "react";
+import React, { useState, useEffect, Fragment, useRef, useMemo } from "react";
✅ Verification successful

Final Response

Import Cleanup: Remove the unused React hook use

The scan confirmed that the use hook imported from React is not used within the file. Please remove it as suggested.


Final Response

Unused Import Correction: Remove use from React imports

The refined search confirms that outside the import statement, there is no usage of the use hook. Please remove it from the import line.


Unused Import Correction: Remove use from React Imports

Our refined search confirms that the use hook imported from React is not used anywhere in the file. It can be safely removed.

🏁 Scripts executed

The following scripts were executed for the analysis:

Error: No shell scripts or web queries found


Script:

#!/bin/bash
# Exclude the import statement and search for any usage of the identifier "use" in the file.
grep -v "^import" health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/SelectingBoundaryComponent.js | rg -w "use"

Length of output: 149


Script:

#!/bin/bash
# Use a refined regex to check for standalone usage of "use" (excluding the import statement)
rg --no-heading -n -w "use" health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/SelectingBoundaryComponent.js | grep -v "import"

Length of output: 162

health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/Module.js (3)

1-2: No concerns regarding these imports.
These added imports from the UI components library and React look standard and appropriate.


76-88: Handle loading and error state from the custom hook.
While the custom hook exposes isLoading and error as hierarchyLoading and possible error, they are not used here. Consider conditionally handling loading states and errors to improve user experience and avoid edge-case failures.


91-93: Validate fallback for module code generation.
If BOUNDARY_HIERARCHY_TYPE is empty or invalid, generating ["boundary-"] might lead to unintended behavior. Confirm that your environment and data guarantee a valid non-empty boundary type before proceeding. Otherwise, implement appropriate handling.

health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/hooks/index.js (1)

22-22: Hook registration and import look good.
Importing the useEmployeeHierarchyType hook and adding it to the campaign hooks object is straightforward and aligned with the existing structure.

Also applies to: 52-52

health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/hooks/useEmployeeHierarchyType.js (5)

3-10: Initial states and constants setup appear fine.
Declaring data, isLoading, and error states, plus HRMS_CONTEXT_PATH and CONSOLE_MDMS_MODULENAME, is an appropriate approach for capturing hook-specific data and configuration.


11-45: Validate employee response and handle possible null scenarios.
While any error is caught in the try block, if employeeResponse?.Employees is empty, employee becomes undefined. Consider gracefully handling this scenario or returning early if no employees are found for the current user.


47-55: Check for multiple matching hierarchies.
Calling find() will return the first matching hierarchy. Confirm whether this is desired or whether you need to accommodate multiple potential matches for an employee.


56-73: Good use of a result object and error boundary.
Packaging the hierarchy, employee, and allHierarchies into a single object is clean. The try/catch ensures unhandled exceptions are minimized. Consider logging or storing a user-friendly error if the data is crucial to application flow.


75-94: Flexible select function and memo usage is a solid approach.
Allowing consumers to shape the returned data via options.select promotes reusability. Caching with useMemo also helps optimize repeated renders.

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

57-60: LGTM! Good use of useEffect for authorization and state updates.

The effect hook correctly handles both authorization check and button state updates based on data availability.


89-97: LGTM! Good use of conditional rendering for InfoCard.

The InfoCard component is properly rendered with appropriate conditions and styling.

🧰 Tools
🪛 Biome (1.9.4)

[error] 93-93: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)


[error] 94-94: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)


[error] 95-95: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)


49-50: LGTM! State management for button control.

The state variable disButton is appropriately initialized and used to control button states based on boundary data availability.


57-60: LGTM! Authorization check implementation.

The useEffect hook correctly checks for the BOUNDARY_MANAGER role and updates states based on data availability.


81-81: LGTM! Button disabled logic.

The button's disabled state correctly considers multiple conditions: edit/create restrictions, boundary data availability, and user authorization.


98-109: LGTM! Toast notifications for user feedback.

The Toast components provide clear feedback about boundary data and authorization status.

health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/CampaignType.js (8)

54-87: 🛠️ Refactor suggestion

Memoize getGroupsFromMatchingHierarchies for performance.

The function performs complex operations and should be memoized to prevent unnecessary recalculations.

-  const getGroupsFromMatchingHierarchies = (employeeDetails, hierarchies) => {
+  const getGroupsFromMatchingHierarchies = useMemo(() => (employeeDetails, hierarchies) => {
     if (!employeeDetails?.assignments || !hierarchies?.length) {
       return [];
     }
     // ... rest of the function
     return Array.from(groups);
-  };
+  }, []);

Likely invalid or redundant comment.


54-87: 🧹 Nitpick (assertive)

Optimize hierarchy filtering logic.

The getGroupsFromMatchingHierarchies function could be memoized to prevent unnecessary recalculations.

+const getGroupsFromMatchingHierarchies = useMemo(() => {
-const getGroupsFromMatchingHierarchies = (employeeDetails, hierarchies) => {
   if (!employeeDetails?.assignments || !hierarchies?.length) {
     return [];
   }

   // Get employee departments from assignments
   const employeeDepartments = new Set(
     employeeDetails.assignments
       .filter(assignment => assignment.department)
       .map(assignment => assignment.department.toUpperCase())
   );

   // Filter hierarchies where employee department matches hierarchy department
   const matchingHierarchies = hierarchies.filter(hierarchy => {
     const hierarchyDepartments = Array.isArray(hierarchy?.department) 
       ? hierarchy?.department 
       : [hierarchy?.department];
           
     return hierarchyDepartments.some(dept => 
       employeeDepartments.has(dept?.toUpperCase())
     );
   });

   // Extract unique groups from matching hierarchies
   const groups = new Set(
     matchingHierarchies
       .filter(hierarchy => hierarchy.group)
       .flatMap(hierarchy => hierarchy.group)
   );
   return Array.from(groups);
-};
+}, [employeeDetails, hierarchies]);

Likely invalid or redundant comment.


204-220: ⚠️ Potential issue

Add keyboard accessibility to campaign type wrapper.

The click handler needs corresponding keyboard events for accessibility compliance.

 <div
   className="campaign-type-wrapper"
+  role="button"
+  tabIndex={0}
   onClick={(e) => {
     if (props?.props?.sessionData?.HCM_CAMPAIGN_TYPE?.projectType && !canUpdate && source!=="microplan") {
       setShowPopUp(true);
       return;
     }
     return;
   }}
+  onKeyDown={(e) => {
+    if (e.key === 'Enter' || e.key === ' ') {
+      if (props?.props?.sessionData?.HCM_CAMPAIGN_TYPE?.projectType && !canUpdate && source!=="microplan") {
+        setShowPopUp(true);
+        return;
+      }
+    }
+  }}
   onFocus={(e) => {
     if (props?.props?.sessionData?.HCM_CAMPAIGN_TYPE?.projectType && !canUpdate) {
       setShowPopUp(true);
       return;
     }
     return;
   }}

Likely invalid or redundant comment.

🧰 Tools
🪛 Biome (1.9.4)

[error] 204-220: Enforce to have the onClick mouse event with the onKeyUp, the onKeyDown, or the onKeyPress keyboard event.

Actions triggered using mouse events should have corresponding keyboard events to account for keyboard-only navigation.

(lint/a11y/useKeyWithClickEvents)


259-293: ⚠️ Potential issue

Fix React best practices in PopUp component.

Several React best practices issues need to be addressed in the PopUp component.

 <PopUp
   className={"boundaries-pop-module"}
   type={"default"}
   heading={t("ES_CAMPAIGN_UPDATE_TYPE_MODAL_HEADER")}
-  children={[
-    <div>
-      <CardText style={{ margin: 0 }}>{t("ES_CAMPAIGN_UPDATE_TYPE_MODAL_TEXT") + " "}</CardText>
-    </div>,
-  ]}
 >
+  <div>
+    <CardText style={{ margin: 0 }}>{`${t("ES_CAMPAIGN_UPDATE_TYPE_MODAL_TEXT")} `}</CardText>
+  </div>
   <div className="popup-button-wrapper">
     <Button
+      key="back-button"
       className={"campaign-type-alert-button"}
       // ... other props
     />
     <Button
+      key="submit-button"
       className={"campaign-type-alert-button"}
       // ... other props
     />
   </div>
 </PopUp>

Likely invalid or redundant comment.

🧰 Tools
🪛 Biome (1.9.4)

[error] 261-261: Template literals are preferred over string concatenation.

Unsafe fix: Use a template literal.

(lint/style/useTemplate)


[error] 259-259: Avoid passing children using a prop

The canonical way to pass children in React is to use JSX elements

(lint/correctness/noChildrenProp)


[error] 260-260: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)


[error] 271-281: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)


[error] 282-292: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)


23-43: LGTM! State management and hooks setup.

The component properly initializes states for loading, toast, and filtered data, and uses memoization for employee details and hierarchies.

🧰 Tools
🪛 Biome (1.9.4)

[error] 33-33: Useless rename.

Safe fix: Remove the renaming.

(lint/complexity/noUselessRename)


[error] 26-26: Use Number.parseInt instead of the equivalent global.

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

(lint/style/useNumberNamespace)


204-220: 🛠️ Refactor suggestion

Add keyboard accessibility to clickable div.

The div with click handler needs keyboard event handlers for accessibility.

 <div
   className="campaign-type-wrapper"
   onClick={(e) => {
     if (props?.props?.sessionData?.HCM_CAMPAIGN_TYPE?.projectType && !canUpdate && source!=="microplan") {
       setShowPopUp(true);
       return;
     }
     return;
   }}
+  onKeyDown={(e) => {
+    if (e.key === 'Enter' || e.key === ' ') {
+      if (props?.props?.sessionData?.HCM_CAMPAIGN_TYPE?.projectType && !canUpdate && source!=="microplan") {
+        setShowPopUp(true);
+        return;
+      }
+    }
+  }}
+  role="button"
+  tabIndex={0}
   onFocus={(e) => {

Likely invalid or redundant comment.

🧰 Tools
🪛 Biome (1.9.4)

[error] 204-220: Enforce to have the onClick mouse event with the onKeyUp, the onKeyDown, or the onKeyPress keyboard event.

Actions triggered using mouse events should have corresponding keyboard events to account for keyboard-only navigation.

(lint/a11y/useKeyWithClickEvents)


259-293: 🛠️ Refactor suggestion

Fix React best practices in PopUp component.

Several React best practices need to be addressed:

  1. Missing key props in iterables
  2. Using string concatenation instead of template literals
  3. Passing children as props
 <PopUp
   className={"boundaries-pop-module"}
   type={"default"}
   heading={t("ES_CAMPAIGN_UPDATE_TYPE_MODAL_HEADER")}
-  children={[
-    <div>
-      <CardText style={{ margin: 0 }}>{t("ES_CAMPAIGN_UPDATE_TYPE_MODAL_TEXT") + " "}</CardText>
-    </div>,
-  ]}
 >
+  <div>
+    <CardText style={{ margin: 0 }}>{`${t("ES_CAMPAIGN_UPDATE_TYPE_MODAL_TEXT")} `}</CardText>
+  </div>
   <div className="popup-button-wrapper">
     <Button
+      key="back-button"
       className={"campaign-type-alert-button"}
       // ... other props
     />
     <Button
+      key="submit-button"
       className={"campaign-type-alert-button"}
       // ... other props
     />
   </div>
 </PopUp>

Likely invalid or redundant comment.

🧰 Tools
🪛 Biome (1.9.4)

[error] 261-261: Template literals are preferred over string concatenation.

Unsafe fix: Use a template literal.

(lint/style/useTemplate)


[error] 259-259: Avoid passing children using a prop

The canonical way to pass children in React is to use JSX elements

(lint/correctness/noChildrenProp)


[error] 260-260: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)


[error] 271-281: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)


[error] 282-292: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)


54-87: 🧹 Nitpick (assertive)

Consider optimizing hierarchy filtering.

The getGroupsFromMatchingHierarchies function performs multiple array operations. Consider memoizing the result to avoid unnecessary recalculations.

+const memoizedGroups = useMemo(
+  () => getGroupsFromMatchingHierarchies(employeeDetails, hierarchies),
+  [employeeDetails, hierarchies]
+);

Likely invalid or redundant comment.

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

67-73: LGTM! Good use of the new hook with proper data selection.

The useEmployeeHierarchyType hook is well implemented with appropriate data selection.

🧰 Tools
🪛 Biome (1.9.4)

[error] 70-70: Useless rename.

Safe fix: Remove the renaming.

(lint/complexity/noUselessRename)


67-73: LGTM! Employee hierarchy hook implementation.

The useEmployeeHierarchyType hook is properly implemented with data selection and loading state management.

🧰 Tools
🪛 Biome (1.9.4)

[error] 70-70: Useless rename.

Safe fix: Remove the renaming.

(lint/complexity/noUselessRename)


74-77: LGTM! Updated hierarchy logic.

The lowestHierarchy calculation is correctly updated to use the new data structure from rawData.

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 4, 2025
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: 2

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b9b80d9 and 6fbabdb.

📒 Files selected for processing (1)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/Module.js (3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.js`: check

**/*.js: check

  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/Module.js
🔇 Additional comments (2)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/Module.js (2)

71-73: Remove or utilize the unused state variables.
They appear to have no references throughout the component, mirroring prior feedback.


118-124: Eliminate naming confusion between hierarchyData and hierarchyRelationData.
The variable hierarchyRelationData is passed as hierarchyData while a separate hierarchyData is also used to derive employeeDetails, which can be confusing.

// Fetch hierarchies using MDMS
const mdmsResponse = await Digit.CustomService.getResponse(
{
url: '/egov-mdms-service/v1/_search',
Copy link
Collaborator

Choose a reason for hiding this comment

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

why mdms url is hardcoded?
@suryansh-egov

const [filteredHierarchyType, setFilteredHierarchyType] = useState(null);
const [employeeData, setEmployeeData] = useState(null);
const [loading, setLoading] = useState(true);
const HRMS_CONTEXT_PATH = window?.globalConfigs?.getConfig("HRMS_CONTEXT_PATH") || "egov-hrms";
Copy link
Collaborator

Choose a reason for hiding this comment

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

why hrms context path is needed here since u have a custom hook do these activity

@@ -33,6 +50,68 @@ const CampaignSelection = ({ onSelect, formData, formState, ...props }) => {
window.history.replaceState({}, "", url);
}

const [filteredProjectTypes, setFilteredProjectTypes] = useState([]);
const getGroupsFromMatchingHierarchies = (employeeDetails, hierarchies) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

dont put these logic in campaign type filtering use a function and do that logic inside it

}],{select:(MdmsRes)=>MdmsRes},{ schemaCode: `${CONSOLE_MDMS_MODULENAME}.HierarchySchema` });
const { data: mailConfig } = Digit.Hooks.useCustomMDMS(tenantId, CONSOLE_MDMS_MODULENAME, [{ name: "mailConfig" }],{select:(MdmsRes)=>MdmsRes},{ schemaCode: `${CONSOLE_MDMS_MODULENAME}.mailConfig` });
// const hierarchyType = props?.props?.dataParams?.hierarchyType;
const employee = props?.props?.employeeDetails?.Employees?.[0];
Copy link
Collaborator

Choose a reason for hiding this comment

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

same here as well

const fetchHierarchies = async (tenantId) => {
try {
const res = await Digit.CustomService.getResponse({
url: `/egov-mdms-service/v1/_search`,
Copy link
Collaborator

Choose a reason for hiding this comment

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

same here

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.

3 participants