Skip to content

Restore checkMSPPortCount and showMSPWarning functions in ports tab#2436

Merged
sensei-hacker merged 2 commits intoiNavFlight:masterfrom
sensei-hacker:fix-preexisting-tab-errors
Nov 27, 2025
Merged

Restore checkMSPPortCount and showMSPWarning functions in ports tab#2436
sensei-hacker merged 2 commits intoiNavFlight:masterfrom
sensei-hacker:fix-preexisting-tab-errors

Conversation

@sensei-hacker
Copy link
Member

@sensei-hacker sensei-hacker commented Nov 26, 2025

User description

Summary

  • Restore checkMSPPortCount() and showMSPWarning() functions that were lost during merge conflict resolution
  • These functions warn users when more than 2 MSP ports are configured

Root cause

Functions were added in commit 92ee343 but lost in subsequent merge conflicts (8ccf4f8, 895c526).


PR Type

Bug fix


Description

  • Restore checkMSPPortCount() function to count MSP ports

  • Restore showMSPWarning() function to display warnings

  • Functions were lost during merge conflict resolution

  • Warn users when more than 2 MSP ports configured


Diagram Walkthrough

flowchart LR
  A["Merge Conflict"] -->|"Lost Functions"| B["Missing MSP Validation"]
  B -->|"PR Fix"| C["Restored checkMSPPortCount"]
  B -->|"PR Fix"| D["Restored showMSPWarning"]
  C -->|"Enables"| E["Port Count Validation"]
  D -->|"Enables"| E
Loading

File Walkthrough

Relevant files
Bug fix
ports.js
Restore MSP port validation and warning functions               

tabs/ports.js

  • Added checkMSPPortCount() function to count active MSP port checkboxes
  • Added showMSPWarning() function to display MSP warning modal
  • Functions iterate through port configurations and check MSP checkbox
    states
  • Supports excluding specific checkbox from count for "before" state
    comparison
+28/-0   

These functions were lost during merge conflict resolution. They provide
warning when more than 2 MSP ports are configured.
@qodo-code-review
Copy link
Contributor

qodo-code-review bot commented Nov 26, 2025

PR Compliance Guide 🔍

Below is a summary of compliance checks for this PR:

Security Compliance
🟢
No security concerns identified No security vulnerabilities detected by AI analysis. Human verification advised for critical code.
Ticket Compliance
🎫 No ticket provided
  • Create ticket/issue
Codebase Duplication Compliance
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
🟢
Generic: Meaningful Naming and Self-Documenting Code

Objective: Ensure all identifiers clearly express their purpose and intent, making code
self-documenting

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Error Handling

Objective: To prevent the leakage of sensitive system information through error messages while
providing sufficient detail for internal debugging.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Logging Practices

Objective: To ensure logs are useful for debugging and auditing without exposing sensitive
information like PII, PHI, or cardholder data.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Security-First Input Validation and Data Handling

Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent
vulnerabilities

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Comprehensive Audit Trails

Objective: To create a detailed and reliable record of critical system actions for security analysis
and compliance.

Status:
No audit logs: The newly added MSP port count check and warning trigger do not record any audit trail of
the user action or outcome, which may be expected for critical configuration changes.

Referred Code
function checkMSPPortCount(excludeCheckbox) {
    let mspCount = 0;

    $('.tab-ports .portConfiguration').each(function () {
        const $portConfig = $(this);

        // Check each MSP checkbox in this port configuration
        $portConfig.find('input:checkbox[value="MSP"]').each(function() {
            const $checkbox = $(this);
            // Skip the checkbox we're currently changing (to get "before" count)
            if (excludeCheckbox && $checkbox.is(excludeCheckbox)) {
                return;
            }
            if ($checkbox.is(':checked')) {
                mspCount++;
            }
        });
    });

    return mspCount;
}


 ... (clipped 6 lines)

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Robust Error Handling and Edge Case Management

Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation

Status:
Missing edge cases: The functions assume DOM elements exist and jQuery selection succeeds without handling
cases where no port configurations or checkboxes are present, or where modal open fails.

Referred Code
function checkMSPPortCount(excludeCheckbox) {
    let mspCount = 0;

    $('.tab-ports .portConfiguration').each(function () {
        const $portConfig = $(this);

        // Check each MSP checkbox in this port configuration
        $portConfig.find('input:checkbox[value="MSP"]').each(function() {
            const $checkbox = $(this);
            // Skip the checkbox we're currently changing (to get "before" count)
            if (excludeCheckbox && $checkbox.is(excludeCheckbox)) {
                return;
            }
            if ($checkbox.is(':checked')) {
                mspCount++;
            }
        });
    });

    return mspCount;
}


 ... (clipped 6 lines)

Learn more about managing compliance generic rules or creating your own custom rules

  • Update
Compliance status legend 🟢 - Fully Compliant
🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label

@qodo-code-review
Copy link
Contributor

qodo-code-review bot commented Nov 26, 2025

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
General
Simplify logic with idiomatic jQuery

Refactor the checkMSPPortCount function to use a more direct jQuery selector
chain instead of nested .each() loops, improving readability and conciseness.

tabs/ports.js [27-47]

 function checkMSPPortCount(excludeCheckbox) {
-    let mspCount = 0;
+    let $checkboxes = $('.tab-ports .portConfiguration input:checkbox[value="MSP"]');
 
-    $('.tab-ports .portConfiguration').each(function () {
-        const $portConfig = $(this);
+    if (excludeCheckbox) {
+        $checkboxes = $checkboxes.not(excludeCheckbox);
+    }
 
-        // Check each MSP checkbox in this port configuration
-        $portConfig.find('input:checkbox[value="MSP"]').each(function() {
-            const $checkbox = $(this);
-            // Skip the checkbox we're currently changing (to get "before" count)
-            if (excludeCheckbox && $checkbox.is(excludeCheckbox)) {
-                return;
-            }
-            if ($checkbox.is(':checked')) {
-                mspCount++;
-            }
-        });
-    });
-
-    return mspCount;
+    return $checkboxes.filter(':checked').length;
 }
  • Apply / Chat
Suggestion importance[1-10]: 6

__

Why: The suggestion correctly refactors the nested loops into a more concise and idiomatic jQuery chain, which significantly improves code readability and maintainability.

Low
Learned
best practice
Guard modal open call
Suggestion Impact:The commit updated the condition to check that mspWarningModal exists and that its open property is a function before calling open(), preventing potential runtime errors.

code diff:

     function showMSPWarning() {
-        if (mspWarningModal) {
+        if (mspWarningModal && typeof mspWarningModal.open === 'function') {
             mspWarningModal.open();
         }

Ensure the modal instance is valid and not destroyed before calling open to
prevent runtime errors if initialization failed or it was disposed.

tabs/ports.js [49-53]

 function showMSPWarning() {
-    if (mspWarningModal) {
+    if (mspWarningModal && typeof mspWarningModal.open === 'function') {
         mspWarningModal.open();
     }
 }

[Suggestion processed]

Suggestion importance[1-10]: 6

__

Why:
Relevant best practice - Gate UI behavior with guards and validate DOM elements before use to avoid runtime errors.

Low
  • Update

Co-authored-by: qodo-merge-pro[bot] <151058649+qodo-merge-pro[bot]@users.noreply.github.com>
@sensei-hacker sensei-hacker merged commit 853ba62 into iNavFlight:master Nov 27, 2025
6 checks passed
@sensei-hacker sensei-hacker added this to the 9.0 milestone Nov 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant