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.
  • Loading branch information
tomalec committed Jul 26, 2023
1 parent da3a5de commit ecdee9b
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 176 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 );

Check warning on line 302 in src/Internal/DependencyManagement/CoreServiceProvider.php

View check run for this annotation

Codecov / codecov/patch

src/Internal/DependencyManagement/CoreServiceProvider.php#L302

Added line #L302 was not covered by tests
$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
95 changes: 14 additions & 81 deletions src/TaskList/CompleteSetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,102 +3,35 @@

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;
use Automattic\WooCommerce\GoogleListingsAndAds\TaskList\CompleteSetupTask;

/**
* Class CompleteSetup
*
* @package Automattic\WooCommerce\GoogleListingsAndAds\TaskList
*/
class CompleteSetup implements Deactivateable, Service, Registerable, Conditional, 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;
}
class CompleteSetup implements Service, Registerable {

/**
* Register a service.
*
* Add CompleteSetupTask to the extended task list on init.
*/
public function register(): void {
$this->assets_handler->add_many( $this->get_assets() );

add_action(
'admin_enqueue_scripts',
function () {
if ( ! $this->should_register_tasks() ) {
return;
}

$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' );
'init',
function() {
$task_list = 'extended';
$task = new CompleteSetupTask(
TaskLists::get_list( $task_list )
);
TaskLists::add_task( $task_list, $task );

Check warning on line 31 in src/TaskList/CompleteSetup.php

View check run for this annotation

Codecov / codecov/patch

src/TaskList/CompleteSetup.php#L25-L31

Added lines #L25 - L31 were not covered by tests

do_action( 'add_woocommerce_extended_task_list_item', $task->get_id() );

Check warning on line 33 in src/TaskList/CompleteSetup.php

View check run for this annotation

Codecov / codecov/patch

src/TaskList/CompleteSetup.php#L33

Added line #L33 was not covered by tests
}
);
}

/**
* 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(),
]
);

return $assets;
}

/**
* 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' );
}
}
90 changes: 90 additions & 0 deletions src/TaskList/CompleteSetupTask.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php
declare( strict_types=1 );

namespace Automattic\WooCommerce\GoogleListingsAndAds\TaskList;

use Automattic\WooCommerce\Admin\Features\OnboardingTasks\Task;
use Automattic\WooCommerce\GoogleListingsAndAds\MerchantCenter\MerchantCenterAwareInterface;
use Automattic\WooCommerce\GoogleListingsAndAds\MerchantCenter\MerchantCenterAwareTrait;

/**
* Complete Setup Task to be added to the extended task list.
*
* @package Automattic\WooCommerce\GoogleListingsAndAds\TaskList
*/
class CompleteSetupTask extends Task implements MerchantCenterAwareInterface {

use MerchantCenterAwareTrait;

/**
* Get the task id.
*
* @return string
*/
public function get_id() {
return 'gla_complete_setup';

Check warning on line 25 in src/TaskList/CompleteSetupTask.php

View check run for this annotation

Codecov / codecov/patch

src/TaskList/CompleteSetupTask.php#L24-L25

Added lines #L24 - L25 were not covered by tests
}

/**
* Get the task name.
*
* @return string
*/
public function get_title() {
return __(
'Set up Google Listings & Ads',
'google-listings-and-ads'
);

Check warning on line 37 in src/TaskList/CompleteSetupTask.php

View check run for this annotation

Codecov / codecov/patch

src/TaskList/CompleteSetupTask.php#L33-L37

Added lines #L33 - L37 were not covered by tests
}

/**
* Get the task description.
*
* @return string empty string
*/
public function get_content() {
return '';

Check warning on line 46 in src/TaskList/CompleteSetupTask.php

View check run for this annotation

Codecov / codecov/patch

src/TaskList/CompleteSetupTask.php#L45-L46

Added lines #L45 - L46 were not covered by tests
}

/**
* Get the task completion time.
*
* @return string
*/
public function get_time() {
return __( '20 minutes', 'woocommerce' );

Check failure on line 55 in src/TaskList/CompleteSetupTask.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Mismatched text domain. Expected 'google-listings-and-ads' but got 'woocommerce'.

Check warning on line 55 in src/TaskList/CompleteSetupTask.php

View check run for this annotation

Codecov / codecov/patch

src/TaskList/CompleteSetupTask.php#L54-L55

Added lines #L54 - L55 were not covered by tests
}

/**
* Always dismissable.
*
* @return bool
*/
public function is_dismissable() {
return true;

Check warning on line 64 in src/TaskList/CompleteSetupTask.php

View check run for this annotation

Codecov / codecov/patch

src/TaskList/CompleteSetupTask.php#L63-L64

Added lines #L63 - L64 were not covered by tests
}

/**
* Get completion status.
* Forwards from the merchant center setup status.
*
* @return bool
*/
public function is_complete() {
return $this->merchant_center && $this->merchant_center->is_setup_complete() || false;

Check warning on line 74 in src/TaskList/CompleteSetupTask.php

View check run for this annotation

Codecov / codecov/patch

src/TaskList/CompleteSetupTask.php#L73-L74

Added lines #L73 - L74 were not covered by tests
}

/**
* Get the action URL.
*
* @return string Start page or dashboard is the setup is completed.
*/
public function get_action_url() {
if ( ! $this->is_complete() ) {
return admin_url( 'admin.php?page=wc-admin&path=/google/start' );

Check warning on line 84 in src/TaskList/CompleteSetupTask.php

View check run for this annotation

Codecov / codecov/patch

src/TaskList/CompleteSetupTask.php#L82-L84

Added lines #L82 - L84 were not covered by tests
}

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

Check warning on line 87 in src/TaskList/CompleteSetupTask.php

View check run for this annotation

Codecov / codecov/patch

src/TaskList/CompleteSetupTask.php#L87

Added line #L87 was not covered by tests
}

}
36 changes: 0 additions & 36 deletions src/TaskList/TaskListTrait.php

This file was deleted.

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 ecdee9b

Please sign in to comment.