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

checklist-bugs-fixes #1513

Merged
merged 2 commits into from
Oct 15, 2024
Merged

checklist-bugs-fixes #1513

merged 2 commits into from
Oct 15, 2024

Conversation

suryansh-egov
Copy link
Collaborator

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

Summary by CodeRabbit

  • New Features

    • Enhanced functionality in the Create Question, Create Checklist, and Search Checklist components.
    • Improved checklist creation process with better user interaction and localization support.
    • Added support for saving and retrieving questions from local storage.
  • Bug Fixes

    • Streamlined handling of question data and checklist types, ensuring smoother updates and submissions.
  • Documentation

    • Updated state management and API request structures for clarity and efficiency.

Copy link
Contributor

coderabbitai bot commented Oct 14, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes in this pull request involve updates to three components within the campaign manager module. The CreateQuestionContext component now initializes state from localStorage and includes enhanced logic for managing question data. The CreateChecklist component introduces new state variables and modifies API request structures, while the SearchChecklist component improves the checklist creation process by managing local storage and enhancing user interactions. Overall, these updates aim to streamline functionality and improve user experience.

Changes

File Change Summary
.../CreateQuestionContext.js Updated initialState to retrieve saved questions from localStorage. Enhanced questionDataReducer logic and added useEffect hooks for data monitoring and local storage updates.
.../CreateChecklist.js Added state variables checklistTypeCode and roleCode. Modified API request structure and updated onSubmit function for logging and object management.
.../SearchChecklist.js Updated createNewChecklist function to remove items from local storage before navigation. Enhanced dropdown options and conditional popup display for checklist creation.

Possibly related PRs

  • Vertical stepper implemenetation #1441: The changes in the Module.js file include updates to the CreateQuestion component registration, which is directly related to the CreateQuestionContext component modified in the main PR.
  • Feature/add mdms roles #1476: The SearchChecklist.js component updates state management for checklist options, which may interact with the question data being managed in CreateQuestionContext.
  • fixed summary and campaign creation #1479: The modifications in CampaignSummary.js and DeliveryDetailsSummary.js involve handling data that could be related to the question data structure in the main PR.
  • updated summary redirection #1488: The changes in BoundarySummary.js and CampaignSummary.js include updates to how data is structured and displayed, which may relate to the question data being managed in the main PR.
  • updated master data + bugs related to master data #1497: The updates in SetupMicroplanConfig.js may affect how data is structured and utilized across components, potentially impacting the question data management in the main PR.
  • Mp hypothesis #1505: The modifications in Hypothesis.js and AssumptionsForm.js involve handling assumptions and hypotheses, which could relate to the question data structure in the main PR.

Suggested reviewers

  • nipunarora-eGov
  • jagankumar-egov

🐰 In the garden where questions bloom,
A checklist grows, dispelling gloom.
With state and storage, we refine,
Creating paths where thoughts align.
Each change a hop, a joyful leap,
In code we trust, our goals to keep! 🌼


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

🧹 Outside diff range comments (6)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/SearchChecklist.js (2)

Line range hint 30-35: Consider refactoring navigation logic and adding error handling

The changes to createNewChecklist function look good overall. However, there are a few points to consider:

  1. The removal of "questions" from localStorage is a good cleanup step.
  2. Dispatching a PopStateEvent after navigation is unusual. It might interfere with the browser's natural history management. Consider if this is necessary or if there's a more standard way to achieve the desired behavior.
  3. Error handling for the navigation and localStorage operations would improve robustness.

Consider refactoring the function as follows:

const createNewChecklist = () => {
  try {
    localStorage.removeItem("questions");
    history.push(
      `/${window.contextPath}/employee/campaign/checklist/create?checklistType=${list?.list}&campaignName=${stateData?.name}&role=${code?.code}&campaignType=${stateData?.campaignType}`
    );
    // Remove this line unless absolutely necessary
    // window.dispatchEvent(new PopStateEvent("popstate"));
  } catch (error) {
    console.error("Error creating new checklist:", error);
    // Handle the error appropriately, e.g., show an error message to the user
  }
};

This refactoring adds error handling and removes the potentially problematic PopStateEvent dispatch.


Line range hint 1-231: Overall structure is good, consider some minor improvements

The overall structure and implementation of the SearchChecklist component look good. Here are some observations and suggestions:

  1. The use of custom hooks and Digit UI components is appropriate and consistent.
  2. The popup implementation for creating a new checklist enhances user experience.
  3. The component handles data fetching and state management well.

However, there are a few areas that could be improved:

  1. Consider extracting the popup content into a separate component to improve readability and maintainability.
  2. The onClickRow function is empty. Ensure it's implemented or remove it if not needed.
  3. Some of the data fetching logic could potentially be moved to custom hooks to keep the component cleaner.

Consider implementing these suggestions to further improve the code quality and maintainability.

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

Line range hint 169-173: LGTM! Consider adding error handling for localStorage.

The changes improve the persistence of question data across sessions by utilizing localStorage. This is a good enhancement to the user experience.

Consider adding a try-catch block to handle potential errors when parsing JSON from localStorage:

const [initialState, setInitialState] = useState(() => {
  try {
    const savedQuestions = localStorage.getItem("questions");
    return savedQuestions ? JSON.parse(savedQuestions) : [{ id: crypto.randomUUID(), parentId: null, level: 1, key: 1, title: null, type: { "code": "SingleValueList" }, value: null, isRequired: false }];
  } catch (error) {
    console.error("Error parsing saved questions:", error);
    return [{ id: crypto.randomUUID(), parentId: null, level: 1, key: 1, title: null, type: { "code": "SingleValueList" }, value: null, isRequired: false }];
  }
});

This will ensure that the component doesn't crash if the stored JSON is invalid.


Line range hint 177-187: Approve changes with suggestions for improvement.

The modifications to the useEffect hook improve efficiency by preventing unnecessary updates. However, there are a few points to consider:

  1. The condition props?.props?.data !== 0 seems unusual. Did you mean to check if it's not null or undefined?
  2. The comment about including initialState in the dependency array is outdated and should be removed.
  3. Consider using the functional update form of setInitialState instead of directly updating questionData to ensure you're working with the most recent state.

Here's a suggested refactor:

useEffect(() => {
  if (props?.props?.data && Array.isArray(props.props.data) && props.props.data.length > 0 && props.props.data[0]?.title !== null) {
    dispatchQuestionData((prevState) => {
      if (JSON.stringify(prevState) !== JSON.stringify(props.props.data)) {
        return {
          type: "UPDATE_QUESTION_DATA",
          payload: props.props.data,
        };
      }
      return prevState;
    });
  }
}, [props?.props?.time, props?.props?.data]);

This refactor includes more robust checks and ensures that we're only updating when the data has actually changed.


Line range hint 190-200: Approve changes with minor suggestions.

The modifications to this useEffect hook are good. They prevent saving an empty initial state to localStorage, which improves efficiency. However, there are a couple of minor points to address:

  1. The commented out setInitialState call should be removed as it's no longer necessary.
  2. Consider using a more explicit condition for clarity.

Here's a suggested minor refactor:

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

This refactor improves readability by using a descriptive variable name for the condition. Also, please remove the commented out setInitialState line.

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

Line range hint 188-196: Avoid redefining the 'createQuestionObject' function

The function createQuestionObject is defined twice, which will cause the first definition to be overwritten. This might lead to unexpected behavior. Ensure that each function has a unique name or consolidate the logic into a single function.

Apply this diff to remove the redundant function definition:

- 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: true,
-     reGex: item?.isRegex ? item?.regex?.regex : null,
-     order: item?.key,
-     additionalDetails: item // Complete object goes here
-   };
- 
-   return questionObject;
- }
🧰 Tools
🪛 Biome

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

'moduleChecklist' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'roleTemp' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'formattedString' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 8e309a6 and 87bf9ba.

📒 Files selected for processing (3)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/CreateQuestionContext.js (1 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/CreateChecklist.js (8 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/SearchChecklist.js (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
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/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

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

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

'matchedItem' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'code' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'res' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'moduleChecklist' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'roleTemp' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'formattedString' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'formattedStringTemp' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'roleTemp' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)

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

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

The changes to CreateQuestionContext.js enhance the component's functionality by improving data persistence and preventing unnecessary updates. The use of localStorage for saving question data is a good addition that will improve user experience across sessions.

Key improvements:

  1. Initialization of initialState from localStorage.
  2. Conditional update in the first useEffect to prevent unnecessary dispatches.
  3. Conditional saving to localStorage in the second useEffect to avoid storing empty initial states.

While these changes are generally positive, there are a few minor suggestions for improvement:

  1. Add error handling when parsing JSON from localStorage.
  2. Refine the condition for updating questionData in the first useEffect.
  3. Improve clarity in the second useEffect by using a descriptive variable name for the condition.
  4. Remove outdated comments.

Implementing these suggestions will further enhance the code's robustness and readability.

@@ -25,6 +25,8 @@ const CreateChecklist = () => {
const checklistType = searchParams.get("checklistType");
const projectName = searchParams.get("campaignName");
const campagnType = searchParams.get("campaignType");
const [checklistTypeCode, setChecklistTypeCode] = useState(null);
const [roleCode, setRoleCode] = useState(null);
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

Remove unused state variable 'roleCode'

The state variable roleCode and its setter setRoleCode are declared but not used anywhere in the code. Consider removing them to clean up the code.

Apply this diff to remove the unused state variable:

- const [roleCode, setRoleCode] = useState(null);
📝 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 [roleCode, setRoleCode] = useState(null);

console.log("ul", uniqueLocal);
let checklistTypeTemp = checklistType.toUpperCase().replace(/ /g, "_");
if(checklistTypeCode) checklistTypeTemp=checklistTypeCode;
let roleTemp = role.toUpperCase().replace(/ /g, "_");
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

Use 'const' instead of 'let' for 'roleTemp'

The variable roleTemp is assigned once and never reassigned. Declaring it with const improves code clarity.

Apply this diff:

- let roleTemp = role.toUpperCase().replace(/ /g, "_");
+ const roleTemp = role.toUpperCase().replace(/ /g, "_");
📝 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 roleTemp = role.toUpperCase().replace(/ /g, "_");
const roleTemp = role.toUpperCase().replace(/ /g, "_");
🧰 Tools
🪛 Biome

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

'roleTemp' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)

Comment on lines +110 to +112
// const addChecklistName = (data) => {
// setChecklistName(data);
// }
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

The code in lines 110-112 appears to be commented out and may not be needed. Removing unused code helps maintain codebase cleanliness and readability.

Apply this diff:

- // const addChecklistName = (data) => {
- //   setChecklistName(data);
- // }
📝 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 addChecklistName = (data) => {
// setChecklistName(data);
// }

let checklistTypeTemp = checklistType.toUpperCase().replace(/ /g, "_");
let roleTemp = role.toUpperCase().replace(/ /g, "_");
if(checklistTypeCode) checklistTypeTemp=checklistTypeCode;
let formattedString = `${campaignName}.${checklistTypeTemp}.${roleTemp}.${code}`;
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

Use 'const' instead of 'let' for 'formattedString'

The variable formattedString is never reassigned after its initial assignment. Consider using const to indicate its immutability.

Apply this diff:

- let formattedString = `${campaignName}.${checklistTypeTemp}.${roleTemp}.${code}`;
+ const formattedString = `${campaignName}.${checklistTypeTemp}.${roleTemp}.${code}`;
📝 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 formattedString = `${campaignName}.${checklistTypeTemp}.${roleTemp}.${code}`;
const formattedString = `${campaignName}.${checklistTypeTemp}.${roleTemp}.${code}`;
🧰 Tools
🪛 Biome

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

'formattedString' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)

@@ -159,15 +196,18 @@ module = "HCM";
}
codes[question.id] = code;

let moduleChecklist = "hcm-checklist";

let checklistTypeTemp = checklistType.toUpperCase().replace(/ /g, "_");
let roleTemp = role.toUpperCase().replace(/ /g, "_");
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

Use 'const' instead of 'let' for 'roleTemp'

The variable roleTemp is assigned once and never reassigned. Declaring it with const enhances code readability and ensures it cannot be accidentally modified.

Apply this diff:

- let roleTemp = role.toUpperCase().replace(/ /g, "_");
+ const roleTemp = role.toUpperCase().replace(/ /g, "_");
📝 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 roleTemp = role.toUpperCase().replace(/ /g, "_");
const roleTemp = role.toUpperCase().replace(/ /g, "_");
🧰 Tools
🪛 Biome

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

'roleTemp' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)

Comment on lines +507 to +512
disabled={true}
className="tetxinput-example"
type={"text"}
name={t("NAME_OF_CHECKLIST")}
value={checklistName || ""}
onChange={(event) => addChecklistName(event.target.value)}
value={`${checklistType} ${role}`}
// onChange={(event) => addChecklistName(event.target.value)}
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 displaying checklist name as static text instead of a disabled input

Using a disabled TextInput to display the checklist name might not provide the best user experience. Consider displaying the checklist name as static text or a read-only field to improve clarity.

Example change:

- <TextInput
-   disabled={true}
-   className="tetxinput-example"
-   type={"text"}
-   name={t("NAME_OF_CHECKLIST")}
-   value={`${checklistType} ${role}`}
-   placeholder={"Checklist Name"}
- />
+ <div style={{ marginTop: "0.7rem", fontWeight: "500" }}>
+   {`${checklistType} ${role}`}
+ </div>
📝 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
disabled={true}
className="tetxinput-example"
type={"text"}
name={t("NAME_OF_CHECKLIST")}
value={checklistName || ""}
onChange={(event) => addChecklistName(event.target.value)}
value={`${checklistType} ${role}`}
// onChange={(event) => addChecklistName(event.target.value)}
<div style={{ marginTop: "0.7rem", fontWeight: "500" }}>
{`${checklistType} ${role}`}
</div>
// onChange={(event) => addChecklistName(event.target.value)}

@@ -159,15 +196,18 @@ module = "HCM";
}
codes[question.id] = code;

let moduleChecklist = "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.

🛠️ Refactor suggestion

Use 'const' instead of 'let' for 'moduleChecklist'

The variable moduleChecklist is assigned once and never reassigned. Consider declaring it with const to indicate that it won't change.

Apply this diff:

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

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

'moduleChecklist' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)

@@ -180,12 +220,13 @@ module = "HCM";
const optionval = option.label;
const upperCaseString = optionval.toUpperCase();
const transformedString = upperCaseString.replace(/ /g, '_');
if(checklistTypeCode) checklistTypeTemp=checklistTypeCode;
option.label = transformedString;
let formattedStringTemp = `${campaignName}.${checklistTypeTemp}.${roleTemp}.${option.label}`;
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

Use 'const' instead of 'let' for 'formattedStringTemp'

The variable formattedStringTemp is assigned once and not reassigned. Using const clarifies that its value remains constant.

Apply this diff:

- let formattedStringTemp = `${campaignName}.${checklistTypeTemp}.${roleTemp}.${option.label}`;
+ const formattedStringTemp = `${campaignName}.${checklistTypeTemp}.${roleTemp}.${option.label}`;
📝 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 formattedStringTemp = `${campaignName}.${checklistTypeTemp}.${roleTemp}.${option.label}`;
const formattedStringTemp = `${campaignName}.${checklistTypeTemp}.${roleTemp}.${option.label}`;
🧰 Tools
🪛 Biome

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

'formattedStringTemp' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)

Comment on lines 78 to 83
let matchedItem = localization.messages.find(item => item.message === checklistType);
// If a match is found, assign the 'code' to 'checklistcode'
if (matchedItem) {
console.log("matched", matchedItem);
let code = matchedItem.code;
let res = code.replace("HCM_CHECKLIST_TYPE_", "");
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

Use 'const' instead of 'let' for variables that are not reassigned

The variables matchedItem, code, and res are declared with let but are never reassigned. Consider using const instead to indicate that these variables are not meant to change after initialization.

Apply this diff:

- let matchedItem = localization.messages.find(item => item.message === checklistType);
+ const matchedItem = localization.messages.find(item => item.message === checklistType);

- let code = matchedItem.code;
+ const code = matchedItem.code;

- let res = code.replace("HCM_CHECKLIST_TYPE_", "");
+ const res = code.replace("HCM_CHECKLIST_TYPE_", "");
📝 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 matchedItem = localization.messages.find(item => item.message === checklistType);
// If a match is found, assign the 'code' to 'checklistcode'
if (matchedItem) {
console.log("matched", matchedItem);
let code = matchedItem.code;
let res = code.replace("HCM_CHECKLIST_TYPE_", "");
const matchedItem = localization.messages.find(item => item.message === checklistType);
// If a match is found, assign the 'code' to 'checklistcode'
if (matchedItem) {
console.log("matched", matchedItem);
const code = matchedItem.code;
const res = code.replace("HCM_CHECKLIST_TYPE_", "");
🧰 Tools
🪛 Biome

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

'matchedItem' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'code' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'res' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)

Comment on lines 75 to 91
useEffect(()=>{
console.log("the achieved localization is", localization);
if (localization?.messages?.length > 0) {
let matchedItem = localization.messages.find(item => item.message === checklistType);
// If a match is found, assign the 'code' to 'checklistcode'
if (matchedItem) {
console.log("matched", matchedItem);
let code = matchedItem.code;
let res = code.replace("HCM_CHECKLIST_TYPE_", "");
console.log("the res", res);
setChecklistTypeCode(res);
} else {
console.log('No matching checklist type found.');
}
} else {
console.log('Localization or messages array is not 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 console.log statements

The console.log statements within the useEffect hook may have been used for debugging purposes. Consider removing them or replacing them with a proper logging mechanism appropriate for the production environment.

Apply this diff to remove the console.log statements:

- console.log("the achieved localization is", localization);
- console.log("matched", matchedItem);
- console.log("the res", res);
- console.log('No matching checklist type found.');
- console.log('Localization or messages array is not available.');
📝 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
useEffect(()=>{
console.log("the achieved localization is", localization);
if (localization?.messages?.length > 0) {
let matchedItem = localization.messages.find(item => item.message === checklistType);
// If a match is found, assign the 'code' to 'checklistcode'
if (matchedItem) {
console.log("matched", matchedItem);
let code = matchedItem.code;
let res = code.replace("HCM_CHECKLIST_TYPE_", "");
console.log("the res", res);
setChecklistTypeCode(res);
} else {
console.log('No matching checklist type found.');
}
} else {
console.log('Localization or messages array is not available.');
}
useEffect(()=>{
if (localization?.messages?.length > 0) {
let matchedItem = localization.messages.find(item => item.message === checklistType);
// If a match is found, assign the 'code' to 'checklistcode'
if (matchedItem) {
let code = matchedItem.code;
let res = code.replace("HCM_CHECKLIST_TYPE_", "");
setChecklistTypeCode(res);
}
}
}, [localization, checklistType, setChecklistTypeCode]);
🧰 Tools
🪛 Biome

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

'matchedItem' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'code' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'res' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)

body: {
MdmsCriteria: {
tenantId: tenantId,
schemaCode: "HCMadminconsole.checklisttemplates"
Copy link
Collaborator

Choose a reason for hiding this comment

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

can u use schema code as

HCM-ADMIN-CONSOLE.ChecklistTemplates

@suryansh-egov ?

body: {
MdmsCriteria: {
const reqCriteriaResource = {
url: `/mdms-v2/v2/_search`,
Copy link
Collaborator

Choose a reason for hiding this comment

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

take the mdms url from global config

}
const { isLoading1, data: localization, isFetching1 } = Digit.Hooks.useCustomAPIHook(reqCriteria);
useEffect(()=>{
console.log("the achieved localization is", localization);
Copy link
Collaborator

Choose a reason for hiding this comment

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

remove logs

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 87bf9ba and 2346626.

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

Pattern **/*.js: check

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

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

'matchedItem' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'code' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'res' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'moduleChecklist' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'roleTemp' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'formattedString' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'formattedStringTemp' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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

'roleTemp' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)

Comment on lines 41 to 43
const history = useHistory();
let data_mdms=[]
let template_data=[]
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

Remove unused variables data_mdms and template_data

The variables data_mdms and template_data are declared but not used anywhere in the code. Removing unused variables helps maintain code cleanliness and readability.

Apply this diff to remove the unused variables:

- let data_mdms=[]
- let template_data=[]
...
- useEffect(()=>{
-   if(data_mdms && data_mdms.length!=0) template_data=data_mdms;
- }, [mdms])

Also applies to: 93-95

🧰 Tools
🪛 Biome

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

'data_mdms' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)

Comment on lines +85 to +88
} else {
}
} else {
}
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 empty else blocks to improve code readability

The else blocks at lines 85-86 and 87-88 are empty and do not perform any actions. Removing these empty blocks enhances code readability.

Apply this diff to remove the empty else blocks:

        } else {
-       }
-     } else {
-       }
        }

Refactored code:

useEffect(() => {
  if (localization?.messages?.length > 0) {
    let matchedItem = localization.messages.find(item => item.message === checklistType);
    if (matchedItem) {
      let code = matchedItem.code;
      let res = code.replace("HCM_CHECKLIST_TYPE_", "");
      setChecklistTypeCode(res);
    }
  }
}, [localization]);

useEffect(()=>{
if(data_mdms && data_mdms.length!=0) template_data=data_mdms;
}, [mdms])

module = "HCM";
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

Avoid reassigning the module variable

At line 97, the variable module is reassigned with a new value "hcm-checklist". This may lead to confusion since module was initially assigned from URL parameters. Consider using a new variable name to preserve the original value from searchParams.

Apply this diff:

- module = "hcm-checklist";
+ const moduleChecklist = "hcm-checklist";

And update references to use moduleChecklist instead of module where appropriate.

Committable suggestion was skipped due to low confidence.

@jagankumar-egov jagankumar-egov changed the base branch from console to boundary-feature October 15, 2024 05:19
@jagankumar-egov jagankumar-egov merged commit a544ad7 into boundary-feature Oct 15, 2024
3 checks passed
@jagankumar-egov jagankumar-egov deleted the feature/cl-mod branch October 15, 2024 05:20
jagankumar-egov added a commit that referenced this pull request Oct 15, 2024
* Feature/boundary ss (#1490)

* boundary-hierarchy

* boundary-hierarchy

* localization changes

* ui changes

* Update health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/CampaignCard.js

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* pr review changes

* removed all logs

---------

Co-authored-by: suryansh-egov <suryansh.singh.egovernments.org>
Co-authored-by: Jagankumar <[email protected]>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* checklist-bugs-fixes (#1513)

* checklist-bugs-fixes

* cahgnes

---------

Co-authored-by: suryansh-egov <suryansh.singh.egovernments.org>

* changesnew

---------

Co-authored-by: suryansh-egov <[email protected]>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: suryansh-egov <suryansh.singh.egovernments.org>
This was referenced Nov 22, 2024
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