Skip to content
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

Merged
merged 36 commits into from
May 25, 2021
Merged

Integration with new WC Navigation #605

merged 36 commits into from
May 25, 2021

Conversation

ecgan
Copy link
Member

@ecgan ecgan commented May 13, 2021

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 the path 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 at path=/google/reports/programs and Products Report at path=/google/reports/products, but we only have one "Reports" menu item in the WC Navigation, which I have tied to path=/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:

  1. Make the "Reports" a menu category, clicking on it will display another WC Navigation level with the two reports. This means we would need to ditch the Reports tab-based navigation. One problem with this during my experimentation is that the "Reports" menu category would appear at the very top above "Dashboard". I'm guessing there is some sort of logic to put menu category first followed by menu items.
  2. Instead of using path=/google/reports/programs and path=/google/reports/products, we use another parameter to represent the type of report, e.g. path=/google/reports&report=programs and path=/google/reports&report=products. With this, the path always be path=/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&section=features.

  1. Turn on the WC Navigation experience.
  2. When Setup MC is not completed yet, there should be only one Google Listings and Ads menu item, and clicking on it will display the Get Started page.
  3. Click the Set up free listings button to start Setup MC flow. The Setup MC flow pages should display OK. (This uses the FullScreen component.)
  4. When Setup MC is completed, the Google Listings and Ads menu would become a category. Clicking on it will show the next level of menu items.
  5. Browse through the Dashboard, Reports, Product Feed, and Settings pages. They should display OK.
  6. Go to Dashboard and click on the Edit button for Free Listings. The Edit Free Listings page should display OK. (This uses the FullContainer component.)
  7. Turn off the WC Navigation experience and repeat the above steps.

Changelog Note:

Integrate GLA plugin with the new WC Navigation experience.

@ecgan ecgan self-assigned this May 13, 2021
Conflicts:
	js/src/reports/programs/index.js
@ecgan ecgan requested a review from a team May 19, 2021 19:52
@ecgan ecgan changed the title DRAFT: New Navigation Integration with new WC Navigation May 19, 2021
@jconroy
Copy link
Member

jconroy commented May 20, 2021

Awesome thanks @ecgan

Copy link
Member

@eason9487 eason9487 left a 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.
    2021-05-20 17 12 37
  • 📜 . Probably here is the pattern to consider having a HOC to conditional switching the new/old Navigation like:
    import MainTabNav from './main-tab-nav';
    import isWCNavigationEnabled from '.~/utils/isWCNavigationEnabled';
    
    const withOldNav = ( WrappedPage ) => ( props ) => {
    	return (
    		<>
    			{ ! isWCNavigationEnabled() && <MainTabNav /> }
    			<WrappedPage { ...props } />
    		</>
    	);
    };
    Then it can wrap pages at the .~/index.js by
    container: withOldNav( Dashboard ),
    Or wrap pages individually at each page's index.js. Take the dashboard index.js as an example
    export default 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.

js/src/reports/products/index.js Outdated Show resolved Hide resolved
js/src/utils/isWCNavigationEnabled.js Outdated Show resolved Hide resolved
src/Menu/Reports/Reports.php Outdated Show resolved Hide resolved
js/src/index.js Outdated Show resolved Hide resolved
js/src/index.js Outdated Show resolved Hide resolved
@ecgan
Copy link
Member Author

ecgan commented May 24, 2021

@eason9487 ,

  • 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.

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)

WC Navigation menu items are displayed based on path in the URL. If the path does not correspond to any items in the WC Navigation, then it will show the root WooCommerce level.

To fix this, we need to deal with the path, e.g. for edit free listings page, instead of using path=/google/edit-free-campaign, we use path=/google/dashboard&subpath=edit-free-campaign so that when edit free listings page is displayed, the Dashboard menu item is displayed and highlighted. We can think of it as edit free listings page is a child of dashboard page.

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.


  • Probably here is the pattern to consider having a HOC to conditional switching the new/old Navigation

That's a good catch, I was having a bit of funny feeling when I was doing import isWCNavigationEnabled and then coding the <MainTabNav> in the files.

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 MainTabNav) based on some conditional logic, I'd prefer it to be a component. I came up with a NavigationClassic component in 74133a8. With this approach, each page is able to dictate where the NavigationClassic shows up (e.g. we can wrap it in a div like in the Settings page), which would be more difficult to do if we use HOC.

@ecgan ecgan requested a review from eason9487 May 24, 2021 19:43
@ecgan
Copy link
Member Author

ecgan commented May 24, 2021

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? 🙏 😄

Copy link
Member

@eason9487 eason9487 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@ecgan
Copy link
Member Author

ecgan commented May 25, 2021

@j111q , almost forgot, please see the PR description for the WC Navigation integration demo video. 🎥 😄

Copy link
Contributor

@layoutd layoutd left a 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() {
Copy link
Contributor

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).

}
);
}

/**
* 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 {
Copy link
Contributor

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_...).

Copy link
Contributor

@mikkamp mikkamp left a 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.

Comment on lines 83 to 90
if ( ! Features::is_enabled( 'navigation' ) ) {
$items[] = [
'id' => 'google-dashboard',
'title' => __( 'Google Listings & Ads', 'google-listings-and-ads' ),
'path' => '/google/dashboard',
'capability' => 'manage_woocommerce',
];
}
Copy link
Contributor

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:

Suggested change
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',
];

Copy link
Contributor

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 );
			}
		);

if ( ! Features::is_enabled( 'navigation' ) ) {
$this->fix_menu_paths();
} else {
wc_admin_register_page(
Copy link
Contributor

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.

if ( ! Features::is_enabled( 'navigation' ) ) {
$this->fix_menu_paths();
} else {
wc_admin_register_page(
Copy link
Contributor

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.

'admin_menu',
function() {
if ( apply_filters( 'gla_enable_reports', true ) ) {
wc_admin_register_page(
Copy link
Contributor

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).

Copy link
Contributor

@mikkamp mikkamp left a 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.

@ecgan
Copy link
Member Author

ecgan commented May 25, 2021

@mikkamp ,

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.

Yeah that is a known issue, I mentioned that in the PR description, in essence it is because:

WC Navigation menu items are displayed based on path in the URL. If the path does not correspond to any items in the WC Navigation, then it will show the root WooCommerce level.

I've created issue #665 to address this.

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.

WooCommerce Navigation
5 participants