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

Hcmpre 1290 #1834

Merged
merged 7 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ const CampaignCard = () => {
roles: ROLES.CAMPAIGN_MANAGER,
// count: isLoading?"-":data
},
{
label: t("MICROPLAN_CAMPAIGN"),
link: `/${window?.contextPath}/employee/campaign/my-microplan`,
roles: ROLES.CAMPAIGN_MANAGER,
// count: isLoading?"-":data
},
Bhavya-egov marked this conversation as resolved.
Show resolved Hide resolved
];

links = links.filter((link) => (link?.roles && link?.roles?.length > 0 ? Digit.Utils.didEmployeeHasAtleastOneRole(link?.roles) : true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const CampaignSelection = ({ onSelect, formData, formState, ...props }) => {
const searchParams = new URLSearchParams(location.search);
const [currentStep , setCurrentStep] = useState(1);
const currentKey = searchParams.get("key");
const productType = searchParams.get("type");
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 extracting URL parameter logic to a custom hook

The URL parameter handling could be moved to a custom hook (e.g., useCampaignType) to:

  • Improve reusability across components
  • Centralize validation logic
  • Make the component more testable

Example implementation:

const useCampaignType = () => {
  const searchParams = new URLSearchParams(location.search);
  const validProductTypes = ["microplan", "other_valid_type"];
  const rawProductType = searchParams.get("type");
  
  return {
    productType: validProductTypes.includes(rawProductType) ? rawProductType : null,
    isMicroplan: rawProductType === "microplan",
  };
};

Then in your component:

const { productType, isMicroplan } = useCampaignType();
// Use isMicroplan for the disabled prop

Also applies to: 147-147


🧹 Nitpick (assertive)

Add validation for the productType URL parameter

The productType parameter from URL should be validated to ensure it only accepts expected values (e.g., "microplan" or other valid types).

-  const productType = searchParams.get("type");
+  const validProductTypes = ["microplan", "other_valid_type"];
+  const rawProductType = searchParams.get("type");
+  const productType = validProductTypes.includes(rawProductType) ? rawProductType : null;

Committable suggestion skipped: line range outside the PR's diff.

Bhavya-egov marked this conversation as resolved.
Show resolved Hide resolved
const [key, setKey] = useState(() => {
const keyParam = searchParams.get("key");
return keyParam ? parseInt(keyParam) : 1;
Expand Down Expand Up @@ -118,7 +119,7 @@ const CampaignSelection = ({ onSelect, formData, formState, ...props }) => {
<div
className="campaign-type-wrapper"
onClick={(e) => {
if (props?.props?.sessionData?.HCM_CAMPAIGN_TYPE?.projectType && !canUpdate) {
if (props?.props?.sessionData?.HCM_CAMPAIGN_TYPE?.projectType && !canUpdate && productType!=="microplan") {
Bhavya-egov marked this conversation as resolved.
Show resolved Hide resolved
setShowPopUp(true);
return;
}
Expand All @@ -143,6 +144,8 @@ const CampaignSelection = ({ onSelect, formData, formState, ...props }) => {
setStartValidation(true);
handleChange(value);
}}
disabled = {productType === "microplan"}
Bhavya-egov marked this conversation as resolved.
Show resolved Hide resolved

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 whitespace

Remove the empty line with whitespace after the disabled prop.

  disabled = {productType === "microplan"}
-  
📝 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 = {productType === "microplan"}
disabled = {productType === "microplan"}

/>
{error?.message && <ErrorMessage message={t(error?.message)} showIcon={true} />}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,66 @@ export const UICustomizations = {
}}
/>
</>
)
);
}

},
},
MicroplanCampaignSearchConfig: {
preProcess: (data, additionalDetails) => {
const { name, status } = data?.state?.searchForm || {};
data.body.PlanConfigurationSearchCriteria = {};
data.body.PlanConfigurationSearchCriteria.limit = data?.state?.tableForm?.limit;
// data.body.PlanConfigurationSearchCriteria.limit = 10
data.body.PlanConfigurationSearchCriteria.offset = data?.state?.tableForm?.offset;
data.body.PlanConfigurationSearchCriteria.name = name;
data.body.PlanConfigurationSearchCriteria.tenantId = Digit.ULBService.getCurrentTenantId();
data.body.PlanConfigurationSearchCriteria.userUuid = Digit.UserService.getUser().info.uuid;
Bhavya-egov marked this conversation as resolved.
Show resolved Hide resolved
// delete data.body.PlanConfigurationSearchCriteria.pagination
data.body.PlanConfigurationSearchCriteria.status = status?.status;
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

Verify correct assignment of status in PlanConfigurationSearchCriteria

At line 317, data.body.PlanConfigurationSearchCriteria.status = status?.status;. Since status is destructured from data?.state?.searchForm || {}, ensure that status?.status is the intended value. It might need to be status?.code or simply status.

Please confirm that the correct value is being assigned to status.

data.body.PlanConfigurationSearchCriteria.name = data?.state?.searchForm?.microplanName;
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 duplicate assignments to PlanConfigurationSearchCriteria.name

In the preProcess method, data.body.PlanConfigurationSearchCriteria.name is assigned twice, at lines 313 and 318. This could lead to unintended behavior or confusion.

Consider consolidating the assignments to ensure only one definitive value is set:

- data.body.PlanConfigurationSearchCriteria.name = name;
...
- data.body.PlanConfigurationSearchCriteria.name = data?.state?.searchForm?.microplanName;
+ data.body.PlanConfigurationSearchCriteria.name = data?.state?.searchForm?.microplanName || name;
📝 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
data.body.PlanConfigurationSearchCriteria.name = name;
data.body.PlanConfigurationSearchCriteria.tenantId = Digit.ULBService.getCurrentTenantId();
data.body.PlanConfigurationSearchCriteria.userUuid = Digit.UserService.getUser().info.uuid;
// delete data.body.PlanConfigurationSearchCriteria.pagination
data.body.PlanConfigurationSearchCriteria.status = status?.status;
data.body.PlanConfigurationSearchCriteria.name = data?.state?.searchForm?.microplanName;
data.body.PlanConfigurationSearchCriteria.name = data?.state?.searchForm?.microplanName || name;
data.body.PlanConfigurationSearchCriteria.tenantId = Digit.ULBService.getCurrentTenantId();
data.body.PlanConfigurationSearchCriteria.userUuid = Digit.UserService.getUser().info.uuid;
// delete data.body.PlanConfigurationSearchCriteria.pagination
data.body.PlanConfigurationSearchCriteria.status = status?.status;

data.body.PlanConfigurationSearchCriteria.campaignType = data?.state?.searchForm?.campaignType?.[0]?.code;
return data;
},
additionalCustomizations: (row, key, column, value, t, searchResult) => {
switch (key) {
case "NAME_OF_MICROPLAN":
if (value && value !== "NA") {
return (
<div
style={{
maxWidth: "15rem", // Set the desired maximum width
wordWrap: "break-word", // Allows breaking within words
whiteSpace: "normal", // Ensures text wraps normally
overflowWrap: "break-word", // Break long words at the edge
}}
>
<p>{t(value)}</p>
</div>
);
} else {
return (
<div>
<p>{t("NA")}</p>
</div>
);
}

case "CAMPAIGN_TYPE":
if (value && value != "NA") {
return <p>{t(Digit.Utils.locale.getTransformedLocale("MICROPLAN_TYPE_" + value))}</p>;
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

Line 348 concatenates strings using +. For better readability and to adhere to best practices, use template literals.

Modify line 348 as follows:

- return <p>{t(Digit.Utils.locale.getTransformedLocale("MICROPLAN_TYPE_" + value))}</p>;
+ return <p>{t(Digit.Utils.locale.getTransformedLocale(`MICROPLAN_TYPE_${value}`))}</p>;
📝 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
return <p>{t(Digit.Utils.locale.getTransformedLocale("MICROPLAN_TYPE_" + value))}</p>;
return <p>{t(Digit.Utils.locale.getTransformedLocale(`MICROPLAN_TYPE_${value}`))}</p>;
🧰 Tools
🪛 Biome

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

Unsafe fix: Use a template literal.

(lint/style/useTemplate)

} else {
return (
<div>
<p>{t("NA")}</p>
</div>
);
}
case "LAST_MODIFIED_TIME":
return Digit.DateUtils.ConvertEpochToDate(value);
default:
return null; // Handle any unexpected keys here if needed
jagankumar-egov marked this conversation as resolved.
Show resolved Hide resolved
}
},
},
MyCampaignConfigOngoing: {
preProcess: (data, additionalDetails) => {
Expand Down Expand Up @@ -886,7 +941,7 @@ export const UICustomizations = {
return value ? t("CM_UPDATE_REQUEST") : t("CM_CREATE_REQUEST");
case "CAMPAIGN_START_DATE":
return Digit.DateUtils.ConvertEpochToDate(value);
case "CAMPAIGN_END_DATE":
case "LAST_MODIFIED_TIME":
return Digit.DateUtils.ConvertEpochToDate(value);
default:
return "case_not_found";
Expand Down Expand Up @@ -993,7 +1048,8 @@ export const UICustomizations = {
</Link>
</span>
);

case "CM_DRAFT_TYPE":
return value ? t("CM_UPDATE_REQUEST") : t("CM_CREATE_REQUEST");
case "CAMPAIGN_START_DATE":
return Digit.DateUtils.ConvertEpochToDate(value);
case "CAMPAIGN_END_DATE":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,11 +524,16 @@ export const myCampaignConfig = {
additionalCustomization: true,
// disableSortBy: true,
},
// {
// label: "CAMPAIGN_END_DATE",
// jsonPath: "endDate",
// additionalCustomization: true,
// // disableSortBy: true,
// },
{
label: "CAMPAIGN_END_DATE",
jsonPath: "endDate",
additionalCustomization: true,
// disableSortBy: true,
label:"LAST_MODIFIED_TIME",
jsonPath:"auditDetails.lastModifiedTime",
additionalCustomization:true
jagankumar-egov marked this conversation as resolved.
Show resolved Hide resolved
},
],
enableGlobalSearch: false,
Expand Down Expand Up @@ -637,6 +642,11 @@ export const myCampaignConfig = {
jsonPath: "campaignName",
// additionalCustomization: true,
},
{
label: "CM_DRAFT_TYPE",
jsonPath: "parentId",
additionalCustomization: true,
},
Comment on lines +645 to +649
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

Clarify CM_DRAFT_TYPE implementation and add documentation

The new CM_DRAFT_TYPE column uses parentId without clear documentation. Consider:

  1. Adding comments explaining the mapping between parentId and draft types
  2. Adding translation support if draft types need localization
 {
   label: "CM_DRAFT_TYPE",
   jsonPath: "parentId",
-  additionalCustomization: true,
+  additionalCustomization: true,
+  translate: true,
+  prefix: "CM_DRAFT_TYPE_",
+  // Maps parentId to specific draft types:
+  // null -> New Draft
+  // campaign-id -> Revision Draft
 },
📝 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
{
label: "CM_DRAFT_TYPE",
jsonPath: "parentId",
additionalCustomization: true,
},
{
label: "CM_DRAFT_TYPE",
jsonPath: "parentId",
additionalCustomization: true,
translate: true,
prefix: "CM_DRAFT_TYPE_",
// Maps parentId to specific draft types:
// null -> New Draft
// campaign-id -> Revision Draft
},

{
label: "CAMPAIGN_TYPE",
jsonPath: "projectType",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@


const tenantId = Digit.ULBService.getCurrentTenantId();
const mdms_context_path = window?.globalConfigs?.getConfig("MDMS_V2_CONTEXT_PATH") || "mdms-v2";
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

Remove unused variable declaration

The mdms_context_path variable is declared but never used in the configuration.

-  const mdms_context_path = window?.globalConfigs?.getConfig("MDMS_V2_CONTEXT_PATH") || "mdms-v2";
📝 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 mdms_context_path = window?.globalConfigs?.getConfig("MDMS_V2_CONTEXT_PATH") || "mdms-v2";

export const MicroplanCampaignSearchConfig = [
{
label: "MICROPLAN_SEARCH",
type: "search",
apiDetails: {
serviceName: "/plan-service/config/_search",
requestParam: {
},
requestBody: {
"PlanConfigurationSearchCriteria": {
"limit": 10,
"offset": 0,
"tenantId": "mz",
Bhavya-egov marked this conversation as resolved.
Show resolved Hide resolved
"userUuid": "ff4ca65b-de7a-48de-ab9d-23c7728dc1aa"
},
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

Replace hard-coded values with dynamic values

The configuration contains hard-coded values for tenantId and userUuid. These should be replaced with dynamic values from the current context.

  "PlanConfigurationSearchCriteria": {
    "limit": 10,
    "offset": 0,
-   "tenantId": "mz",
-   "userUuid": "ff4ca65b-de7a-48de-ab9d-23c7728dc1aa"
+   "tenantId": Digit.ULBService.getCurrentTenantId(),
+   "userUuid": Digit.UserService.getUser().uuid
  },
📝 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
"PlanConfigurationSearchCriteria": {
"limit": 10,
"offset": 0,
"tenantId": "mz",
"userUuid": "ff4ca65b-de7a-48de-ab9d-23c7728dc1aa"
},
"PlanConfigurationSearchCriteria": {
"limit": 10,
"offset": 0,
"tenantId": Digit.ULBService.getCurrentTenantId(),
"userUuid": Digit.UserService.getUser().uuid
},

},
masterName: "commonUiConfig",
moduleName: "MicroplanCampaignSearchConfig",
Copy link
Collaborator

Choose a reason for hiding this comment

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

just config, moduleName is differnt for microplan UI and here ?

minParametersForSearchForm: 0,
tableFormJsonPath: "requestBody.PlanConfigurationSearchCriteria.pagination",
// filterFormJsonPath: "requestBody.MdmsCriteria.customs",
searchFormJsonPath: "requestBody.PlanConfigurationSearchCriteria",
},
sections: {
search: {
uiConfig: {
formClassName: "custom-both-clear-search",
primaryLabel: "ES_COMMON_SEARCH",
secondaryLabel: "ES_COMMON_CLEAR_SEARCH",
Comment on lines +30 to +32
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 proper i18n label keys

The form labels should follow proper i18n naming conventions for better internationalization support.

-  primaryLabel: "ES_COMMON_SEARCH",
-  secondaryLabel: "ES_COMMON_CLEAR_SEARCH",
+  primaryLabel: "ES_CAMPAIGN_MICROPLAN_SEARCH_BTN",
+  secondaryLabel: "ES_CAMPAIGN_MICROPLAN_CLEAR_SEARCH_BTN",
📝 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
formClassName: "custom-both-clear-search",
primaryLabel: "ES_COMMON_SEARCH",
secondaryLabel: "ES_COMMON_CLEAR_SEARCH",
formClassName: "custom-both-clear-search",
primaryLabel: "ES_CAMPAIGN_MICROPLAN_SEARCH_BTN",
secondaryLabel: "ES_CAMPAIGN_MICROPLAN_CLEAR_SEARCH_BTN",

minReqFields: 0,
defaultValues:{
microplanName: "",
campaignType: "",
},
fields: [
{
label: "Name of the microplan",
Bhavya-egov marked this conversation as resolved.
Show resolved Hide resolved
isMandatory: false,
key: "microplanName",
type: "text",
populators: {
name: "microplanName"
},
},
{
label: "CAMPAIGN_SEARCH_TYPE",
type: "apidropdown",
isMandatory: false,
disable: false,
populators: {
optionsCustomStyle: {
top: "2.3rem",
},
name: "campaignType",
optionsKey: "code",
allowMultiSelect: false,
masterName: "commonUiConfig",
moduleName: "MyCampaignConfigDrafts",
customfn: "populateCampaignTypeReqCriteria",
},
},
],
},

show: true,
},
searchResult: {
uiConfig: {
columns: [
{
label: "NAME_OF_MICROPLAN",
jsonPath: "name",
additionalCustomization:true
},
{
label:"CAMPAIGN_TYPE",
jsonPath:"campaignDetails.projectType",
additionalCustomization:true
},
{
label:"LAST_MODIFIED_TIME",
jsonPath:"auditDetails.lastModifiedTime",
additionalCustomization:true
},
],
resultsJsonPath: "PlanConfiguration",

enableColumnSort: true,
// resultsJsonPath: "mdms",
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Remove commented code

Remove the commented out resultsJsonPath line as it's no longer needed.

-            // resultsJsonPath: "mdms",
📝 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
// resultsJsonPath: "mdms",

},
show: true,
},
// customHookName: "microplanv1.useSavedMicroplans",

},
customHookName:"microplanv1.useSavedMicroplans"
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

🛠️ Refactor suggestion

Remove commented hook definition and update hook name

The custom hook useSavedMicroplans exists and is properly implemented in the codebase. However, I noticed that the root level hook name should be useSavedMicroplansWithCampaign to match other config files.

  • Remove the commented hook definition
  • Update the root level hook name to microplanv1.useSavedMicroplansWithCampaign to maintain consistency with MyMicroplanSearchConfig.js
-       // customHookName: "microplanv1.useSavedMicroplans", 
        
      },
-      customHookName:"microplanv1.useSavedMicroplans"
+      customHookName:"microplanv1.useSavedMicroplansWithCampaign"
🔗 Analysis chain

Remove duplicate custom hook definition

The custom hook is defined twice - once commented out inside sections and once at the root level. Remove the commented version to avoid confusion.

-       // customHookName: "microplanv1.useSavedMicroplans", 

Also, verify that the custom hook exists and is properly implemented.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for the custom hook implementation
rg -A 10 "useSavedMicroplans" --type js

Length of output: 18341

Bhavya-egov marked this conversation as resolved.
Show resolved Hide resolved
},
];


Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { Header, InboxSearchComposer } from "@egovernments/digit-ui-react-components";
import React, { useState, useEffect } from "react";
import { useTranslation } from "react-i18next";
import { useHistory } from "react-router-dom";
import { MicroplanCampaignSearchConfig } from "../../configs/myMicroplanConfig";



const defaultSearchValues = {

};

const MyMicroplans = () => {
const { t } = useTranslation();
const [defaultValues, setDefaultValues] = useState(defaultSearchValues); // State to hold default values for search fields
const history = useHistory();
useEffect(() => {
// Set default values when component mounts
setDefaultValues(defaultSearchValues);
}, []);
jagankumar-egov marked this conversation as resolved.
Show resolved Hide resolved

const onTabChange = (n) => {

setTabData((prev) => prev.map((i, c) => ({ ...i, active: c === n ? true : false }))); //setting tab enable which is being clicked
// setConfig(TabSearchconfig?.TabSearchconfig?.[n]);// as per tab number filtering the config
const url = new URL(window.location.href);
url.searchParams.set("tabId", `${n}`);
window.history.replaceState({}, "", url);

};
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

⚠️ Potential issue

Fix undefined tabData state

The onTabChange function references tabData and setTabData but these are not defined in the component. The state needs to be initialized using useState hook.

  • Remove or properly implement the onTabChange function as it's currently not being used by any tab component in the rendered JSX
  • If tabs are needed, initialize the tabData state: const [tabData, setTabData] = useState([]);
🔗 Analysis chain

Fix incomplete tab implementation

The onTabChange function has several issues:

  1. It references undefined variables (tabData, setTabData)
  2. Contains commented code suggesting incomplete implementation
  3. Updates URL params but the tab state isn't properly managed

Let me search for the state definitions and React imports in the specific file to verify if tabData is properly initialized.


Let me check the complete file content to see how tabData is initialized and used in the component.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for tab-related state definitions in the file
rg "tabData|setTabData" 

Length of output: 88832


Script:

#!/bin/bash
# Search for tabData state definition in the specific file
rg -A 5 "tabData|setTabData" "health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/MyMicroplans.js"

# Search for useState imports
rg "useState" "health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/MyMicroplans.js"

Length of output: 806


Script:

#!/bin/bash
# Get more context around the file to see tabData initialization
cat "health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/MyMicroplans.js"

Length of output: 1947

🧰 Tools
🪛 Biome

[error] 24-24: 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 onClickRow = ({ original: row }) => {
history.push(`/${window.contextPath}/employee/campaign/setup-campaign?id=${row.campaignId}&draft=true&fetchBoundary=true&draftBoundary=true&type=microplan`);
};
return (
<React.Fragment>

<Header styles={{ fontSize: "32px" }}>{t("MY_MICROPLANS_HEADING")}</Header>
jagankumar-egov marked this conversation as resolved.
Show resolved Hide resolved
<div className="inbox-search-wrapper">
{/* Pass defaultValues as props to InboxSearchComposer */}
<InboxSearchComposer
configs={MicroplanCampaignSearchConfig?.[0]}
additionalConfig={{
resultsTable: {
onClickRow,
},
}}
></InboxSearchComposer>
</div>
Comment on lines +33 to +41
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Use self-closing tag for InboxSearchComposer.

Since the InboxSearchComposer component doesn't have any children, it should use a self-closing tag.

-        <InboxSearchComposer
-        configs={MicroplanCampaignSearchConfig?.[0]}
-        additionalConfig={{
-          resultsTable: {
-            onClickRow,
-          },
-        }}
-        ></InboxSearchComposer>
+        <InboxSearchComposer
+          configs={MicroplanCampaignSearchConfig?.[0]}
+          additionalConfig={{
+            resultsTable: {
+              onClickRow,
+            },
+          }}
+        />
📝 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
<InboxSearchComposer
configs={MicroplanCampaignSearchConfig?.[0]}
additionalConfig={{
resultsTable: {
onClickRow,
},
}}
></InboxSearchComposer>
</div>
<InboxSearchComposer
configs={MicroplanCampaignSearchConfig?.[0]}
additionalConfig={{
resultsTable: {
onClickRow,
},
}}
/>
</div>
🧰 Tools
🪛 Biome

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

</React.Fragment>
);
};
export default MyMicroplans;
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const SetupCampaign = ({ hierarchyType, hierarchyData }) => {
const isDateRestricted = searchParams.get("date");
const isChangeDates = searchParams.get("changeDates");
const actionBar = searchParams.get("actionBar");
const type = searchParams.get("type");
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 using a custom hook for URL params.

The URL parameter handling is scattered across the component. Consider extracting URL parameter handling into a custom hook for better reusability and maintainability.

-const type = searchParams.get("type");
+const useUrlParams = () => {
+  const searchParams = new URLSearchParams(location.search);
+  return {
+    type: searchParams.get("type"),
+    id: searchParams.get("id"),
+    isPreview: searchParams.get("preview"),
+    // ... other params
+  };
+};
+const { type } = useUrlParams();

Committable suggestion skipped: line range outside the PR's diff.

const [isDraftCreated, setIsDraftCreated] = useState(false);
const [currentKey, setCurrentKey] = useState(() => {
const keyParam = searchParams.get("key");
Expand Down Expand Up @@ -112,9 +113,12 @@ const SetupCampaign = ({ hierarchyType, hierarchyData }) => {
setIsDraftCreated(true);
if (isSkip === "false") {
if (currentKey === 1) setCurrentKey(1);
} else if (isDateRestricted === "true") {
setCurrentKey(3);
} else {
} else if (type === "microplan") {
Bhavya-egov marked this conversation as resolved.
Show resolved Hide resolved
setCurrentKey(2);
}else if (isDateRestricted === "true") {
setCurrentKey(3);
}
else {
Bhavya-egov marked this conversation as resolved.
Show resolved Hide resolved
if(draftData?.additionalDetails?.key === 7 || draftData?.additionalDetails?.key === 8){
setCurrentKey(6);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import ViewHierarchy from "./ViewHierarchy";
import ViewChecklist from "./ViewChecklist";
import UpdateChecklist from "./UpdateChecklist";
import BoundaryHome from "./BoundaryHome";
import MyMicroplans from "./MyMicroplans";
/**
* The CampaignBreadCrumb function generates breadcrumb navigation for a campaign setup page in a React
* application.
Expand Down Expand Up @@ -148,6 +149,7 @@ const App = ({ path, BOUNDARY_HIERARCHY_TYPE, hierarchyData }) => {
<PrivateRoute path={`${path}/boundary/view-all-hierarchy`} component={()=> <ViewBoundary />} />
<PrivateRoute path={`${path}/boundary/data`} component={()=> <ViewHierarchy />} />
<PrivateRoute path={`${path}/update-campaign`} component={() => <UpdateCampaign />} />
<PrivateRoute path={`${path}/my-microplan`} component={() => <MyMicroplans />} />
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 breadcrumb entry for the new microplan route.

The new route for MyMicroplans is missing a corresponding breadcrumb entry in the CampaignBreadCrumb component's crumbs array. This will affect navigation consistency.

Add the following entry to the crumbs array in CampaignBreadCrumb:

 const crumbs = [
   // ... existing crumbs
+  {
+    path: pathVar === "my-microplan" ? "" : `/${window?.contextPath}/employee/campaign/my-microplan`,
+    content: t("MY_MICROPLANS"),
+    show: pathVar === "my-microplan" ? true : false,
+  },
   // ... remaining crumbs
 ];

Committable suggestion skipped: line range outside the PR's diff.

</AppContainer>
</Switch>
</React.Fragment>
Expand Down