Skip to content

Conversation

@Shamim-97
Copy link
Contributor

@Shamim-97 Shamim-97 commented Jan 27, 2026

All Submissions:

  • My code follow the WordPress' coding standards
  • My code satisfies feature requirements
  • My code is tested
  • My code passes the PHPCS tests
  • My code has proper inline documentation
  • I've included related pull request(s) (optional)
  • I've included developer documentation (optional)
  • I've added proper labels to this pull request

Changes proposed in this Pull Request:

Related Pull Request(s)

  • Full PR Link

Closes

How to test the changes in this Pull Request:

  • Steps or issue link

Changelog entry

Title

Detailed Description of the pull request. What was previous behaviour
and what will be changed in this PR.

Before Changes

Describe the issue before changes with screenshots(s).

After Changes

Describe the issue after changes with screenshot(s).

Feature Video (optional)

Link of detailed video if this PR is for a feature.

PR Self Review Checklist:

  • Code is not following code style guidelines
  • Bad naming: make sure you would understand your code if you read it a few months from now.
  • KISS: Keep it simple, Sweetie (not stupid!).
  • DRY: Don't Repeat Yourself.
  • Code that is not readable: too many nested 'if's are a bad sign.
  • Performance issues
  • Complicated constructions that need refactoring or comments: code should almost always be self-explanatory.
  • Grammar errors.

FOR PR REVIEWER ONLY:

As a reviewer, your feedback should be focused on the idea, not the person. Seek to understand, be respectful, and focus on constructive dialog.

As a contributor, your responsibility is to learn from suggestions and iterate your pull request should it be needed based on feedback. Seek to collaborate and produce the best possible contribution to the greater whole.

  • Correct — Does the change do what it’s supposed to? ie: code 100% fulfilling the requirements?
  • Secure — Would a nefarious party find some way to exploit this change? ie: everything is sanitized/escaped appropriately for any SQL or XSS injection possibilities?
  • Readable — Will your future self be able to understand this change months down the road?
  • Elegant — Does the change fit aesthetically within the overall style and architecture?

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Enhanced sidebar menu active state detection to more accurately display the current page across different navigation scenarios, including routes with query parameters, hash-based navigation, and dashboard base paths.

✏️ Tip: You can customize this high-level summary in your review settings.

@Shamim-97 Shamim-97 self-assigned this Jan 27, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 27, 2026

📝 Walkthrough

Walkthrough

The Sidebar component's active state detection was refactored to use new helper functions isUrlActive() and cleanPathCompare(). These centralize URL matching logic to handle query parameters, hashes, root paths, and standard path matching across menu items and submenus.

Changes

Cohort / File(s) Summary
Sidebar Active State Refactor
src/vendor-dashboard/layout/components/Sidebar.tsx
Introduced isUrlActive(itemUrl) and cleanPathCompare(current, item) helpers to consolidate URL activation logic. Added support for query parameter specificity, hash-based matching, root path guards for dashboard links, and fallback path comparison. Updated all active-state checks for parent items, submenus, and menu items to use the new helper. Includes error handling with try/catch.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

A sidebar so clever, with paths it will measure,
Query params and hashes become its new treasure,
With isUrlActive dancing through routes so divine,
Each menu item highlights when perfectly aligned—
Hop along smoothly through navigation's delight! 🐰✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description contains the template checklist but lacks essential details: 'Changes proposed' section is empty, no 'How to test' steps provided, changelog entry is incomplete, before/after screenshots missing, and PR self-review checklist items are unchecked. Complete the description by filling in: specific changes made, testing instructions, detailed changelog entry, and before/after screenshots. Review the self-review checklist items and mark completed ones with [x].
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: improving sidebar menu highlighting for React-based navigation, which aligns with the refactoring of URL matching logic in the Sidebar component.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/vendor-dashboard/layout/components/Sidebar.tsx (1)

493-497: Inconsistent active state check for inline submenu items.

The isSubActive check still uses the old currentUrl.startsWith(subitem.url) logic, while hasActiveChild detection at line 335 uses the new isUrlActive() helper. This inconsistency can cause the parent menu to correctly highlight (because hasActiveChild uses isUrlActive), but the actual submenu item may not highlight correctly (because isSubActive uses startsWith), or vice versa—particularly for hash-based or query-param URLs.

🔧 Proposed fix
                                                             const isSubActive =
                                                                 subitem?.url &&
-                                                                currentUrl.startsWith(
-                                                                    subitem.url
-                                                                );
+                                                                isUrlActive(
+                                                                    subitem.url
+                                                                );
🧹 Nitpick comments (1)
src/vendor-dashboard/layout/components/Sidebar.tsx (1)

181-202: Consider using isUrlActive for auto-expand logic consistency.

The initial expansion logic at line 191 still uses currentUrl.startsWith(sub.url). For consistent behavior with hash-based and query-param URLs, consider updating this to use the same isUrlActive logic. Note that line 182 declares a local currentUrl that shadows the state variable, so if you switch to isUrlActive, ensure it references the correct URL value.

♻️ Suggested refactor
     useEffect( () => {
-        const currentUrl = window.location?.href || '';
         const initial: Record< string, boolean > = {};
+        const locationHref = window.location?.href || '';

         Object.entries( ( sidebarNav as any ) || {} ).forEach(
             ( [ key, item ]: any ) => {
                 let hasActiveChild = false;

                 if ( item?.submenu ) {
                     Object.values( item.submenu ).forEach( ( sub: any ) => {
-                        if ( sub?.url && currentUrl.startsWith( sub.url ) ) {
+                        if ( sub?.url && isUrlActive( sub.url ) ) {
                             hasActiveChild = true;
                         }
                     } );
                 }

                 initial[ key ] = hasActiveChild;
             }
         );

         setExpanded( initial );
-    }, [ sidebarNav ] );
+    }, [ sidebarNav, currentUrl ] );

Note: Adding currentUrl to the dependency array ensures the expanded state updates when the URL changes via React navigation.

@Shamim-97 Shamim-97 added Needs: Testing This requires further testing Needs: Dev Review It requires a developer review and approval labels Jan 27, 2026
@Shamim-97 Shamim-97 requested a review from mrabbani January 27, 2026 06:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs: Dev Review It requires a developer review and approval Needs: Testing This requires further testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants