-
Notifications
You must be signed in to change notification settings - Fork 21
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
Integration with new WC Navigation #605
Conversation
Title seems to be not used at all. This has been cross checked in WC Admin code base.
Conflicts: js/src/reports/programs/index.js
Conflicts: js/src/reports/programs/index.js
Awesome thanks @ecgan |
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.
Some questions
- ❓. Not sure if this is the expected result. The main pages are not listed in the menu when adding/editing campaigns or editing the free listings.
- 📜 . Probably here is the pattern to consider having a HOC to conditional switching the new/old Navigation like:
Then it can wrap pages at the .~/index.js by
import MainTabNav from './main-tab-nav'; import isWCNavigationEnabled from '.~/utils/isWCNavigationEnabled'; const withOldNav = ( WrappedPage ) => ( props ) => { return ( <> { ! isWCNavigationEnabled() && <MainTabNav /> } <WrappedPage { ...props } /> </> ); };
Or wrap pages individually at each page's index.js. Take the dashboard index.js as an examplecontainer: withOldNav( Dashboard ),
This way, it could avoid adding the same logic to every main page, and it would be easier to remove the old navigation supporting in the future.export default withOldNav( Dashboard );
Conflicts: js/src/product-feed/index.js js/src/reports/programs/index.js
…on WC Navigation.
Yeah, this is actually related to the problem I mentioned in the PR description (I mentioned the case for Report pages, but it applies to the add campaign page, edit campaign page and edit free listings page like you have discovered). The problem is: (quoted from PR description)
To fix this, we need to deal with the path, e.g. for edit free listings page, instead of using I'm thinking maybe we should work on these pages (reports pages and these add and edit pages) as a separate issue. I'll work on that after this PR is done.
That's a good catch, I was having a bit of funny feeling when I was doing For this case, I don't prefer to use HOC though. I usually use HOC for sharing logic or cross-cutting concerns (which has been replaced by hooks). Because we still want to render something (the |
Also, I'm thinking maybe it's good to get some additional eyes on the PHP side of things (8 .php files changed in this PR). Maybe either one of @mikkamp @layoutd @nima-karimi could help out? 🙏 😄 |
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.
LGTM.
@j111q , almost forgot, please see the PR description for the WC Navigation integration demo video. 🎥 😄 |
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.
💯 Looks good, two small notes.
@@ -36,25 +37,57 @@ function( $menu_items ) { | |||
add_action( | |||
'admin_menu', | |||
function() { |
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.
💅 This could all be moved to a separate function (similar to add_items
in the woocommerce_marketing_menu_items
hook).
src/Menu/Dashboard.php
Outdated
} | ||
); | ||
} | ||
|
||
/** | ||
* Add Google Menu item under Marketing | ||
* Add Google Menu item under Marketing, when WC Navigation is not enabled. | ||
* | ||
* @param array $items | ||
* | ||
* @return array | ||
*/ | ||
protected function add_items( array $items ): array { |
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.
💅 Since items are conditionally added, perhaps the function name should be updated to reflect that (maybe_
...).
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.
Looks good. Got similar comments as @layoutd but just sending them anyways.
src/Menu/Dashboard.php
Outdated
if ( ! Features::is_enabled( 'navigation' ) ) { | ||
$items[] = [ | ||
'id' => 'google-dashboard', | ||
'title' => __( 'Google Listings & Ads', 'google-listings-and-ads' ), | ||
'path' => '/google/dashboard', | ||
'capability' => 'manage_woocommerce', | ||
]; | ||
} |
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.
Works fine this way, but for readability I would have refactored it slightly different:
if ( ! Features::is_enabled( 'navigation' ) ) { | |
$items[] = [ | |
'id' => 'google-dashboard', | |
'title' => __( 'Google Listings & Ads', 'google-listings-and-ads' ), | |
'path' => '/google/dashboard', | |
'capability' => 'manage_woocommerce', | |
]; | |
} | |
if ( Features::is_enabled( 'navigation' ) ) { | |
return $items; | |
} | |
$items[] = [ | |
'id' => 'google-dashboard', | |
'title' => __( 'Google Listings & Ads', 'google-listings-and-ads' ), | |
'path' => '/google/dashboard', | |
'capability' => 'manage_woocommerce', | |
]; |
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.
Actually, it's even better to move the condition a level higher (and leave the add_items function as is).
add_filter(
'woocommerce_marketing_menu_items',
function( $menu_items ) {
if ( Features::is_enabled( 'navigation' ) ) {
return $items;
}
return $this->add_items( $menu_items );
}
);
src/Menu/Dashboard.php
Outdated
if ( ! Features::is_enabled( 'navigation' ) ) { | ||
$this->fix_menu_paths(); | ||
} else { | ||
wc_admin_register_page( |
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.
I'd move this functionality to a helper function so we can simplify the code in this action. Something like:
$this->register_navigation_pages();
7 lines of closing brackets in a row gets to be a bit much.
src/Menu/GetStarted.php
Outdated
if ( ! Features::is_enabled( 'navigation' ) ) { | ||
$this->fix_menu_paths(); | ||
} else { | ||
wc_admin_register_page( |
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.
Same refactoring as suggested in the Dashboard page.
src/Menu/Reports/Reports.php
Outdated
'admin_menu', | ||
function() { | ||
if ( apply_filters( 'gla_enable_reports', true ) ) { | ||
wc_admin_register_page( |
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.
Here again I'd move this to a separate helper function to reduce the closing brackets (reached 8 in a row here).
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.
The latest PHP changes look good, they are working well for me.
I just noticed that when I navigate from GLA > Reports > Programs to GLA > Reports > Products, the nav jumps back to WooCommerce Home, instead of staying on GLA.
@mikkamp ,
Yeah that is a known issue, I mentioned that in the PR description, in essence it is because:
I've created issue #665 to address this. |
Changes proposed in this Pull Request:
Closes #285 .
This PR makes our GLA plugin work with the new WC Navigation experience.
Technical notes
In
js/src/index.js
,title
seemed to be not used at all, I removed them in 3b577f5.The WC Navigation menu item text depends on breadcrumbs (see code: https://github.com/woocommerce/woocommerce-admin/blob/7d70ebdd168eb91ccf0c6be4c7aec1ef7f07189d/client/layout/navigation.js#L68). Without changing the breadcrumbs, all the menu items show "Google Listings & Ads" (this was one of the major pains for me to figure out in this PR). So I had to fix the breadcrumbs, which was done in 706c8d8.
In the WC Navigation menu, when you click on menu items at the same hierarchy level, there will be menu transition animation, which does not match normal user experience. I believe this is an issue with WC Navigation. I looked into WC Payment https://github.com/Automattic/woocommerce-payments and their plugin is having the same issue as well.
Screen.Recording.2021-05-20.at.4.07.45.AM.mov
WC Navigation menu items are displayed based on
path
in the URL. If thepath
does not correspond to any items in the WC Navigation, then it will show the root WooCommerce level. This presents a problem for us in the report pages, because we have Programs Report atpath=/google/reports/programs
and Products Report atpath=/google/reports/products
, but we only have one "Reports" menu item in the WC Navigation, which I have tied topath=/google/reports/programs
. This means that when we are displaying Programs Report, WC Navigation will display the menu item correctly, but when we navigate to Products Report, WC Navigation will show the root WooCommerce level. You can see this in the demo video below. To solve this problem, I'd suggest two ways:path=/google/reports/programs
andpath=/google/reports/products
, we use another parameter to represent the type of report, e.g.path=/google/reports&report=programs
andpath=/google/reports&report=products
. With this, thepath
always bepath=/google/reports
, and the WC Navigation menu item "Reports" will always show correctly. If this is ok, we can work on this in a separate issue.Update 2021-05-25: I've created issue #665 to address the URL
path
issue.Screenshots:
Demo video with my voice: https://d.pr/v/jLpVI2
wc-navigation-with-gla.mp4
Detailed test instructions:
Note: You can turn on/off the WC Navigation experience at https://gla1.test/wp-admin/admin.php?page=wc-settings&tab=advanced§ion=features.
FullScreen
component.)FullContainer
component.)Changelog Note:
Integrate GLA plugin with the new WC Navigation experience.