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

intial changes new #1530

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

intial changes new #1530

wants to merge 12 commits into from

Conversation

suryansh-egov
Copy link
Collaborator

@suryansh-egov suryansh-egov commented Oct 16, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a "VIEW_CHECKLIST" link in the CampaignCard for quick access to checklist views.
    • Added a new ViewChecklist component for managing and displaying checklists.
    • Implemented a new route for viewing checklists in the application.
    • Added a new UpdateChecklist component for updating existing checklists.
  • Enhancements

    • Added typeOfCall prop across various components to control the enabled/disabled states of UI elements based on user roles.
    • Enhanced the CreateChecklist and UpdateChecklist components with improved data handling and user interface elements.
    • Updated dropdown options and labels for better localization and user experience.
  • Bug Fixes

    • Improved rendering logic to conditionally display or disable UI elements based on the typeOfCall prop.
    • Refined error handling and loading states in checklist creation and updating processes.

Copy link
Contributor

coderabbitai bot commented Oct 16, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes in this pull request primarily involve the addition of a new prop, typeOfCall, across multiple components within the campaign management module. This prop influences the rendering logic and the disabled state of various UI elements based on its value. Additionally, a new component, ViewChecklist, is introduced to manage a checklist view, and new routes for this component and an update checklist component are added in the application. The modifications ensure that the application can handle different interaction modes, such as viewing and editing.

Changes

File Change Summary
.../CampaignCard.js Added a new link "VIEW_CHECKLIST" for the CAMPAIGN_MANAGER role.
.../Checkboxes.js Introduced typeOfCall prop to control the disabled state of components.
.../CreateQuestion.js Added typeOfCall prop affecting rendering logic and UI element visibility.
.../CreateQuestionContext.js Added typeOfCall state variable and updated logic in useEffect hooks.
.../Dropdowns.js Included typeOfCall prop to manage rendering logic for UI elements.
.../MultipleChoice.js Added typeOfCall prop to control the disabled state of radio buttons and comments.
.../checklistCreateConfig.js Modified function signature to accept typeOfCall as a parameter.
.../employee/ViewChecklist.js Introduced a new ViewChecklist component for checklist display and interaction.
.../employee/index.js Added new routes for the ViewChecklist and UpdateChecklist components within the App component.
.../employee/UpdateChecklist.js Introduced a new UpdateChecklist component for updating checklists.
.../employee/CreateChecklist.js Enhanced state management and logic for checklist creation.
.../employee/SearchChecklist.js Updated dropdown options and state management with campaignName.
.../hooks/index.js Added new useUpdateChecklist hook to manage checklist updates.
.../hooks/services/updateChecklistService.js Introduced updateChecklistService function for service interactions.

Suggested reviewers

  • jagankumar-egov

Poem

🐇 In the garden where ideas bloom,
A checklist now finds its room.
With typeOfCall guiding the way,
New links and routes brighten the day.
Hop along, let changes flow,
In our campaign, watch us grow! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 17

🧹 Outside diff range comments (6)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/CampaignCard.js (1)

Line range hint 1-82: LGTM with a minor suggestion

The addition of the new "VIEW_CHECKLIST" link to the CampaignCard component is consistent with the existing structure and functionality. The changes are minimal and focused, which is good for maintainability.

Consider adding a brief comment explaining the purpose of the "VIEW_CHECKLIST" link and why it's associated with the CAMPAIGN_MANAGER role. This would improve code readability and help future developers understand the intent behind this addition.

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

Line range hint 90-103: LGTM: Conditional rendering of "Add Options" button.

The conditional rendering of the "Add Options" button based on the dis variable is correct and aligns with the expected behavior for different interaction modes.

Consider improving the indentation of the button's JSX for better readability:

{!dis && (
  <div>
    <Button
      className="custom-class"
      icon="AddIcon"
      iconFill=""
      label={t("ADD_OPTIONS")}
      onClick={() => addOption()}
      size="medium"
      title=""
      variation="teritiary"
      textStyles={{width:'unset'}}
    />
  </div>
)}

Line range hint 131-183: Improve DropdownOption component implementation.

The changes to support different interaction modes in the DropdownOption component are generally correct, but there are a few improvements that can be made:

  1. The dis variable declaration can be simplified:

    const dis = typeOfCall === "view";
  2. The conditional rendering of the checkboxes and delete button can be combined for better readability:

    {!dis && (
      <>
        <CheckBox
          // ... (ADD_COMMENT_(OR) checkbox props)
        />
        <CheckBox
          // ... (LINK_NESTED_CHECKLIST checkbox props)
        />
        {!disableDelete && (
          <Button
            // ... (DELETE button props)
          />
        )}
      </>
    )}

These changes will improve code quality and maintainability while preserving the intended functionality.

🧰 Tools
🪛 Biome

[error] 134-134: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)


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

'dis' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)

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

Line range hint 89-101: LGTM: Conditional rendering for "ADD_OPTIONS" button.

The addition of conditional rendering for the "ADD_OPTIONS" button based on the dis variable is consistent with the new view/edit mode functionality. It correctly prevents adding new options in view mode.

Consider improving the indentation for better readability:

-      {!dis && <div>
-      <Button
+      {!dis && (
+        <div>
+          <Button
             // ... (button props)
-      />
-      </div>}
+          />
+        </div>
+      )}

Line range hint 132-183: Review of changes in CheckBoxOption component

  1. The dis variable declaration can be simplified:
-  let dis = typeOfCall==="view"?true:false;
+  const dis = typeOfCall === "view";
  1. The addition of the disabled prop to CheckBox and input elements is correct and consistent with the view/edit mode functionality.

  2. The conditional rendering for the comment checkbox (lines 159-172) can be simplified:

-          {!dis && 
-            <>
-              <CheckBox
-              key={field.key}
-              mainClassName={"checkboxOptionVariant"}          
-              disabled={optionDependency ? true: false}
-              label={t("ADD_COMMENT")}
-              checked={optionComment}
-              onChange={(event) => handleOptionComment(optionId)}
-              // isLabelFirst={true}
-              index={field.key}
-              />
-            </>
-          }
+          {!dis && (
+            <CheckBox
+              key={field.key}
+              mainClassName="checkboxOptionVariant"
+              disabled={optionDependency}
+              label={t("ADD_COMMENT")}
+              checked={optionComment}
+              onChange={() => handleOptionComment(optionId)}
+              index={field.key}
+            />
+          )}
  1. The update to the delete button's conditional rendering is correct and consistent with the view/edit mode functionality.

Please consider applying the suggested changes to improve code readability and consistency.

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

Line range hint 201-205: Fix indentation in the useEffect hook.

The logic to prevent storing an empty question in localStorage is good. However, the indentation of the if statement and its content is incorrect. Please fix the indentation to improve readability.

Here's the corrected indentation:

useEffect(() => {
  onSelect("createQuestion", {
    questionData,
  });
  if (!(questionData.length === 1 && questionData?.[0].title === null)) {
    localStorage.setItem("questions", JSON.stringify(questionData));
  } 
}, [questionData]);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between f887c42 and 1987af5.

📒 Files selected for processing (9)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/CampaignCard.js (1 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/Checkboxes.js (7 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/CreateQuestion.js (14 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/CreateQuestionContext.js (3 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/Dropdowns.js (8 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/MultipleChoice.js (8 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/configs/checklistCreateConfig.js (2 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/ViewChecklist.js (1 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/index.js (2 hunks)
🧰 Additional context used
📓 Path-based instructions (9)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/CampaignCard.js (1)

Pattern **/*.js: check

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

Pattern **/*.js: check

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

Pattern **/*.js: check

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

Pattern **/*.js: check

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

Pattern **/*.js: check

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

Pattern **/*.js: check

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

Pattern **/*.js: check

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

Pattern **/*.js: check

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

Pattern **/*.js: check

🪛 Biome
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/Checkboxes.js

[error] 34-34: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)


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

'dis' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


[error] 132-132: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)


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

'dis' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)

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

[error] 334-334: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)


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

'dis' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)

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

[error] 35-35: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)


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

'dis' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


[error] 134-134: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)


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

'dis' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)

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

[error] 34-34: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)


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

'dis' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


[error] 142-142: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)


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

'dis' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)

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

[error] 184-184: 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] 74-74: This let declares a variable that is only assigned once.

'matchedItem' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'code' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'res' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'temp_data' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'formatted_data' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


[error] 175-175: 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] 215-224: 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)

🔇 Additional comments (15)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/configs/checklistCreateConfig.js (1)

20-21: LGTM! Consistent with function signature update.

The addition of typeOfCall to the customProps object is consistent with the function signature update. This change allows the CreateQuestion component to access the typeOfCall value, which is likely used to influence the component's behavior or rendering.

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

33-33: LGTM: New prop added for interaction mode control.

The addition of the typeOfCall prop is appropriate for supporting different interaction modes (view/edit) in the Dropdowns component.


65-65: LGTM: Disabled state applied correctly.

The disabled prop of FieldV1 is now correctly set based on the typeOfCall, which is consistent with the intended behavior for different interaction modes.

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

32-32: LGTM: New prop typeOfCall added.

The addition of the typeOfCall prop is consistent with the PR objectives and allows for different interaction modes in the component.


128-129: LGTM: New props added to CheckBoxOption.

The addition of handleOptionComment and typeOfCall props to the CheckBoxOption component is consistent with the changes in the parent component. This allows for proper handling of comments and view/edit mode functionality in the child component.

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

Line range hint 97-110: LGTM: Conditional rendering of the Button component

The conditional rendering of the Button component based on the dis variable is implemented correctly. This ensures that the "ADD OPTIONS" button is only displayed when the component is not in "view" mode.


Line range hint 148-215: LGTM: Conditional rendering and disabling of elements

The implementation of conditional rendering and disabling of elements based on the dis variable is correct and consistent throughout the component. This includes:

  1. Disabling the radio button and text input (lines 148, 150)
  2. Conditionally rendering the "ADD COMMENT" and "LINK NESTED CHECKLIST" checkboxes (lines 164-180, 181-196)
  3. Conditionally rendering the delete button (lines 197-215)

This approach ensures that the component behaves appropriately in both view and edit modes.

🧰 Tools
🪛 Biome

[error] 142-142: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)


[error] 170-170: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)


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

'dis' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)

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

18-18: LGTM: New import statement for ViewChecklist component.

The import statement is correctly formatted and follows React component naming conventions.


Line range hint 1-134: Overall assessment: Changes are well-integrated and follow existing patterns.

The addition of the ViewChecklist component import and its corresponding route are implemented correctly and consistently with the rest of the file. The changes enhance the functionality of the campaign management module without disrupting the existing structure.


131-131: LGTM: New route for ViewChecklist component added correctly.

The new route is properly integrated into the existing routing structure. It follows the established patterns for route definition in this file.

To ensure the ViewChecklist component is properly implemented, please run the following script:

✅ Verification successful

Verified: ViewChecklist component implementation is correct.

The ViewChecklist component is properly implemented and integrates seamlessly with the new route. No issues found.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of the ViewChecklist component

# Test: Check if the ViewChecklist component file exists
fd -t f ViewChecklist.js$ health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee

# Test: Inspect the content of the ViewChecklist component
fd -t f ViewChecklist.js$ health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee -x cat

Length of output: 9289

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

175-175: LGTM: New state variable added correctly.

The addition of the typeOfCall state variable is consistent with the changes described in the AI summary. The initial value of null is appropriate if the type of call is not known at component mount.


212-212: LGTM: typeOfCall prop added correctly.

The addition of the typeOfCall prop to the CreateQuestion component is consistent with the new state variable and allows the component to access this information. This change aligns with the modifications described in the AI summary.


180-184: ⚠️ Potential issue

Remove console.log statements and review dependency array.

  1. The console.log statements at lines 180 and 183 should be removed before merging to production.
  2. The condition for dispatching the UPDATE_QUESTION_DATA action has been improved, which is good.
  3. Setting typeOfCall from props is correct.
  4. Consider the implications of adding props?.props?.time to the dependency array. If it changes frequently, it might cause unnecessary re-renders.

To verify the frequency of props?.props?.time changes, you can add a console.log statement in the useEffect hook:

useEffect(() => {
  console.log('props?.props?.time changed:', props?.props?.time);
  // ... rest of the useEffect code
}, [props?.props?.time]);

Then, monitor the console output during typical usage of the component to see how often this value changes.

Also applies to: 190-190

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

21-21: LGTM: Addition of typeOfCall prop to FieldSelector and its child components.

The typeOfCall prop has been consistently added to the FieldSelector component and passed down to its child components. This change allows for consistent behavior control across the component tree based on the type of interaction (view/edit).

Also applies to: 173-173, 197-197, 221-221

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

215-224: ⚠️ Potential issue

Add a key prop to elements in actionFields array

Similarly, elements in the actionFields array should have a unique key prop to prevent potential rendering issues.

Add a key prop to the <Button> component:

<ActionBar
    actionFields={[
-        <Button
+        <Button
+            key="next-button"

Likely invalid or redundant comment.

🧰 Tools
🪛 Biome

[error] 215-224: 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)

@@ -1,4 +1,4 @@
export const checklistCreateConfig = (data, time) => [
export const checklistCreateConfig = (data, time, typeOfCall) => [
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Some checklistCreateConfig function calls are missing the typeOfCall parameter. Please update them accordingly.

  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/CreateChecklist.js:
    • setConfig(checklistCreateConfig([{ id: crypto.randomUUID(), parentId: null, level: 1, key: 1, title: null, type: {"code": "SingleValueList"}, value: null, isRequired: false }]))
    • setConfig(checklistCreateConfig(mdms, currentTime));
🔗 Analysis chain

LGTM! Verify function calls across the codebase.

The addition of the typeOfCall parameter to the checklistCreateConfig function signature is a good improvement for flexibility. However, ensure that all calls to this function across the codebase have been updated to include this new parameter.

To verify the function usage, run the following script:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all occurrences of checklistCreateConfig function calls

# Search for checklistCreateConfig function calls
rg --type js 'checklistCreateConfig\s*\(' -A 3

Length of output: 3427

Comment on lines 76 to 82
},
{
label: t("VIEW_CHECKLIST"),
link: `/${window?.contextPath}/employee/campaign/checklist/view?campaignName=paradigms&role=Distributor&checklistType=Health facility Referral: Drug side effect from previous cycle`,
roles: ROLES.CAMPAIGN_MANAGER,
// count: isLoading?"-":data

Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider using dynamic values for URL parameters

The new link for "VIEW_CHECKLIST" has been added successfully. However, the URL contains hardcoded values for query parameters such as campaignName, role, and checklistType. This approach might limit the reusability and flexibility of the component.

Consider refactoring this to use dynamic values:

  1. Define these values as constants or fetch them from a configuration.
  2. Use template literals to construct the URL dynamically.

Example:

const VIEW_CHECKLIST_CONFIG = {
  campaignName: "paradigms",
  role: "Distributor",
  checklistType: "Health facility Referral: Drug side effect from previous cycle"
};

// In the links array
{
  label: t("VIEW_CHECKLIST"),
  link: `/${window?.contextPath}/employee/campaign/checklist/view?campaignName=${VIEW_CHECKLIST_CONFIG.campaignName}&role=${VIEW_CHECKLIST_CONFIG.role}&checklistType=${encodeURIComponent(VIEW_CHECKLIST_CONFIG.checklistType)}`,
  roles: ROLES.CAMPAIGN_MANAGER,
}

This approach would make it easier to update these values in the future and potentially allow for dynamic generation based on user context or application state.

}) => {
let dis = typeOfCall==="view"?true:false;
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)

Simplify boolean assignment and use const.

The boolean assignment can be simplified, and const should be used instead of let as the variable is not reassigned.

Consider refactoring this line as follows:

const dis = typeOfCall === "view";

This change improves readability and adheres to best practices for variable declarations.

🧰 Tools
🪛 Biome

[error] 35-35: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)


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

'dis' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)

}) => {
let dis = typeOfCall==="view"?true:false;
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Simplify the dis variable declaration.

The current implementation can be improved for better readability and consistency with best practices:

  1. Use const instead of let as the variable is never reassigned.
  2. Simplify the boolean expression to avoid unnecessary use of a ternary operator.

Apply this change:

-  let dis = typeOfCall==="view"?true:false;
+  const dis = typeOfCall === "view";

This change addresses the following static analysis hints:

  • Unnecessary use of boolean literals in conditional expression.
  • Use of let for a variable that is only assigned once.
📝 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
let dis = typeOfCall==="view"?true:false;
const dis = typeOfCall === "view";
🧰 Tools
🪛 Biome

[error] 34-34: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)


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

'dis' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)

Comment on lines +138 to +142
typeOfCall
}) => {
// const [optionTitle, setOptionTitle] = useState(title);
const [isFocused, setIsFocused] = useState(false);
let dis = typeOfCall==="view"?true:false;
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Simplify the dis variable assignment and improve code structure

The dis variable assignment can be simplified, and the code structure can be improved for better readability.

Consider updating the code as follows:

export const RadioButtonOption = ({
  // ... other props
  handleOptionComment,
  typeOfCall
}) => {
  const [isFocused, setIsFocused] = useState(false);
- let dis = typeOfCall==="view"?true:false;
+ const dis = typeOfCall === "view";

  return (
    <div>
      {/* Component JSX */}
    </div>
  );
};

This change simplifies the dis assignment and improves the overall code structure by grouping the useState and dis assignment together.

📝 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
typeOfCall
}) => {
// const [optionTitle, setOptionTitle] = useState(title);
const [isFocused, setIsFocused] = useState(false);
let dis = typeOfCall==="view"?true:false;
typeOfCall
}) => {
// const [optionTitle, setOptionTitle] = useState(title);
const [isFocused, setIsFocused] = useState(false);
const dis = typeOfCall === "view";
🧰 Tools
🪛 Biome

[error] 142-142: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)


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

'dis' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)

Comment on lines 20 to 33
const [viewData, setViewData] = useState(
// [
// {
// id: crypto.randomUUID(),
// parentId: null,
// level: 1,
// key: 1,
// title: null,
// type: { code: "SingleValueList" },
// value: null,
// isRequired: false
// }
// ]
null
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-out code to clean up the file

There are large blocks of commented-out code that can be removed to improve code readability and maintainability.

Consider removing the commented code from these sections to keep the codebase clean.

Also applies to: 131-144

Comment on lines 75 to 76
console.log("matched item", matchedItem);
// If a match is found, assign the 'code' to 'checklistcode'
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 console.log statements before production

console.log statements are useful during development but should be removed or disabled in production code to prevent cluttering the console and potentially leaking sensitive information.

Remove or comment out these console.log statements.

Also applies to: 82-83, 97-97, 114-114, 121-121, 145-145

value={pair.value} // Dynamically set the value
// style={{ fontSize: "16px", fontWeight: "bold" }} // Optional: customize styles
/>
{index !== fieldPairs.length - 1 && <div style={{ height: "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.

🛠️ Refactor suggestion

Self-close JSX elements without children

JSX elements without children can be self-closed to improve code readability and adhere to JSX conventions.

Apply this change:

- {index !== fieldPairs.length - 1 && <div style={{ height: "1rem" }}></div>}
+ {index !== fieldPairs.length - 1 && <div style={{ height: "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
{index !== fieldPairs.length - 1 && <div style={{ height: "1rem" }}></div>}
{index !== fieldPairs.length - 1 && <div style={{ height: "1rem" }} />}
🧰 Tools
🪛 Biome

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

}
}
catch (error) {
}
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

Handle errors in the catch block appropriately

The catch block is empty, which means any errors thrown in the try block will be silently ignored. It's important to handle errors or at least log them to aid in debugging.

You can log the error as follows:

catch (error) {
+   console.error("Error fetching data:", error);
}
📝 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
}
}
catch (error) {
console.error("Error fetching data:", error);
}

Comment on lines 175 to 185
<div>
<ViewCardFieldPair
key={index} // Provide a unique key for each item
className=""
inline
label={pair.label} // Dynamically set the label
value={pair.value} // Dynamically set the value
// style={{ fontSize: "16px", fontWeight: "bold" }} // Optional: customize styles
/>
{index !== fieldPairs.length - 1 && <div style={{ height: "1rem" }}></div>}
</div>
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

Add a unique key prop to elements in list iterations

When rendering lists in React, each top-level element in an iteration should have a unique key prop to help React identify which items have changed, are added, or are removed.

Apply this change:

{fieldPairs.map((pair, index) => (
-    <div>
+    <div key={index}>
📝 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>
<ViewCardFieldPair
key={index} // Provide a unique key for each item
className=""
inline
label={pair.label} // Dynamically set the label
value={pair.value} // Dynamically set the value
// style={{ fontSize: "16px", fontWeight: "bold" }} // Optional: customize styles
/>
{index !== fieldPairs.length - 1 && <div style={{ height: "1rem" }}></div>}
</div>
{fieldPairs.map((pair, index) => (
<div key={index}>
<ViewCardFieldPair
key={index} // Provide a unique key for each item
className=""
inline
label={pair.label} // Dynamically set the label
value={pair.value} // Dynamically set the value
// style={{ fontSize: "16px", fontWeight: "bold" }} // Optional: customize styles
/>
{index !== fieldPairs.length - 1 && <div style={{ height: "1rem" }}></div>}
</div>
))}
🧰 Tools
🪛 Biome

[error] 184-184: 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] 175-175: 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)

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 1987af5 and 83283b0.

📒 Files selected for processing (14)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/CampaignCard.js (1 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/CreateQuestion.js (14 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/CreateQuestionContext.js (6 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/MobileChecklist.js (2 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/configs/UICustomizations.js (7 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/configs/checklistSearchConfig.js (3 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/services/updateChecklistService.js (1 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/hooks/useUpdateChecklist.js (1 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/CreateChecklist.js (15 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/SearchChecklist.js (8 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/UpdateChecklist.js (1 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/ViewChecklist.js (1 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/index.js (4 hunks)
🧰 Additional context used
📓 Path-based instructions (14)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/CampaignCard.js (1)

Pattern **/*.js: check

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

Pattern **/*.js: check

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

Pattern **/*.js: check

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

Pattern **/*.js: check

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

Pattern **/*.js: check

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

Pattern **/*.js: check

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/hooks/services/updateChecklistService.js (1)

Pattern **/*.js: check

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

Pattern **/*.js: check

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

Pattern **/*.js: check

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

Pattern **/*.js: check

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

Pattern **/*.js: check

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

Pattern **/*.js: check

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

Pattern **/*.js: check

🪛 Biome
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/CreateQuestion.js

[error] 343-343: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)


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

'dis' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


[error] 350-350: 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/CreateQuestionContext.js

[error] 57-57: This code is unreachable

(lint/correctness/noUnreachable)


[error] 74-74: This code is unreachable

(lint/correctness/noUnreachable)


[error] 140-140: This code is unreachable

(lint/correctness/noUnreachable)

health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/configs/UICustomizations.js

[error] 145-145: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


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

Unsafe fix: Use a template literal.

(lint/style/useTemplate)


[error] 151-151: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


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

Unsafe fix: Use a template literal.

(lint/style/useTemplate)


[error] 157-157: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 159-166: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 168-168: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 240-240: This code is unreachable

... because this statement will return from the function beforehand

(lint/correctness/noUnreachable)


[error] 271-271: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 276-276: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 277-291: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 292-305: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 306-315: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 309-309: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 274-274: This code is unreachable

... because this statement will return from the function beforehand

(lint/correctness/noUnreachable)

health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/hooks/useUpdateChecklist.js

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

'val' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)

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

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

Unsafe fix: Use a template literal.

(lint/style/useTemplate)


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

Unsafe fix: Use a template literal.

(lint/style/useTemplate)


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

'temp_data' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'clt' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'locale' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'data_mdms' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'temp_data' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'formatted_data' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'formattedString' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


[error] 625-625: 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] 639-639: 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/UpdateChecklist.js

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

Unsafe fix: Use a template literal.

(lint/style/useTemplate)


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

Unsafe fix: Use a template literal.

(lint/style/useTemplate)


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

Unsafe fix: Use a template literal.

(lint/style/useTemplate)


[error] 459-459: 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] 473-473: 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] 29-30: A global variable should not be reassigned.

Assigning to a global variable can override essential functionality.

(lint/suspicious/noGlobalAssign)


[error] 246-246: Shouldn't redeclare 'createQuestionObject'. Consider to delete it or rename it.

'createQuestionObject' is defined here:

(lint/suspicious/noRedeclare)


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

'clt' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'locale' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'checklistName' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'temp_data' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'formatted_data' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'nvd' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'moduleChecklist' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'roleTemp' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'formattedString' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'formattedStringTemp' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


[error] 298-298: This let declares some variables that are only assigned once.

'codes' is never reassigned.

'local' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'final_payload' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'roleTemp' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)

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

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

Unsafe fix: Use a template literal.

(lint/style/useTemplate)


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

Unsafe fix: Use a template literal.

(lint/style/useTemplate)


[error] 243-243: 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] 258-258: 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] 18-18: This let declares a variable that is only assigned once.

'clt' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'checklistName' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'temp_data' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'formatted_data' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'nvd' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

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

(lint/correctness/noChildrenProp)


[error] 219-227: 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] 228-236: 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] 249-249: 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] 289-300: 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/index.js

[error] 38-38: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)


[error] 63-63: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)


[error] 66-66: This property value named path is later overwritten by an object member with the same name.

Overwritten with this value.

If an object property with the same name is defined multiple times (except when combining a getter with a setter), only the last definition makes it into the object and previous definitions are ignored.
Unsafe fix: Remove this property value named path

(lint/suspicious/noDuplicateObjectKeys)


[error] 67-67: This property value named content is later overwritten by an object member with the same name.

Overwritten with this value.

If an object property with the same name is defined multiple times (except when combining a getter with a setter), only the last definition makes it into the object and previous definitions are ignored.
Unsafe fix: Remove this property value named content

(lint/suspicious/noDuplicateObjectKeys)


[error] 68-68: This property value named show is later overwritten by an object member with the same name.

Overwritten with this value.

If an object property with the same name is defined multiple times (except when combining a getter with a setter), only the last definition makes it into the object and previous definitions are ignored.
Unsafe fix: Remove this property value named show

(lint/suspicious/noDuplicateObjectKeys)


[error] 68-68: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)

🔇 Additional comments (29)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/hooks/useUpdateChecklist.js (3)

1-2: LGTM: Imports are correct and follow best practices.

The imports are appropriate for the hook's functionality. Using react-query for managing server state is a good practice in React applications.


13-13: LGTM: Export statement is correct.

The default export of the useUpdateChecklist hook follows common practices for React hooks.


1-13: Overall assessment: Good implementation with minor improvements suggested.

The useUpdateChecklist hook is well-structured and correctly integrated into the campaign management module. The suggested improvements will enhance code quality and maintainability. Once the refactoring suggestions are applied, this implementation will be solid and follow best practices for React hooks and react-query usage.

🧰 Tools
🪛 Biome

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

'val' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)

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

17-18: LGTM: Appropriate module export

The default export of the updateChecklistService function is correct and follows standard practices. This allows for easy importing and usage of the function in other parts of the application.

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

16-16: Approve consistent prop usage.

The change to use checklistRole in the rendered title is consistent with the prop rename. This ensures that the component correctly displays the intended information.


Line range hint 1-42: Overall assessment: Improvements with minor suggestions.

The changes to the MobileChecklist component enhance its clarity and functionality. The prop renaming and additional filtering for active questions are positive improvements. Consider the suggested simplification and ensure thorough testing to verify that these changes don't unexpectedly alter the component's behavior or user experience.


5-5: 🛠️ Refactor suggestion

Simplify condition and verify impact on displayed questions.

The additional filter for active questions is a good improvement. However, the condition can be simplified:

- const topLevelQuestions = questions.filter(q => q.parentId === null && (q.isActive === true));
+ const topLevelQuestions = questions.filter(q => q.parentId === null && q.isActive);

Also, please verify that this change doesn't unexpectedly reduce the number of displayed questions.


3-3: Approve prop rename and verify usage.

The renaming of checklistName to checklistRole improves clarity. However, ensure that all instances where this component is used are updated accordingly.

Run the following script to verify the component usage:

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

17-17: LGTM: New hook import added correctly.

The import statement for useUpdateChecklist is correctly placed and follows the established pattern for importing hooks in this file.


41-41: LGTM: New hook correctly added to the campaign object.

The useUpdateChecklist hook is appropriately added to the campaign object, making it available for use in the campaign management module. The placement is consistent with the existing structure.


Line range hint 17-41: Overall: Changes are well-implemented and consistent.

The addition of the useUpdateChecklist hook is properly implemented. It's correctly imported and added to the campaign object, following the established patterns in this file. These changes enhance the functionality of the campaign management module by making the new hook available for use.

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

76-76: New link for "VIEW_CHECKLIST" added successfully.

The new link object for "VIEW_CHECKLIST" has been correctly added to the links array. It follows the existing pattern for link objects, including the use of the translation function and proper role assignment.

However, as mentioned in a previous review comment, consider using dynamic values for URL parameters in the link to improve reusability and flexibility. This suggestion remains valid for this new link as well.

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

93-93: LGTM: Addition of campaignName to checklistSearchConfig.

The addition of campaignName to the additionalDetails of checklistSearchConfig is consistent with the new state variable. This change allows the search configuration to include the campaign name in its details.


165-165: LGTM: Addition of translation prop to Dropdown components.

The addition of the t prop to the Dropdown components is a good practice for internationalization. This change ensures that the dropdown components can utilize the translation function directly, improving the localization capabilities of the application.

Also applies to: 179-179


7-7: Verify usage of imported UICustomizations module.

The UICustomizations module is imported but not used in the visible code. If it's not used elsewhere in the component, consider removing this import to avoid unused imports.

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

15-16: LGTM: New component imports added correctly.

The new imports for ViewChecklist and UpdateChecklist components are correctly placed and follow proper naming conventions.


137-137: LGTM: New PrivateRoute for ViewChecklist added correctly.

The new PrivateRoute for the ViewChecklist component is properly structured and consistent with the existing routing pattern.


138-138: LGTM: New PrivateRoute for UpdateChecklist added correctly.

The new PrivateRoute for the UpdateChecklist component is properly structured and consistent with the existing routing pattern.


Line range hint 1-148: Summary of changes and recommendations.

The changes to this file enhance the campaign management module by adding new routes and breadcrumb items for viewing and updating checklists. The modifications are generally well-implemented, with a few minor issues:

  1. The breadcrumb visibility logic can be simplified for better readability.
  2. There's a duplicate object key issue in the new breadcrumb items that needs to be resolved.
  3. Boolean expressions in the breadcrumb items can be simplified.

Once these small corrections are made, the changes will significantly improve the module's functionality and maintain code quality standards.

🧰 Tools
🪛 Biome

[error] 58-58: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)


[error] 63-63: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)


[error] 66-66: This property value named path is later overwritten by an object member with the same name.

Overwritten with this value.

If an object property with the same name is defined multiple times (except when combining a getter with a setter), only the last definition makes it into the object and previous definitions are ignored.
Unsafe fix: Remove this property value named path

(lint/suspicious/noDuplicateObjectKeys)


[error] 67-67: This property value named content is later overwritten by an object member with the same name.

Overwritten with this value.

If an object property with the same name is defined multiple times (except when combining a getter with a setter), only the last definition makes it into the object and previous definitions are ignored.
Unsafe fix: Remove this property value named content

(lint/suspicious/noDuplicateObjectKeys)


[error] 68-68: This property value named show is later overwritten by an object member with the same name.

Overwritten with this value.

If an object property with the same name is defined multiple times (except when combining a getter with a setter), only the last definition makes it into the object and previous definitions are ignored.
Unsafe fix: Remove this property value named show

(lint/suspicious/noDuplicateObjectKeys)


[error] 68-68: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)


[error] 71-71: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)

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

2-2: Good use of dynamic tenant ID retrieval

Utilizing Digit.ULBService.getCurrentTenantId() to assign tenantId enhances the flexibility and scalability of the application by dynamically setting the tenant ID.


16-16: Verify the correctness of the schemaCode value

Please confirm that the schemaCode "HCM-ADMIN-CONSOLE.Checklist-Templates" is accurate and corresponds to the intended MDMS schema. An incorrect schemaCode may lead to unsuccessful API calls or data retrieval issues.


74-78: Confirm the removal of "UNIQUE_IDENTIFIER" column

The "UNIQUE_IDENTIFIER" column in the search results has been commented out. If this column is important for identifying records uniquely, consider if it should remain in the results. Ensure that its removal does not affect functionality or user ability to distinguish between records.


102-102: Verify the updated resultsJsonPath

The resultsJsonPath has been changed to "mdms". Please confirm that the API response structure matches this path and that the data will be correctly mapped to the UI components.


22-22: 🧹 Nitpick (assertive)

Reconsider pagination limit reduction to 5

Reducing the limit from a higher value to 5 may impact user experience by limiting the number of results displayed per page. If the dataset is large, users might need to navigate through many pages. Consider whether this aligns with the intended functionality or if a higher limit would be more appropriate.

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

343-343: Variable name dis is not descriptive

As previously mentioned, the variable dis could be renamed to isViewMode or isDisabled for better readability.

🧰 Tools
🪛 Biome

[error] 343-343: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)


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

'dis' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)

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

50-55: Verify 'campaignName' is not null

The campaignName retrieved from URL parameters might be null if the parameter is absent. Ensure it has a valid value before using it in subsequent code.


Line range hint 744-773: Ensure consistent properties when pushing to history

When using window.history.pushState, ensure the properties passed in the state object are consistent across different cases.


3-4: 🧹 Nitpick (assertive)

Consolidate imports from 'react-router-dom'

You can combine imports from 'react-router-dom' into a single statement to improve code readability.

Apply this diff:

- import { Link } from "react-router-dom";
- import { useHistory, useLocation } from 'react-router-dom';
+ import { Link, useHistory, useLocation } from "react-router-dom";

Likely invalid or redundant comment.

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

28-28: ⚠️ Potential issue

'module' Is Used Before It Is Defined

The variable module is used as an argument before it is assigned a value. This will result in module being undefined during the function call.

To fix this, ensure that module is defined before it is used.

Apply this diff to update the code:

+const module = "hcm-checklist";
 const { mutateAsync: localisationMutateAsync } = Digit.Hooks.campaign.useUpsertLocalisation(tenantId, module, locale);
-module = "hcm-checklist";

Alternatively, adjust the order of declarations accordingly.

Likely invalid or redundant comment.

Comment on lines +4 to +11
const useUpdateChecklist = (tenantId) => {
return useMutation((reqData) => {
let val = updateChecklistService(reqData, tenantId);
val.then(result => {
})
return val;
});
};
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Simplify the hook implementation and address static analysis suggestions.

The hook structure is correct, but there are a few improvements we can make:

  1. Remove the unnecessary empty then block.
  2. Use const instead of let for the val declaration, as suggested by the static analysis tool.
  3. Simplify the mutation function by directly returning the service call.

Here's the suggested implementation:

const useUpdateChecklist = (tenantId) => {
  return useMutation((reqData) => updateChecklistService(reqData, tenantId));
};

This refactored version is more concise and addresses the static analysis suggestion while maintaining the same functionality.

🧰 Tools
🪛 Biome

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

'val' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)

Comment on lines +1 to +2
const updateChecklistService = async (req, tenantId) => {
try {
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)

LGTM with a minor observation

The function signature and error handling structure look good. However, the tenantId parameter is not used within the function. Consider removing it if it's not needed, or use it if it's intended to be part of the request.

Also applies to: 15-15

Comment on lines +3 to +9
const response = await Digit.CustomService.getResponse({
url: "/service-request/service/definition/v1/_update",
body: {
ServiceDefinition: req,
},
});
return { success: true, data: response }; // Indicate success
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)

Consider adding input validation

The API call structure looks good. However, it might be beneficial to add some validation for the req parameter before using it in the API call. This could help prevent potential issues if the req object is not in the expected format.

Consider adding a validation check like this:

if (!req || typeof req !== 'object') {
  throw new Error('Invalid request object');
}

Comment on lines +10 to +14
} catch (error) {
const errorCode = error?.response?.data?.Errors[0]?.code || "Unknown error";
const errorDescription = error?.response?.data?.Errors[0]?.description || "An error occurred";
return { success: false, error: { code: errorCode, description: errorDescription } }; // Indicate failure
}
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)

Robust error handling, with a suggestion

The error handling is well-implemented, using optional chaining and providing default values. This approach effectively prevents undefined errors and ensures meaningful error information is always returned.

Consider adding a more generic fallback for cases where the error object might not have the expected structure:

const errorCode = error?.response?.data?.Errors?.[0]?.code || error.message || "Unknown error";
const errorDescription = error?.response?.data?.Errors?.[0]?.description || error.toString() || "An error occurred";

This change would capture a wider range of potential error formats.

@@ -13,10 +13,15 @@ const SearchChecklist = () => {
const tenantId = Digit.ULBService.getCurrentTenantId();
const searchParams = new URLSearchParams(location.search);
const id = searchParams.get("campaignId");
const [campaignName, setCampaignName] = useState(searchParams.get("name"));
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

Refactor useEffect hook for campaignName.

The useEffect hook appears to be redundant as it's setting campaignName to its current value. Additionally, the dependency array is missing brackets. Consider removing this hook if it's not needed, or refactor it to perform necessary side effects.

If you decide to keep the hook, ensure the dependency array is properly formatted:

useEffect(() => {
  // Perform side effects here if needed
}, [campaignName]);

Also applies to: 21-23

Comment on lines +229 to +243
function createQuestionObject(item, tenantId) {
const questionObject = {
tenantId: tenantId,
code: idCodeMap[item.id], // Use the idCodeMap to get the code
dataType: item?.type?.code,
values: item?.value,
required: item?.isRequired,
isActive: item?.isActive,
reGex: item?.isRegex ? item?.regex?.regex : null,
order: item?.key,
additionalDetails: item // Complete object goes here
};

return questionObject;
}
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 Unused Function 'createQuestionObject'

The function createQuestionObject defined here is not used in the code. Consider removing it to clean up the codebase.

Apply this diff to remove the unused function:

-function createQuestionObject(item, tenantId) {
-    const questionObject = {
-        tenantId: tenantId,
-        code: idCodeMap[item.id],  // Use the idCodeMap to get the code
-        dataType: item?.type?.code,
-        values: item?.value,
-        required: item?.isRequired,
-        isActive: item?.isActive,
-        reGex: item?.isRegex ? item?.regex?.regex : null,
-        order: item?.key,
-        additionalDetails: item // Complete object goes here
-    };
-
-    return questionObject;
-}
📝 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
function createQuestionObject(item, tenantId) {
const questionObject = {
tenantId: tenantId,
code: idCodeMap[item.id], // Use the idCodeMap to get the code
dataType: item?.type?.code,
values: item?.value,
required: item?.isRequired,
isActive: item?.isActive,
reGex: item?.isRegex ? item?.regex?.regex : null,
order: item?.key,
additionalDetails: item // Complete object goes here
};
return questionObject;
}

const rlt = searchParams.get("role");
const roleLocal = (!rlt.startsWith("ACCESSCONTROL_ROLES_ROLES_")) ? "ACCESSCONTROL_ROLES_ROLES_"+rlt : rlt;
const checklistType = searchParams.get("checklistType");
let clt = searchParams.get("checklistType");
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)

Declare 'clt' with 'const' Instead of 'let'

The variable 'clt' is never reassigned after its initial assignment. Consider declaring it with 'const' for better code safety.

Apply this diff to update the code:

-let clt = searchParams.get("checklistType");
+const clt = searchParams.get("checklistType");
📝 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
let clt = searchParams.get("checklistType");
const clt = searchParams.get("checklistType");
🧰 Tools
🪛 Biome

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

'clt' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)




const name = t(`${checklistTypeLocal}`) + " " + t(`${roleLocal}`);
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 Template Literals Instead of String Concatenation

Consider using template literals instead of string concatenation for better readability.

Apply this diff to update the code:

-const name = t(`${checklistTypeLocal}`) + " " + t(`${roleLocal}`);
+const name = `${t(`${checklistTypeLocal}`)} ${t(`${roleLocal}`)}`;
📝 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 name = t(`${checklistTypeLocal}`) + " " + t(`${roleLocal}`);
const name = `${t(`${checklistTypeLocal}`)} ${t(`${roleLocal}`)}`;
🧰 Tools
🪛 Biome

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

Unsafe fix: Use a template literal.

(lint/style/useTemplate)

}

// Helper function to generate the desired object format for each question
function createQuestionObject(item, tenantId, idCodeMap) {
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

Avoid Redeclaring Function 'createQuestionObject'

The function createQuestionObject is redeclared, which can cause confusion and potential bugs. Consider renaming one of the functions or consolidating them if they serve the same purpose.

Apply this diff to rename the second function:

-function createQuestionObject(item, tenantId, idCodeMap) {
+function createQuestionObjectWithIdCodeMap(item, tenantId, idCodeMap) {

Then, make sure to update all references to this function accordingly.

📝 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
function createQuestionObject(item, tenantId, idCodeMap) {
function createQuestionObjectWithIdCodeMap(item, tenantId, idCodeMap) {
🧰 Tools
🪛 Biome

[error] 246-246: Shouldn't redeclare 'createQuestionObject'. Consider to delete it or rename it.

'createQuestionObject' is defined here:

(lint/suspicious/noRedeclare)

let locale = Digit?.SessionStorage.get("initData")?.selectedLanguage || "en_IN";
const { mutateAsync } = Digit.Hooks.campaign.useUpdateChecklist(tenantId);
const { mutateAsync: localisationMutateAsync } = Digit.Hooks.campaign.useUpsertLocalisation(tenantId, module, locale);
module = "hcm-checklist";
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

Declare Variable 'module' Before Use

The variable module is assigned without prior declaration. This can lead to unintended global variable assignment or a ReferenceError. Consider declaring it with let or const.

Apply this diff to update the code:

-module = "hcm-checklist";
+const module = "hcm-checklist";
📝 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
module = "hcm-checklist";
const module = "hcm-checklist";
🧰 Tools
🪛 Biome

[error] 29-30: A global variable should not be reassigned.

Assigning to a global variable can override essential functionality.

(lint/suspicious/noGlobalAssign)

Copy link
Collaborator

@jagankumar-egov jagankumar-egov left a comment

Choose a reason for hiding this comment

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

use custom api hook

useEffect(() => {

const callSearch = async () => {
const res = await Digit.CustomService.getResponse({
Copy link
Collaborator

Choose a reason for hiding this comment

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

use custom api hook for loading checlist configured and select function with this
data to detstaructue
if (res?.ServiceDefinitions?.[0]?.attributes) {
setSearching(false);
let temp_data = res?.ServiceDefinitions?.[0]?.attributes
let formatted_data = temp_data.map((item) => item.additionalDetails);
let nvd = formatted_data.filter((value, index, self) =>
index === self.findIndex((t) => t.id === value.id)
);
setViewData(nvd);

            }

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

🧹 Outside diff range comments (1)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/configs/UICustomizations.js (1)

Line range hint 377-396: Refactor duplicated preProcess functions to improve maintainability

The preProcess functions in MyCampaignConfigOngoing, MyCampaignConfigCompleted, MyCampaignConfigUpcoming, MyCampaignConfigDrafts, and MyCampaignConfigFailed configurations share a significant amount of duplicated code. This duplication can make maintenance harder and increase the risk of inconsistencies.

Extract the shared logic into a reusable function. Here's how you might refactor:

+ // Define a shared preProcess function
+ const sharedPreProcess = (data, statusArray, dateConfig = {}) => {
+   const tenantId = Digit.ULBService.getCurrentTenantId();
+   data.body = { RequestInfo: data.body.RequestInfo };
+   const { limit, offset } = data?.state?.tableForm || {};
+   const { campaignName, campaignType } = data?.state?.searchForm || {};
+   data.body.CampaignDetails = {
+     tenantId: tenantId,
+     status: statusArray,
+     createdBy: Digit.UserService.getUser().info.uuid,
+     pagination: {
+       sortBy: "createdTime",
+       sortOrder: "desc",
+       limit: limit,
+       offset: offset,
+     },
+     ...dateConfig,
+   };
+   if (campaignName) {
+     data.body.CampaignDetails.campaignName = campaignName;
+   }
+   if (campaignType) {
+     data.body.CampaignDetails.projectType = campaignType?.[0]?.code;
+   }
+   delete data.body.custom;
+   delete data.body.inbox;
+   delete data.params;
+   return data;
+ };
  
  // Use the shared function in each configuration
  MyCampaignConfigOngoing: {
-   preProcess: (data, additionalDetails) => {
-     // existing code
-   },
+   preProcess: (data, additionalDetails) => {
+     return sharedPreProcess(data, ["creating", "created"], {
+       campaignsIncludeDates: true,
+       startDate: Digit.Utils.pt.convertDateToEpoch(new Date().toISOString().split("T")[0], "daystart"),
+       endDate: Digit.Utils.pt.convertDateToEpoch(new Date().toISOString().split("T")[0]),
+     });
+   },
    // ... other properties
  },

  // Repeat for other configurations with appropriate parameters

Also applies to: 515-534, 639-658, 745-773, 897-916

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 36905ce and e467ab7.

📒 Files selected for processing (2)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/configs/UICustomizations.js (7 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/index.js (4 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/configs/UICustomizations.js (1)

Pattern **/*.js: check

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

Pattern **/*.js: check

🪛 Biome
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/configs/UICustomizations.js

[error] 145-145: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


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

Unsafe fix: Use a template literal.

(lint/style/useTemplate)


[error] 151-151: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


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

Unsafe fix: Use a template literal.

(lint/style/useTemplate)


[error] 157-157: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 159-166: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 168-168: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 240-240: This code is unreachable

... because this statement will return from the function beforehand

(lint/correctness/noUnreachable)


[error] 271-271: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 276-276: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 277-291: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 292-305: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 306-315: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 309-309: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 274-274: This code is unreachable

... because this statement will return from the function beforehand

(lint/correctness/noUnreachable)

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

[error] 38-38: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)


[error] 63-63: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)


[error] 68-68: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)

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

15-16: LGTM: New component imports added correctly.

The import statements for ViewChecklist and UpdateChecklist components are correctly added and consistent with the existing import style.


144-145: LGTM: New routes for checklist view and update added correctly.

The new PrivateRoute components for ViewChecklist and UpdateChecklist are correctly implemented and consistent with the existing route structure.


Line range hint 1-154: LGTM: Overall changes are well-integrated and consistent.

The additions for checklist viewing and updating functionality are well-integrated into the existing campaign management flow. The file structure remains consistent, and no existing functionality appears to be affected by these changes.

🧰 Tools
🪛 Biome

[error] 58-58: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)


[error] 63-63: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)


[error] 68-68: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)

@@ -33,7 +35,7 @@ const CampaignBreadCrumb = ({ location, defaultPath }) => {
{
path: pathVar === "my-campaign" ? "" : `/${window?.contextPath}/employee/campaign/my-campaign`,
content: t("MY_CAMPAIGN"),
show: pathVar === "my-campaign" || pathVar === "checklist/search" || pathVar === "checklist/create" ? true : false,
show: pathVar === "my-campaign" || pathVar === "checklist/search" || pathVar === "checklist/create" || pathVar === "checklist/view" || pathVar === "checklist/update" ? true : false,
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)

Approve breadcrumb updates with suggested simplifications.

The breadcrumb updates for checklist-related paths are correct. However, the boolean expressions can be simplified for better readability.

Consider these changes:

  1. For the "MY_CAMPAIGN" breadcrumb (line 38):
show: ["my-campaign", "checklist/search", "checklist/create", "checklist/view", "checklist/update"].includes(pathVar),
  1. For the new checklist breadcrumbs (lines 60-69):
{
  path: "",
  content: t("ACTION_VIEW_CHECKLIST"),
  show: pathVar === "checklist/view"
},
{
  path: "",
  content: t("ACTION_UPDATE_CHECKLIST"),
  show: pathVar === "checklist/update"
}

These simplifications improve code readability and maintainability.

Also applies to: 60-69

🧰 Tools
🪛 Biome

[error] 38-38: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)

Comment on lines +21 to +105
const apiCache = {};
const rowDataCache = {};


export const UICustomizations = {
MyChecklistSearchConfig: {


preProcess: (data, additionalDetails) => {
if (data?.state?.searchForm?.Role?.code) {
let ro = data.state.searchForm.Role.code;
ro = ro.replace("ACCESSCONTROL_ROLES_ROLES_", "");
data.body.MdmsCriteria.filters.role = ro;
}
if (data?.state?.searchForm?.Type?.list) {
let ty = data.state.searchForm.Type.list;
ty = ty.replace("HCM_CHECKLIST_TYPE_", "");
data.body.MdmsCriteria.filters.checklistType = ty;
}
if (data?.state?.searchForm && Object.keys(data.state.searchForm).length === 0) {
data.body.MdmsCriteria.filters = {};
}
data.params.limit = 5;
data.params.offset = 0;

// if (additionalDetails?.campaignName) setCampaignName(additionalDetails?.campaignName);
return data;
},


additionalCustomizations: (row, key, column, value, searchResult) => {
const { t } = useTranslation();
const history = useHistory();
const location = useLocation();
const searchParams = new URLSearchParams(location.search);
const campaignName = searchParams.get("name");
const tenantId = Digit.ULBService.getCurrentTenantId();
const [checklistTypeCode, setChecklistTypeCode] = useState(null);
let checklistType = data?.state?.searchForm?.Type?.list;
const reqCriteria = {
url: `/localization/messages/v1/_search`,
body:{
tenantId: tenantId
},
params: {
locale: "en_MZ",
tenantId: tenantId,
module: "hcm-campaignmanager"
},

const cl_code = row?.data?.checklistType.replace("HCM_CHECKLIST_TYPE_", "");
const role_code = row?.data?.role.replace("ACCESSCONTROL_ROLES_ROLES_", "");
const serviceCode = `${campaignName}.${cl_code}.${role_code}`;

// Check if we've already processed this row
if (!rowDataCache[serviceCode]) {
rowDataCache[serviceCode] = {
isLoading: true,
isActive: false,
attributes: null,
fetchPromise: null
};

const fetchData = async () => {
if (apiCache[serviceCode]) {
return apiCache[serviceCode];
}

try {
const res = await Digit.CustomService.getResponse({
url: "/service-request/service/definition/v1/_search",
params: {},
body: {
ServiceDefinitionCriteria: {
"tenantId": tenantId,
"code": [serviceCode]
},
includeDeleted: true
},
});
apiCache[serviceCode] = res;
return res;
} catch (error) {
// console.error("Error fetching data:", error);
return null;
}
};

// Start the fetch if it hasn't been started yet
if (!rowDataCache[serviceCode].fetchPromise) {
rowDataCache[serviceCode].fetchPromise = fetchData().then(res => {
if (res?.ServiceDefinitions?.[0]) {
rowDataCache[serviceCode].attributes = res.ServiceDefinitions[0].attributes;
rowDataCache[serviceCode].isActive = res.ServiceDefinitions[0].isActive;
}
rowDataCache[serviceCode].isLoading = false;
});
}
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

Avoid using shared mutable state with module-level variables

The apiCache and rowDataCache variables are declared at the module level, making them shared across all instances of the component. This can lead to unexpected behavior if multiple instances are rendered simultaneously, as state from one instance may interfere with another.

Consider moving apiCache and rowDataCache inside the component or function where they are used. Alternatively, use a state management solution like React's Context API or Redux to manage shared state appropriately.

Comment on lines +50 to +55
additionalCustomizations: (row, key, column, value, searchResult) => {
const { t } = useTranslation();
const history = useHistory();
const location = useLocation();
const searchParams = new URLSearchParams(location.search);
const campaignName = searchParams.get("name");
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

Ensure React Hooks are called at the top level of React function components

React Hooks like useTranslation, useHistory, and useLocation should be called at the top level of React function components or custom Hooks. Calling them inside regular functions or conditionally can cause unexpected behavior.

Verify that additionalCustomizations is a React function component or a custom Hook. If it's a regular function, consider refactoring it into a custom Hook or passing the necessary values as parameters.

Comment on lines +114 to +117
rowDataCache[serviceCode].fetchPromise?.then(() => {
// This will trigger a re-render once the data is available
});

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 unnecessary empty .then() block

The .then() block attached to rowDataCache[serviceCode].fetchPromise is empty and does not perform any action. This does not trigger a re-render as intended.

Remove the empty .then() block or implement a state update inside it to trigger a re-render when the data is available.

Comment on lines +428 to +439
window.history.pushState(
{
name: row?.campaignName,
data: row,
projectId: row?.projectId,
},
"",
`/${window.contextPath}/employee/campaign/checklist/search?name=${row?.campaignName}&campaignId=${row?.id}`
);
const navEvent1 = new PopStateEvent("popstate");
window.dispatchEvent(navEvent1);
break;
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

Handle potential undefined values for row properties

When constructing URLs or using row properties, ensure that the values are defined to prevent runtime errors. Properties like row?.campaignName, row?.id, and row?.projectId might be undefined.

Add checks or default values to handle cases where these properties might be undefined.

- name: row?.campaignName,
- data: row,
- projectId: row?.projectId,
+ name: row?.campaignName || '',
+ data: row || {},
+ projectId: row?.projectId || '',

Also applies to: 760-772

Comment on lines +157 to +175
const [localIsActive, setLocalIsActive] = useState(rowDataCache[serviceCode].isActive);

const toggle = async () => {
const newStatus = !localIsActive;
const res = await updateServiceDefinition(newStatus);
if (res) {
rowDataCache[serviceCode].isActive = newStatus;
setLocalIsActive(newStatus);
}
};

const switchText = localIsActive ? "Active" : "Inactive";
return (
<Switch
isCheckedInitially={isActive ? true : false}
isCheckedInitially={localIsActive}
label={switchText}
onToggle={toggle} // Passing the function reference here
onToggle={toggle}
/>
</>
);
);
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

Avoid using Hooks inside switch cases

React Hooks like useState should not be called conditionally or inside loops, conditions, or nested functions. Placing Hooks inside a switch case can lead to violations of the Rules of Hooks.

Refactor the code to ensure that all Hooks are called at the top level of the React function component.

🧰 Tools
🪛 Biome

[error] 157-157: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 159-166: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


[error] 168-168: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)

const downloadExcelTemplate = async () => {
const res = await generateFile();
const resFile = await generateTemplate();
if (resFile && resFile?.GeneratedResource?.[0]?.fileStoreid) {
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Simplify condition using optional chaining

You can simplify the condition in line 309 by utilizing optional chaining to improve readability.

Apply this diff:

- if (resFile && resFile?.GeneratedResource?.[0]?.fileStoreid) {
+ if (resFile?.GeneratedResource?.[0]?.fileStoreid) {
📝 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
if (resFile && resFile?.GeneratedResource?.[0]?.fileStoreid) {
if (resFile?.GeneratedResource?.[0]?.fileStoreid) {
🧰 Tools
🪛 Biome

[error] 309-309: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between e467ab7 and bb447db.

📒 Files selected for processing (2)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/UpdateChecklist.js (1 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/ViewChecklist.js (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/UpdateChecklist.js (1)

Pattern **/*.js: check

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

Pattern **/*.js: check

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

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

Unsafe fix: Use a template literal.

(lint/style/useTemplate)


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

Unsafe fix: Use a template literal.

(lint/style/useTemplate)


[error] 113-113: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)


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

Unsafe fix: Use a template literal.

(lint/style/useTemplate)


[error] 495-495: 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] 509-509: 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] 29-30: A global variable should not be reassigned.

Assigning to a global variable can override essential functionality.

(lint/suspicious/noGlobalAssign)


[error] 282-282: Shouldn't redeclare 'createQuestionObject'. Consider to delete it or rename it.

'createQuestionObject' is defined here:

(lint/suspicious/noRedeclare)


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

'clt' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'locale' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'checklistName' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'moduleChecklist' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'roleTemp' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'formattedString' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'formattedStringTemp' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


[error] 334-334: This let declares some variables that are only assigned once.

'codes' is never reassigned.

'local' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'final_payload' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'roleTemp' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'code_of_checklist' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'roleTemp' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)

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

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

Unsafe fix: Use a template literal.

(lint/style/useTemplate)


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

Unsafe fix: Use a template literal.

(lint/style/useTemplate)


[error] 166-166: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)


[error] 282-282: 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] 297-297: 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] 18-18: This let declares a variable that is only assigned once.

'clt' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'checklistName' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

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

(lint/correctness/noChildrenProp)


[error] 258-266: 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] 267-275: 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] 288-288: 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] 328-339: 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)

🔇 Additional comments (1)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/ViewChecklist.js (1)

335-335: Ensure window.contextPath is defined before using it

When constructing the navigation URL, window.contextPath is used. If contextPath is undefined, it might lead to navigation issues.

Please verify that window.contextPath is always defined. You can run the following script to check for its definition:

✅ Verification successful

Verified: window.contextPath is always defined.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for the definition and usage of window.contextPath

# Test: Find where window.contextPath is set. Expect: At least one definition.
rg "window\.contextPath\s*=\s*['\"]?[^'\";]+" -t js

Length of output: 1576

},
changeQueryName: `${serviceCode}`,
config: {
enabled: serviceCode? true: false,
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Simplify the boolean expression for enabled

The conditional serviceCode ? true : false can be simplified by directly converting serviceCode to a boolean.

Apply this diff to simplify the expression:

- enabled: serviceCode ? true : false,
+ enabled: Boolean(serviceCode),
📝 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
enabled: serviceCode? true: false,
enabled: Boolean(serviceCode),
🧰 Tools
🪛 Biome

[error] 166-166: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)

// }
// }
// catch (error) {
// }
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

Handle errors in the catch block appropriately

The catch block is currently empty, which means any errors during the API call will be silently ignored. It's important to handle or log errors to aid in debugging.

Apply this diff to log the error:

catch (error) {
+   console.error("Error fetching service definitions:", error);
}

Committable suggestion was skipped due to low confidence.

},
changeQueryName: `${serviceCode}`,
config: {
enabled: serviceCode? true: false,
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Simplify boolean expression in 'enabled' configuration

The conditional expression serviceCode ? true : false is unnecessary. You can simplify it by directly converting serviceCode to a boolean.

Apply this diff to update the code:

     config: {
-        enabled: serviceCode? true: false,
+        enabled: Boolean(serviceCode),
         cacheTime: 5000,
       },
📝 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
enabled: serviceCode? true: false,
enabled: Boolean(serviceCode),
🧰 Tools
🪛 Biome

[error] 113-113: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)

const UpdateChecklist = () => {
const { t } = useTranslation();
const tenantId = Digit.ULBService.getCurrentTenantId();
const searchParams = new URLSearchParams(location.search);
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

Declare 'location' using 'useLocation()'

The variable location is used but not defined. You need to call useLocation() to get the current location from react-router-dom.

Apply this diff to fix the issue:

+  const location = useLocation();
   const searchParams = new URLSearchParams(location.search);

Committable suggestion was skipped due to low confidence.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants