Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@mrabbani
Copy link
Member

@mrabbani mrabbani commented Oct 23, 2025

Description

This PR improves the dashboard panel switching functionality and menu rendering in the Dokan admin interface.

Changes Made

  • Dashboard.php: Fixed panel switching logic to properly handle the new admin UI
  • Menu.php: Updated menu state management to ensure correct rendering after panel switch
  • PanelSwitch.tsx: Enhanced component for better state management and UI feedback

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Testing

  • Verified panel switching works correctly between old and new admin UI
  • Confirmed menu state persists properly after switching
  • Tested UI feedback in PanelSwitch component

Related Issues

Resolves issues with dashboard panel switching and menu rendering inconsistencies.

Summary by CodeRabbit

  • Refactor
    • Adjusted admin footer and update footer behavior to be conditional on specific admin screens for consistent display.
    • Removed a previously rendered admin switching container element from the dashboard output.
    • Changed the admin panel switcher wrapper from a block element with top padding to an inline wrapper with vertical margin, refining layout and spacing.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 23, 2025

Walkthrough

Dashboard footer injection for the Dokan switching UI was moved from inline markup to WordPress footer filters; update-footer output is suppressed on Dokan screens. The panel switcher wrapper element changed from a block div to an inline span with margin spacing.

Changes

Cohort / File(s) Summary
Dashboard hook integrations
includes/Admin/Dashboard/Dashboard.php
Registers admin_footer_text and update_footer filters; adds add_switching_container( $text ) to inject the switching container on Dokan screens and add_update_footer( $content ) to suppress update footer on Dokan screens; removes inline dokan-admin-switching output from render_dashboard_page().
Admin menu cleanup
includes/Admin/Menu.php
Removes the inline dokan-admin-switching div from dashboard output.
Panel switcher layout
src/admin/panel-switcher/PanelSwitch.tsx
Changes outer wrapper from <div class="new-dashboard-url pt-8 ..."> to <span class="new-dashboard-url my-8 ...">, switching from padding-top to vertical margin and block to inline element.

Sequence Diagram(s)

sequenceDiagram
    participant AdminPage as Admin Page Render
    participant Menu as Menu::dashboard
    participant Dashboard as Dashboard::register_hooks
    participant WP as WordPress Hooks
    participant Footer as Admin Footer

    Note over Menu,Dashboard: Old flow (inline)
    AdminPage->>Menu: render dashboard()
    Menu->>AdminPage: includes inline <div id="dokan-admin-switching">
    AdminPage->>Footer: render footer (normal)

    Note over Dashboard,WP: New flow (hook-based)
    AdminPage->>Dashboard: instantiate / register_hooks()
    Dashboard->>WP: add_filter(admin_footer_text, add_switching_container, priority=...)
    Dashboard->>WP: add_filter(update_footer, add_update_footer, priority=99)
    AdminPage->>Footer: render footer -> WP applies filters
    WP->>Footer: add_switching_container injects span when on Dokan screens
    WP->>Footer: add_update_footer returns '' to suppress updates on Dokan screens
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

:\:tada\: QA Approved, Dev Review Done

Poem

🐰
I hopped from div to quiet hooks,
A footer span where silence looks,
No update bell on Dokan ground,
A tidy patch, a gentle bound,
— cheers from a rabbit, lightly crowned!

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Description Check ❓ Inconclusive The PR description provides substantive information about the changes made, including specific files affected (Dashboard.php, Menu.php, PanelSwitch.tsx), type of change (bug fix), and testing performed. However, the description significantly deviates from the template structure and omits several required sections, including the All Submissions checklist, specific issue references in the "Closes" section, the Changelog entry section with detailed before/after descriptions, and the Before/After comparison sections. While the core information about what changed and how it was tested is present, the vague "Related Issues" reference ("Resolves issues...") lacks specific issue numbers, and the description does not follow the template's structured format.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The PR title "Fix: Improve dashboard panel switching and menu rendering" is directly related to the changeset. The title accurately captures the main focus of the changes across all three files: Dashboard.php modifications to filter hooks and conditional rendering, Menu.php removal of the switching container, and PanelSwitch.tsx container restructuring. The title is specific, concise, and avoids vague language or unnecessary detail, making it clear to reviewers what aspect of the system is being addressed.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/dashboard-swithcing

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cf1aec5 and e1ba60f.

📒 Files selected for processing (3)
  • includes/Admin/Dashboard/Dashboard.php (2 hunks)
  • includes/Admin/Menu.php (0 hunks)
  • src/admin/panel-switcher/PanelSwitch.tsx (2 hunks)
💤 Files with no reviewable changes (1)
  • includes/Admin/Menu.php
🚧 Files skipped from review as they are similar to previous changes (1)
  • includes/Admin/Dashboard/Dashboard.php
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: api tests (1, 1)
  • GitHub Check: e2e tests (1, 3)
  • GitHub Check: e2e tests (3, 3)
  • GitHub Check: e2e tests (2, 3)
🔇 Additional comments (1)
src/admin/panel-switcher/PanelSwitch.tsx (1)

62-81: Verify visual spacing in the admin footer—the margin change significantly alters spacing behavior.

The semantic change from a block div to an inline span is appropriate for footer text content. However, the spacing model has changed significantly:

  • Old: div with pt-8 (padding-top: 2rem inside the element)
  • New: span with my-8 (margin-top and margin-bottom: 2rem each, outside the element)

The new my-8 applies margin on both top and bottom (whereas before only the top was padded). In a footer text context, this could create excessive vertical spacing. Please verify that the rendered footer appears correct and spacing is as intended.


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.

@mrabbani mrabbani force-pushed the fix/dashboard-swithcing branch from cf1aec5 to e1ba60f Compare October 23, 2025 14:22
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

🧹 Nitpick comments (3)
includes/Admin/Dashboard/Dashboard.php (3)

629-630: Tighten the screen detection to avoid false positives.

Using strpos( $current_screen->id, 'dokan' ) matches any screen ID containing 'dokan' as a substring, which could inadvertently match third-party plugins or custom screens (e.g., 'my-custom-dokan-page').

Apply this diff to check for a 'dokan' prefix or use a whitelist:

-        $is_dokan_screen = ( $current_screen && false !== strpos( $current_screen->id, 'dokan' ) );
+        $is_dokan_screen = ( $current_screen && 0 === strpos( $current_screen->id, 'dokan' ) );

Or use a whitelist approach for more control:

-        $is_dokan_screen = ( $current_screen && false !== strpos( $current_screen->id, 'dokan' ) );
+        $allowed_screens = [ 'toplevel_page_dokan', 'dokan_page_dokan-dashboard' ];
+        $is_dokan_screen = ( $current_screen && in_array( $current_screen->id, $allowed_screens, true ) );

634-634: Consider removing the unnecessary <br/> tag.

The <br/> tag after the span element may create unintended spacing in the footer. Since the React component renders inside the span, the line break might not be necessary.

Apply this diff to remove the <br/> tag:

-        $dom_element = '<span id="dokan-admin-switching" class="dokan-layout dokan-admin-page-body"></span><br/>';
+        $dom_element = '<span id="dokan-admin-switching" class="dokan-layout dokan-admin-page-body"></span>';

648-654: Apply the same tightened screen detection here.

This method uses the same loose strpos check as add_switching_container. For consistency and to avoid false positives, apply the same fix suggested in the previous comment.

Consider extracting the screen check into a private helper method to avoid duplication:

/**
 * Check if current screen is a Dokan admin screen.
 *
 * @since DOKAN_SINCE
 *
 * @return bool
 */
private function is_dokan_admin_screen(): bool {
    $current_screen = get_current_screen();
    return ( $current_screen && 0 === strpos( $current_screen->id, 'dokan' ) );
}

Then use it in both methods:

-        $current_screen = get_current_screen();
-		$is_dokan_screen = ( $current_screen && false !== strpos( $current_screen->id, 'dokan' ) );
-		if ( ! $is_dokan_screen ) {
+        if ( ! $this->is_dokan_admin_screen() ) {
             return $text;
         }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4b83082 and cf1aec5.

📒 Files selected for processing (3)
  • includes/Admin/Dashboard/Dashboard.php (2 hunks)
  • includes/Admin/Menu.php (0 hunks)
  • src/admin/panel-switcher/PanelSwitch.tsx (2 hunks)
💤 Files with no reviewable changes (1)
  • includes/Admin/Menu.php
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: api tests (1, 1)
  • GitHub Check: e2e tests (2, 3)
  • GitHub Check: e2e tests (1, 3)
  • GitHub Check: e2e tests (3, 3)
🔇 Additional comments (3)
includes/Admin/Dashboard/Dashboard.php (2)

58-59: LGTM! Hook registration is appropriate.

The filter hooks are correctly registered for footer manipulation. The update_footer filter with priority 99 ensures the footer clearing runs after other plugins.


626-637: Verify that replacing the footer text entirely is intentional.

The admin_footer_text filter typically modifies WordPress's default "Thank you for creating with WordPress" message. This implementation completely discards the original $text parameter and returns only the switching container. If this is intentional, consider renaming the method or adding a comment to clarify the behavior.

If you want to preserve the original footer text and append the switching container, apply this diff:

-        return $dom_element;
+        return $text . $dom_element;
src/admin/panel-switcher/PanelSwitch.tsx (1)

62-81: Based on my verification of the code and context, the spacing concern is valid but needs clarification. In Tailwind, my-8 applies 2rem (32 pixels) of margin on both top and bottom, while mt-8 applies 2rem only to the top. The original code used pt-8 (padding-top only), so the change to my-8 introduces an extra 32px margin-bottom that wasn't present before.

This is particularly significant because the component is injected into WordPress's admin_footer_text filter, which wraps content in a span within a paragraph element. Adding a bottom margin to an inline element within a paragraph could affect the footer layout. Additionally, the PHP injection includes a <br/> tag after the component, which combined with the new bottom margin creates potential for excessive vertical spacing.

Verify the visual behavior of the footer after the spacing change to ensure my-8 is intentional and doesn't create unwanted gaps in the footer layout.

@mrabbani mrabbani merged commit b6ac9bc into develop Oct 23, 2025
1 of 5 checks passed
@mrabbani mrabbani deleted the fix/dashboard-swithcing branch October 23, 2025 14:29
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