Merge pull request #507 from woocommerce/fix-onboarding-js-loading

Load onboarding assets only on the first tab
This commit is contained in:
Emili Castells 2022-02-22 09:33:37 +01:00 committed by GitHub
commit 4fa6c30595
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 4 deletions

View file

@ -133,7 +133,8 @@ return array(
$container->get( 'onboarding.url' ),
$state,
$container->get( 'onboarding.environment' ),
$login_seller_endpoint
$login_seller_endpoint,
$container->get( 'wcgateway.current-ppcp-settings-page-id' )
);
},

View file

@ -12,6 +12,7 @@ namespace WooCommerce\PayPalCommerce\Onboarding\Assets;
use WooCommerce\PayPalCommerce\Onboarding\Endpoint\LoginSellerEndpoint;
use WooCommerce\PayPalCommerce\Onboarding\Environment;
use WooCommerce\PayPalCommerce\Onboarding\State;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
/**
* Class OnboardingAssets
@ -46,6 +47,13 @@ class OnboardingAssets {
*/
private $login_seller_endpoint;
/**
* ID of the current PPCP gateway settings page, or empty if it is not such page.
*
* @var string
*/
protected $page_id;
/**
* OnboardingAssets constructor.
*
@ -53,18 +61,21 @@ class OnboardingAssets {
* @param State $state The State object.
* @param Environment $environment The Environment.
* @param LoginSellerEndpoint $login_seller_endpoint The LoginSeller endpoint.
* @param string $page_id ID of the current PPCP gateway settings page, or empty if it is not such page.
*/
public function __construct(
string $module_url,
State $state,
Environment $environment,
LoginSellerEndpoint $login_seller_endpoint
LoginSellerEndpoint $login_seller_endpoint,
string $page_id
) {
$this->module_url = untrailingslashit( $module_url );
$this->state = $state;
$this->environment = $environment;
$this->login_seller_endpoint = $login_seller_endpoint;
$this->page_id = $page_id;
}
/**
@ -149,7 +160,6 @@ class OnboardingAssets {
* @return bool
*/
private function should_render_onboarding_script(): bool {
global $current_section;
return 'ppcp-gateway' === $current_section;
return PayPalGateway::ID === $this->page_id;
}
}