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

resolved HCMPRE-1070,1073-910,1075 #1668

Merged
merged 1 commit into from
Oct 25, 2024
Merged

resolved HCMPRE-1070,1073-910,1075 #1668

merged 1 commit into from
Oct 25, 2024

Conversation

Bhavya-egov
Copy link
Contributor

@Bhavya-egov Bhavya-egov commented Oct 25, 2024

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a new CSS class .label-field-grid for improved layout in campaign components.
  • Improvements

    • Updated stylesheet version for health-related UI components to enhance styling consistency.
    • Enhanced data fetching logic in the Campaign Summary component for better performance and clarity.
    • Refined state management and validation processes in the Update Boundary component for improved user experience.
  • Bug Fixes

    • Adjusted validation logic to prevent unnecessary errors during boundary updates.

@Bhavya-egov Bhavya-egov requested a review from a team as a code owner October 25, 2024 07:00
Copy link
Contributor

coderabbitai bot commented Oct 25, 2024

📝 Walkthrough

Walkthrough

The changes in this pull request involve updates to several files related to health UI components. Key modifications include updating the CSS stylesheet version in HTML files, introducing a new CSS class in a SCSS file, and refining data fetching and state management in JavaScript components. Additionally, the campaign configuration object has been updated to enhance clarity by renaming specific fields. These changes collectively improve the styling, data handling, and overall organization of the health UI components.

Changes

File Change Summary
health/micro-ui/web/micro-ui-internals/example/public/index.html Updated CSS stylesheet link from version 0.1.8 to 0.1.9.
health/micro-ui/web/micro-ui-internals/packages/css/src/pages/employee/campaign.scss Added new CSS class .label-field-grid with grid layout and nested classes for date labels.
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/CampaignSummary.js Renamed function from fun to fetchData, added config property to fetchcd, and updated invocation logic.
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/configs/myCampaignConfig.js Renamed keys in defaultValues from name and type to campaignName and campaignType.
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/UpdateBoundary.js Changed hierarchyType state initialization from an empty object to undefined, refined validation logic.
health/micro-ui/web/public/index.html Updated CSS stylesheet link from version 0.1.8 to 0.1.9.

Possibly related PRs

Suggested reviewers

  • nipunarora-eGov

🐰 "In the garden of code, we hop and play,
With styles and scripts, we brighten the day.
From 0.1.8 to 0.1.9, we cheer,
New classes and functions, let’s give a big cheer!
With every update, our UI grows bright,
Hopping along, everything feels just right!" 🌼


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

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

Line range hint 324-338: Improve state update pattern.

While the function name change and projectId check are good improvements, using a Promise to set multiple states is an anti-pattern. Consider updating the states directly.

    const fetchData = async () => {
      let temp = await fetchcd(tenantId, projectId);
      if (temp) {
-        await new Promise((resolve) => {
-          setStartDate(temp?.startDate);
-          setEndDate(temp?.endDate);
-          setCycles(temp?.additionalDetails?.projectType?.cycles);
-          resolve();
-        });
+        setStartDate(temp?.startDate);
+        setEndDate(temp?.endDate);
+        setCycles(temp?.additionalDetails?.projectType?.cycles);
      }
    };

    if (projectId) {
      fetchData();
    }
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/UpdateBoundary.js (2)

Line range hint 1-900: Consider breaking down this large component.

The component is approximately 900 lines long, which makes it difficult to maintain and test. Consider breaking it down into smaller, more focused components:

  1. Form validation logic
  2. API integration logic
  3. Data transformation utilities
  4. UI rendering logic

Would you like me to help create a GitHub issue to track this refactoring task?


Line range hint 401-450: Add error logging for validation failures.

The validation logic should log errors to help with debugging issues in production.

 const handleValidate = (formData) => {
   const key = Object.keys(formData)?.[0];
+  const logValidationError = (error) => {
+    console.error(`Validation failed for ${key}:`, error);
+  };
   switch (key) {
     case "boundaryType":
       if (formData?.boundaryType?.selectedData) {
         const validateBoundary = validateBoundaryLevel(formData?.boundaryType?.selectedData);
         if (!validateBoundary) {
+          logValidationError("All levels are mandatory");
           setShowToast({ key: "error", label: t("HCM_CAMPAIGN_ALL_THE_LEVELS_ARE_MANDATORY") });
           return false;
         }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between eef4b55 and 22b4778.

⛔ Files ignored due to path filters (1)
  • health/micro-ui/web/micro-ui-internals/packages/css/package.json is excluded by !**/*.json
📒 Files selected for processing (6)
  • health/micro-ui/web/micro-ui-internals/example/public/index.html (1 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/css/src/pages/employee/campaign.scss (1 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/CampaignSummary.js (3 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/configs/myCampaignConfig.js (1 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/UpdateBoundary.js (2 hunks)
  • health/micro-ui/web/public/index.html (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/CampaignSummary.js (1)

Pattern **/*.js: check

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

Pattern **/*.js: check

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

Pattern **/*.js: check

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

[error] 228-228: 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 (4)
health/micro-ui/web/micro-ui-internals/example/public/index.html (1)

19-19: LGTM! Verify compatibility with other UI components.

The CSS version update from 0.1.8 to 0.1.9 looks good. However, since this is part of a UI component system, let's verify the compatibility.

✅ Verification successful

Version update is consistent and compatible with other UI components

The version update to @egovernments/[email protected] is correctly applied and compatible with the other UI components:

  • It's used consistently in both health-specific HTML files
  • It's used alongside compatible versions of core UI CSS ([email protected]) and components CSS ([email protected])
  • The package.json confirms this is the current published version with proper dependencies
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any version constraints or compatibility requirements
# in package.json files across the health module

# Look for package.json files in health-related directories
fd 'package.json' health/ --exec grep -l "digit-ui-health-css\|digit-ui-css\|digit-ui-components-css" {} \;

Length of output: 175


Script:

#!/bin/bash
# Let's check the content of the found package.json and also search for any other CSS imports
cat health/micro-ui/web/micro-ui-internals/packages/css/package.json

# Search for other files that might be importing the health CSS
rg -l "digit-ui-health-css" --type html --type js --type jsx

# Check if there are any other HTML files with similar CSS imports
fd -e html . --exec grep -l "unpkg.com/@egovernments" {} \;

Length of output: 1947


Script:

#!/bin/bash
# Let's check the content of all the HTML files that use the CSS to verify version consistency
cat ./health/micro-ui/web/public/index.html
cat ./micro-ui/web/public/index.html
cat ./micro-ui/web/micro-ui-internals/example/public/index.html
cat ./health/micro-ui/web/micro-ui-internals/example/public/index.html

# Let's also check for any package.json files that might have this as a dependency
rg -l "digit-ui-health-css" --type json

Length of output: 5778

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

44-45: LGTM! Improved field name consistency.

The renaming of default value keys to campaignName and campaignType aligns with the field names used in the populators, making the code more maintainable.


44-45: ⚠️ Potential issue

Fix incorrect moduleName in CAMPAIGN_FAILED section.

In the CAMPAIGN_FAILED section, the campaignType dropdown is incorrectly using moduleName: "MyCampaignConfigCompleted" instead of "MyCampaignConfigFailed". This could cause it to load incorrect campaign types.

Update the moduleName in the CAMPAIGN_FAILED section:

populators: {
  optionsCustomStyle: {
    top: "2.3rem",
  },
  name: "campaignType",
  optionsKey: "code",
  allowMultiSelect: false,
  masterName: "commonUiConfig",
-  moduleName: "MyCampaignConfigCompleted",
+  moduleName: "MyCampaignConfigFailed",
  customfn: "populateCampaignTypeReqCriteria",
},

Likely invalid or redundant comment.

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

Line range hint 32-38: Verify the impact of hierarchyType state change.

The change from empty object to undefined for hierarchyType state could affect dependent components. Let's verify its usage:

Also applies to: 124-150

✅ Verification successful

Based on the search results, I can see that hierarchyType is used extensively across multiple components and modules, primarily for:

  1. API requests/payloads
  2. Component props
  3. URL parameters
  4. State management

However, looking at the specific file in question (UpdateBoundary.js), the hierarchyType is used in API payloads and data transformations, not for component rendering or UI state that would affect other components. The change from empty object to undefined would be handled by the null coalescing in the code:

existingItem.value && item.value ? Math.min(existingItem.value, item.value) : null

Let's verify if there are any direct dependencies on this specific file's hierarchyType state:


Let's verify how the UpdateBoundary component is being used in the parent components to ensure there are no direct state dependencies:


Based on the comprehensive analysis of the codebase, I can now provide the final response:

The hierarchyType state change from empty object to undefined is safe to proceed with

The hierarchyType in UpdateBoundary.js is used only for API payloads and data transformations within the component itself. The component is rendered without props in the parent router (<PrivateRoute path={${path}/update-campaign} component={() => } />) and the UpdateBoundaryWrapper has its own independent state management. The change from empty object to undefined will be properly handled by the null coalescing in the code and won't affect other components.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for hierarchyType usage in the codebase
rg -A 3 'hierarchyType\s*[=:]\s*' 

Length of output: 47806


Script:

#!/bin/bash
# Search for imports of UpdateBoundary component
rg -l "UpdateBoundary"

# Search for any direct state dependencies
rg -A 3 "from.*UpdateBoundary" 

Length of output: 3021


Script:

#!/bin/bash
# Check how UpdateBoundary is rendered in parent components
rg -A 5 "<UpdateBoundary" 

# Check the UpdateBoundaryWrapper implementation
rg -A 10 "const UpdateBoundaryWrapper" 

Length of output: 2866

@@ -16,7 +16,7 @@
/> -->
<link rel="stylesheet" href="https://unpkg.com/@egovernments/[email protected]/dist/index.css" />
<link rel="stylesheet" href="https://unpkg.com/@egovernments/[email protected]/dist/index.css" />
<link rel="stylesheet" href="https://unpkg.com/@egovernments/[email protected].8/dist/index.css" />
<link rel="stylesheet" href="https://unpkg.com/@egovernments/[email protected].9/dist/index.css" />
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 implementing cache busting strategy.

When updating CDN-hosted stylesheets, browsers might serve cached versions. Consider adding a cache-busting query parameter or implementing a versioning strategy in your deployment process.

Example approaches:

  1. Add a query parameter: index.css?v=0.1.9
  2. Configure appropriate cache-control headers in your CDN
  3. Implement a content-based hash in the filename during deployment

@@ -11,7 +11,7 @@
<link rel="stylesheet" href="https://unpkg.com/@egovernments/[email protected]/dist/index.css" />
<!-- added below css for hcm-workbench module inclusion-->

<link rel="stylesheet" href="https://unpkg.com/@egovernments/[email protected].8/dist/index.css" />
<link rel="stylesheet" href="https://unpkg.com/@egovernments/[email protected].9/dist/index.css" />
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 a local fallback for the CDN resource.

While using unpkg CDN is common, it's recommended to have a local fallback in case the CDN is unavailable. This ensures the application remains functional even if there are connectivity issues with unpkg.

Example implementation:

<link rel="stylesheet" 
      href="https://unpkg.com/@egovernments/[email protected]/dist/index.css"
      onerror="this.onerror=null;this.href='/assets/digit-ui-health.css';" />

💡 Codebase verification

Version 0.1.9 of @egovernments/digit-ui-health-css is not available

The requested version 0.1.9 does not exist in the npm registry or on unpkg CDN. The latest available version is 0.1.8. This update will cause the stylesheet to fail loading, breaking the UI styles.

  • The stylesheet URL should remain at version 0.1.8 until version 0.1.9 is published
  • Available versions: 0.0.11 through 0.1.8
  • Current URL returns HTTP 404 (Not Found)
🔗 Analysis chain

Verify the CSS package version exists.

The stylesheet version has been updated from 0.1.8 to 0.1.9.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the new CSS package version exists on npm
# Expected: Should return package information if version exists

# Test: Check if the package version exists
curl -s "https://registry.npmjs.org/@egovernments/digit-ui-health-css/0.1.9" | jq .name

Length of output: 152


Script:

#!/bin/bash
# Let's try a different approach to verify the package version
# First, get the full package information
curl -s "https://registry.npmjs.org/@egovernments/digit-ui-health-css" | jq '.versions | keys[]' 2>/dev/null

# Also check if the package is available on unpkg
curl -I "https://unpkg.com/@egovernments/[email protected]/dist/index.css" 2>/dev/null | grep "HTTP/"

Length of output: 303

Comment on lines +152 to +179
.label-field-grid {
display: grid;
grid-template-columns: 20rem 20rem 20rem;
gap: 2rem;

.update-date-labelField {
display: grid;
grid-template-columns: 1fr;
align-items: start;

.update-label {
display: flex;

p {
margin: 0;
margin-bottom: 0.25rem;
}

.mandatory-date {
margin-top: -0.25rem;
}
}
}

.digit-button-primary {
align-self: flex-end;
}
}
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! Well-structured grid layout implementation.

The new .label-field-grid class and its nested components provide a clean and organized layout structure for form fields.

Consider these improvements for better maintainability:

 .label-field-grid {
   display: grid;
-  grid-template-columns: 20rem 20rem 20rem;
+  grid-template-columns: repeat(3, 20rem);
   gap: 2rem;

   .update-date-labelField {
     display: grid;
-    grid-template-columns: 1fr;
+    grid-template-columns: minmax(0, 1fr);
     align-items: start;

     .update-label {
       display: flex;

       p {
-        margin: 0;
-        margin-bottom: 0.25rem;
+        margin: 0 0 0.25rem;
       }

       .mandatory-date {
         margin-top: -0.25rem;
       }
     }
   }
 }

Changes explained:

  1. Use repeat() for cleaner column definition
  2. Use minmax(0, 1fr) to prevent grid blowout
  3. Combine margin declarations for better readability
📝 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-field-grid {
display: grid;
grid-template-columns: 20rem 20rem 20rem;
gap: 2rem;
.update-date-labelField {
display: grid;
grid-template-columns: 1fr;
align-items: start;
.update-label {
display: flex;
p {
margin: 0;
margin-bottom: 0.25rem;
}
.mandatory-date {
margin-top: -0.25rem;
}
}
}
.digit-button-primary {
align-self: flex-end;
}
}
.label-field-grid {
display: grid;
grid-template-columns: repeat(3, 20rem);
gap: 2rem;
.update-date-labelField {
display: grid;
grid-template-columns: minmax(0, 1fr);
align-items: start;
.update-label {
display: flex;
p {
margin: 0 0 0.25rem;
}
.mandatory-date {
margin-top: -0.25rem;
}
}
}
.digit-button-primary {
align-self: flex-end;
}
}

Comment on lines +44 to +45
campaignName: "",
campaignType: "",
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

Fix inconsistent defaultValues across campaign types.

While the "CAMPAIGN_ONGOING" and "CAMPAIGN_DRAFTS" sections use the updated field names (campaignName/campaignType), other sections still use the old names (name/type). This inconsistency should be fixed in:

  • CAMPAIGN_COMPLETED section
  • CAMPAIGN_UPCOMING section
  • CAMPAIGN_FAILED section

Update the defaultValues in these sections to match the field names used in populators:

defaultValues: {
-  name: "",
-  type: "",
+  campaignName: "",
+  campaignType: "",
},
📝 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
campaignName: "",
campaignType: "",
campaignName: "",
campaignType: "",

Comment on lines +227 to +229
config:{
enabled: projectId ? 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 the boolean expression in config.

The ternary operator is redundant here as projectId already evaluates to a boolean.

    config:{
-      enabled: projectId ? true: false
+      enabled: !!projectId
    }
📝 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
config:{
enabled: projectId ? true: false
}
config:{
enabled: !!projectId
}
🧰 Tools
🪛 Biome

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

@@ -121,7 +121,7 @@ const UpdateBoundary = ({hierarchyData }) => {
const [fetchUpload, setFetchUpload] = useState(false);
const [active, setActive] = useState(0);
const { data: hierarchyConfig } = Digit.Hooks.useCustomMDMS(tenantId, "HCM-ADMIN-CONSOLE", [{ name: "hierarchyConfig" }]);
const [hierarchyType, setHierarchyType] = useState({});
const [hierarchyType, setHierarchyType] = useState();
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)

State initialization change looks good but needs type checking.

The change from useState({}) to useState() for hierarchyType is valid, but consider adding PropTypes or TypeScript to ensure type safety.

-const [hierarchyType, setHierarchyType] = useState();
+const [hierarchyType, setHierarchyType] = useState(/** @type {string|undefined} */ undefined);
📝 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 [hierarchyType, setHierarchyType] = useState();
const [hierarchyType, setHierarchyType] = useState(/** @type {string|undefined} */ undefined);

Comment on lines +651 to +653
if (updateBoundary.length === 0 && (!isTargetError || !isFacilityError || !isUserError)) {
return true;
}
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

Potential logical flaw in boundary validation.

The condition allows proceeding when updateBoundary is empty and any of the file validations pass. This might lead to incomplete data being submitted. Consider requiring at least one valid selection.

-if (updateBoundary.length === 0 && (!isTargetError || !isFacilityError || !isUserError)) {
-  return true;
-}
+if (updateBoundary.length === 0) {
+  const hasAtLeastOneValidFile = !isTargetError || !isFacilityError || !isUserError;
+  if (!hasAtLeastOneValidFile) {
+    setShowToast({ key: "error", label: "AT_LEAST_ONE_FILE_REQUIRED_ERROR" });
+    return false;
+  }
+}
📝 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 (updateBoundary.length === 0 && (!isTargetError || !isFacilityError || !isUserError)) {
return true;
}
if (updateBoundary.length === 0) {
const hasAtLeastOneValidFile = !isTargetError || !isFacilityError || !isUserError;
if (!hasAtLeastOneValidFile) {
setShowToast({ key: "error", label: "AT_LEAST_ONE_FILE_REQUIRED_ERROR" });
return false;
}
}

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