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

Product Block Editor: Add a custom block for prompting user to complete onboarding #2237

Conversation

eason9487
Copy link
Member

@eason9487 eason9487 commented Feb 5, 2024

Changes proposed in this Pull Request:

With the original product editor, this extension shows a prompt if the user has not yet completed onboarding.

image

To have a consistent prompt in the Product Block Editor, this PR:

  • Change to let the ChannelVisibilityBlock handle its own registration as it has different conditions than ProductBlocksService.
  • Change ProductBlocksService to still add a group for this extension and register custom blocks when the onboarding is not yet completed.
  • Add a new custom block for prompting the user to complete the onboarding.
  • Show the onboarding prompt in the Product Block Editor when it's not yet completed.
  • Extra changes:
    • Fix the integrity checks for woocommerce-grow-jsdoc and woocommerce-grow-storybook.
    • Fix the deprecations of using ${var} in a string for the ProductBlocksService class.

Screenshots:

Kapture.2024-02-05.at.18.26.04.mp4

Detailed test instructions:

📌 Prepare test environment

  1. Please refer to the test preparation in PR 2151 with Woo 8.5.1.
    • 💡 Please note that the current implementation doesn't work with Woo >= 8.6 due to breaking changes. This will be fixed by another PR.
  2. npm install
  3. npm start
  4. To control the onboarding status, locally changing this return value would be easier to test.
    public function is_setup_complete(): bool {
    return boolval( $this->options->get( OptionsInterface::MC_SETUP_COMPLETED_AT, false ) );
    }

📌 Test the onboarding prompt

  1. Set the onboarding status to not completed.
  2. Go to edit a simple product, e.g. the Beanie with Logo imported from WC's sample products.
  3. Switch to the Google Listings & Ads tab.
  4. Check if it shows a prompt as in the following screenshot.
    image
  5. Click the "Get Started" button to see if it brings you to this extension's Get Started page.
  6. Repeat this test with variable and variation products.

Changelog entry

@eason9487 eason9487 requested a review from a team February 5, 2024 10:45
@eason9487 eason9487 self-assigned this Feb 5, 2024
@github-actions github-actions bot added changelog: add A new feature, function, or functionality was added. type: enhancement The issue is a request for an enhancement. labels Feb 5, 2024
Copy link

codecov bot commented Feb 5, 2024

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (4f2e536) 61.5% compared to head (20d8e0c) 61.5%.

Additional details and impacted files

Impacted file tree graph

@@                          Coverage Diff                           @@
##             feature/support-product-block-editor   #2237   +/-   ##
======================================================================
  Coverage                                    61.5%   61.5%           
- Complexity                                   4184    4185    +1     
======================================================================
  Files                                         748     748           
  Lines                                       21529   21538    +9     
  Branches                                      532     532           
======================================================================
+ Hits                                        13232   13244   +12     
+ Misses                                       7846    7843    -3     
  Partials                                      451     451           
Flag Coverage Δ
js-unit-tests 54.0% <ø> (ø)
php-unit-tests 63.1% <92.3%> (+<0.1%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
src/Admin/Product/ChannelVisibilityBlock.php 100.0% <100.0%> (ø)
src/Admin/ProductBlocksService.php 96.8% <100.0%> (+1.0%) ⬆️
...ernal/DependencyManagement/CoreServiceProvider.php 0.0% <0.0%> (ø)

... and 1 file with indirect coverage changes

@eason9487 eason9487 force-pushed the add/product-block-editor-prompt-user-to-complete-onboarding branch from b6ccd44 to d75ee28 Compare February 5, 2024 11:38
Copy link
Contributor

@puntope puntope left a comment

Choose a reason for hiding this comment

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

Thanks for the changes @eason9487 ✅ LGTM

  • I tested the product-onboarding-prompt and I can see it when the onboarding is not completed.
  • When it's completed then it shows the GLA blocks instead.

❓Not introduced in this PR but it seems that ChannelVisibilityBlock::update_data and ChannelVisibilityBlock::prepare_data have the wrong type in the params. Shouldn't be just WC_Product instead of WC_Data ?

Actually. We return if $product is not WC_Product

if ( ! $product instanceof WC_Product || ! in_array( $product->get_type(), $this->get_visible_product_types(), true ) ) {
			return;
		}

Comment on lines +54 to +56
if ( ! $this->merchant_center->is_setup_complete() ) {
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

💅 Why not make this controller conditional as well?

Copy link
Member Author

@eason9487 eason9487 Feb 6, 2024

Choose a reason for hiding this comment

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

The Conditional::is_needed method is static but the MerchantCenterService::is_setup_complete method is not static, so this service cannot be registered conditionally.

$this->variation_anchor_group->get_root_template()
->expects( $this->exactly( 0 ) )
->expects( $this->exactly( 1 ) )
Copy link
Contributor

Choose a reason for hiding this comment

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

💅 Another simple version for $this->exactly( 1 ) and $this->exactly( 0 ) that we normally use is $this->once() and $this->never(). Not against using $this->exactly() just mentioning it in case you didn't know.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the information. I chose exactly because it's relatively effortless to maintain.

@eason9487
Copy link
Member Author

Hi @puntope, thanks for the review!

❓Not introduced in this PR but it seems that ChannelVisibilityBlock::update_data and ChannelVisibilityBlock::prepare_data have the wrong type in the params. Shouldn't be just WC_Product instead of WC_Data ?

Actually. We return if $product is not WC_Product
[...]

The code reviews in #2214 did discuss this, please refer to #2214 (comment) and #2214 (comment).

@eason9487 eason9487 force-pushed the add/product-block-editor-prompt-user-to-complete-onboarding branch from 222d5e1 to 20d8e0c Compare February 7, 2024 03:19
@eason9487
Copy link
Member Author

eason9487 commented Feb 7, 2024

Rebased this PR onto the current feature/support-product-block-editor branch (4f2e536) and also removed the integrity checksum fix (d75ee28) in favor of the same fix merged in #2241.

@eason9487 eason9487 merged commit c08f614 into feature/support-product-block-editor Feb 7, 2024
14 checks passed
@eason9487 eason9487 deleted the add/product-block-editor-prompt-user-to-complete-onboarding branch February 7, 2024 03:27
@eason9487 eason9487 mentioned this pull request Feb 27, 2024
21 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: add A new feature, function, or functionality was added. type: enhancement The issue is a request for an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants