Skip to content

Commit

Permalink
Add task using TaskLists::add_task API,
Browse files Browse the repository at this point in the history
`woocommerce_admin_onboarding_task_list` is deprecated.
Fixes #2024

Remove `remove_woocommerce_extended_task_list_item` hook.

Mock the use of `$this->merchant_center->is_setup_complete()`.
  • Loading branch information
tomalec committed Jul 26, 2023
1 parent da3a5de commit 21a172c
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 131 deletions.
45 changes: 0 additions & 45 deletions js/src/tasks/complete-setup/index.js

This file was deleted.

8 changes: 0 additions & 8 deletions src/Hooks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,6 @@ A list of hooks, i.e `actions` and `filters`, that are defined or used in this p

- <a href="https://github.com/woocommerce/google-listings-and-ads/blob/develop/src/Admin/BulkEdit/BulkEditInitializer.php#L36">BulkEditInitializer.php#L36</a>

## remove_woocommerce_extended_task_list_item

**Type**: action

**Used in**:

- <a href="https://github.com/woocommerce/google-listings-and-ads/blob/develop/src/TaskList/CompleteSetup.php#L102">CompleteSetup.php#L102</a>

## woocommerce_admin_disabled

**Type**: filter
Expand Down
2 changes: 1 addition & 1 deletion src/Internal/DependencyManagement/CoreServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ function ( ...$arguments ) {
$this->conditionally_share_with_tags( EventTracking::class, ContainerInterface::class );
$this->conditionally_share_with_tags( RESTControllers::class, ContainerInterface::class );
$this->conditionally_share_with_tags( ConnectionTest::class, ContainerInterface::class );
$this->conditionally_share_with_tags( CompleteSetup::class, AssetsHandlerInterface::class );
$this->conditionally_share_with_tags( CompleteSetup::class );
$this->conditionally_share_with_tags( GlobalSiteTag::class, AssetsHandlerInterface::class, GoogleGtagJs::class, ProductHelper::class, WC::class, WP::class );
$this->share_with_tags( SiteVerificationMeta::class );
$this->conditionally_share_with_tags( MerchantSetupCompleted::class );
Expand Down
121 changes: 49 additions & 72 deletions src/TaskList/CompleteSetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,103 +2,80 @@
declare( strict_types=1 );

namespace Automattic\WooCommerce\GoogleListingsAndAds\TaskList;

use Automattic\WooCommerce\GoogleListingsAndAds\Assets\AdminScriptWithBuiltDependenciesAsset;
use Automattic\WooCommerce\GoogleListingsAndAds\Assets\Asset;
use Automattic\WooCommerce\GoogleListingsAndAds\Assets\AssetsHandlerInterface;
use Automattic\WooCommerce\GoogleListingsAndAds\Infrastructure\AdminConditional;
use Automattic\WooCommerce\GoogleListingsAndAds\Infrastructure\Conditional;
use Automattic\WooCommerce\GoogleListingsAndAds\Infrastructure\Deactivateable;
use Automattic\WooCommerce\Admin\Features\OnboardingTasks\TaskLists;
use Automattic\WooCommerce\GoogleListingsAndAds\Infrastructure\Registerable;
use Automattic\WooCommerce\GoogleListingsAndAds\Infrastructure\Service;
use Automattic\WooCommerce\GoogleListingsAndAds\MerchantCenter\MerchantCenterAwareInterface;
use Automattic\WooCommerce\GoogleListingsAndAds\MerchantCenter\MerchantCenterAwareTrait;
use Automattic\WooCommerce\GoogleListingsAndAds\PluginHelper;
use Automattic\WooCommerce\GoogleListingsAndAds\Value\BuiltScriptDependencyArray;

/**
* Class CompleteSetup
*
* @package Automattic\WooCommerce\GoogleListingsAndAds\TaskList
*/
class CompleteSetup implements Deactivateable, Service, Registerable, Conditional, MerchantCenterAwareInterface {
class CompleteSetup implements Service, Registerable, MerchantCenterAwareInterface {

use AdminConditional;
use MerchantCenterAwareTrait;
use PluginHelper;
use TaskListTrait;

/**
* @var AssetsHandlerInterface
*/
protected $assets_handler;

/**
* CompleteSetup constructor.
*
* @param AssetsHandlerInterface $assets_handler
*/
public function __construct( AssetsHandlerInterface $assets_handler ) {
$this->assets_handler = $assets_handler;
}

/**
* Register a service.
*/
public function register(): void {
$this->assets_handler->add_many( $this->get_assets() );

add_action(
'admin_enqueue_scripts',
function () {
if ( ! $this->should_register_tasks() ) {
return;
}
'init',
function() {
$task_list = 'extended';
$task = new CompleteSetupTask(
TaskLists::get_list( $task_list )
);
TaskLists::add_task( $task_list, $task );

$this->assets_handler->enqueue_many( $this->get_assets() );

// argument matches the task "key" property
do_action( 'add_woocommerce_extended_task_list_item', 'gla_complete_setup' );
do_action( 'add_woocommerce_extended_task_list_item', $task->get_id() );
}
);
}
}

/**
* Return an array of assets.
*
* @return Asset[]
*/
protected function get_assets(): array {
$assets[] = ( new AdminScriptWithBuiltDependenciesAsset(
'gla-task-complete-setup',
'js/build/task-complete-setup',
"{$this->get_root_dir()}/js/build/task-complete-setup.asset.php",
new BuiltScriptDependencyArray(
[
'dependencies' => [],
'version' => (string) filemtime( "{$this->get_root_dir()}/js/build/task-complete-setup.js" ),
]
),
function () {
return $this->should_register_tasks();
}
) )->add_localization(
'glaTaskData',
[
'isComplete' => $this->merchant_center->is_setup_complete(),
]
);
use Automattic\WooCommerce\Admin\Features\OnboardingTasks\Task;

return $assets;
class CompleteSetupTask extends Task {
public function get_id() {
return 'gla_complete_setup';
}

/**
* Deactivate the service.
*
* @return void
*/
public function deactivate(): void {
// argument matches the task "key" property
do_action( 'remove_woocommerce_extended_task_list_item', 'gla_complete_setup' );
public function get_title() {
return __(
'Set up Google Listings & Ads',
'google-listings-and-ads'
);
}
}

public function get_content() {
return __( 'Add your task description here for display in the task list.', 'woocommerce');
}

public function get_time() {
return __( '20 minutes', 'woocommerce' );
}

public function is_dismissable() {
return true;
}

public function is_complete() {
// return false;//$this->merchant_center->is_setup_complete();
return false;
}

public function get_action_url() {

// if ( ! $this->merchant_center->is_setup_complete() ) {
if ( ! false ) {
return admin_url( 'admin.php?page=wc-admin&path=/google/start' );
}

return admin_url( 'admin.php?page=wc-admin&path=/google/dashboard' );
}

}
5 changes: 0 additions & 5 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,6 @@ const webpackConfig = {
],
entry: {
index: path.resolve( process.cwd(), 'js/src', 'index.js' ),
'task-complete-setup': path.resolve(
process.cwd(),
'js/src/tasks/complete-setup',
'index.js'
),
'custom-inputs': path.resolve(
process.cwd(),
'js/src/custom-inputs',
Expand Down

0 comments on commit 21a172c

Please sign in to comment.