Load onboarding assets only on the first tab

This commit is contained in:
Alex P 2022-02-22 09:55:46 +02:00
parent c1cd718ecc
commit 4a858bd5b8
2 changed files with 15 additions and 4 deletions

View file

@ -133,7 +133,8 @@ return array(
$container->get( 'onboarding.url' ), $container->get( 'onboarding.url' ),
$state, $state,
$container->get( 'onboarding.environment' ), $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\Endpoint\LoginSellerEndpoint;
use WooCommerce\PayPalCommerce\Onboarding\Environment; use WooCommerce\PayPalCommerce\Onboarding\Environment;
use WooCommerce\PayPalCommerce\Onboarding\State; use WooCommerce\PayPalCommerce\Onboarding\State;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
/** /**
* Class OnboardingAssets * Class OnboardingAssets
@ -46,6 +47,13 @@ class OnboardingAssets {
*/ */
private $login_seller_endpoint; 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. * OnboardingAssets constructor.
* *
@ -53,18 +61,21 @@ class OnboardingAssets {
* @param State $state The State object. * @param State $state The State object.
* @param Environment $environment The Environment. * @param Environment $environment The Environment.
* @param LoginSellerEndpoint $login_seller_endpoint The LoginSeller endpoint. * @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( public function __construct(
string $module_url, string $module_url,
State $state, State $state,
Environment $environment, Environment $environment,
LoginSellerEndpoint $login_seller_endpoint LoginSellerEndpoint $login_seller_endpoint,
string $page_id
) { ) {
$this->module_url = untrailingslashit( $module_url ); $this->module_url = untrailingslashit( $module_url );
$this->state = $state; $this->state = $state;
$this->environment = $environment; $this->environment = $environment;
$this->login_seller_endpoint = $login_seller_endpoint; $this->login_seller_endpoint = $login_seller_endpoint;
$this->page_id = $page_id;
} }
/** /**
@ -149,7 +160,6 @@ class OnboardingAssets {
* @return bool * @return bool
*/ */
private function should_render_onboarding_script(): bool { private function should_render_onboarding_script(): bool {
global $current_section; return PayPalGateway::ID === $this->page_id;
return 'ppcp-gateway' === $current_section;
} }
} }