-
Notifications
You must be signed in to change notification settings - Fork 216
Fix: Improve dashboard panel switching and menu rendering #2946
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
Conversation
WalkthroughDashboard 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 Changes
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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (3)
💤 Files with no reviewable changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ 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)
🔇 Additional comments (1)
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. Comment |
cf1aec5 to
e1ba60f
Compare
There was a problem hiding this 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 thespanelement may create unintended spacing in the footer. Since the React component renders inside thespan, 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
strposcheck asadd_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
📒 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_footerfilter 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_textfilter typically modifies WordPress's default "Thank you for creating with WordPress" message. This implementation completely discards the original$textparameter 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 usedpt-8(padding-top only), so the change tomy-8introduces an extra 32px margin-bottom that wasn't present before.This is particularly significant because the component is injected into WordPress's
admin_footer_textfilter, 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-8is intentional and doesn't create unwanted gaps in the footer layout.
Description
This PR improves the dashboard panel switching functionality and menu rendering in the Dokan admin interface.
Changes Made
Type of Change
Testing
Related Issues
Resolves issues with dashboard panel switching and menu rendering inconsistencies.
Summary by CodeRabbit