Skip to content

Commit

Permalink
Merge pull request #2049 from woocommerce/release/2.5.2
Browse files Browse the repository at this point in the history
release 2.5.2
  • Loading branch information
jorgemd24 authored Aug 8, 2023
2 parents fa2a652 + 32b8d04 commit 0c095a6
Show file tree
Hide file tree
Showing 19 changed files with 448 additions and 292 deletions.
7 changes: 7 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
*** WooCommerce Google Listings and Ads Changelog ***

= 2.5.2 - 2023-08-08 =
* Fix - Remove `add_woocommerce_extended_task_list_item` and `remove_woocommerce_extended_task_list_item` hooks.
* Fix - WordPress 6.3 compatibility: The forms and image selector may not work due to "setImmediate" deprecation.
* Tweak - Use the latest API to add an item to the WC tasks list.
* Tweak - WC 8.0 compatibility.
* Tweak - WP 6.3 compatibility.

= 2.5.1 - 2023-08-01 =
* Dev - Setup wp-env for E2E tests.
* Dev - automate merging trunk to develop after a release.
Expand Down
8 changes: 4 additions & 4 deletions google-listings-and-ads.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
* Plugin Name: Google Listings and Ads
* Plugin URL: https://wordpress.org/plugins/google-listings-and-ads/
* Description: Native integration with Google that allows merchants to easily display their products across Google’s network.
* Version: 2.5.1
* Version: 2.5.2
* Author: WooCommerce
* Author URI: https://woocommerce.com/
* Text Domain: google-listings-and-ads
* Requires at least: 5.9
* Tested up to: 6.2
* Tested up to: 6.3
* Requires PHP: 7.4
* Requires PHP Architecture: 64 bits
*
* WC requires at least: 6.9
* WC tested up to: 7.9
* WC tested up to: 8.0
* Woo:
*
* @package WooCommerce\Admin
Expand All @@ -30,7 +30,7 @@

defined( 'ABSPATH' ) || exit;

define( 'WC_GLA_VERSION', '2.5.1' ); // WRCS: DEFINED_VERSION.
define( 'WC_GLA_VERSION', '2.5.2' ); // WRCS: DEFINED_VERSION.

Check warning on line 33 in google-listings-and-ads.php

View check run for this annotation

Codecov / codecov/patch

google-listings-and-ads.php#L33

Added line #L33 was not covered by tests
define( 'WC_GLA_MIN_PHP_VER', '7.4' );
define( 'WC_GLA_MIN_WC_VER', '6.9' );

Expand Down
4 changes: 2 additions & 2 deletions js/src/components/adaptive-form/adaptive-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,12 @@ function AdaptiveForm( { onSubmit, extendAdapter, children, ...props }, ref ) {
// Related to WC 6.9. Only one delegate can be consumed at a time in this render prop to
// ensure the updating states will always be the latest when calling.
if ( batchQueue.length ) {
// Use `setImmediate` to avoid the warning of request state updates while rendering.
// Use `setTimeout` to avoid the warning of request state updates while rendering.
// Mutating a React hook state is an anti-pattern in most cases. Here is done intentionally
// because it's necessary to ensure this component will be triggered re-rendering through
// `setBatchQueue`, but also to avoid calling `setBatchQueue` here and triggering additional
// rendering again.
setImmediate( () => setDelegation( batchQueue.shift() ) );
setTimeout( () => setDelegation( batchQueue.shift() ) );
}

/* === Start of enhancement-related codes === */
Expand Down
109 changes: 109 additions & 0 deletions js/src/components/adaptive-form/adaptive-form.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,113 @@ describe( 'AdaptiveForm', () => {

expect( inspect ).toHaveBeenLastCalledWith( false, 0 );
} );

describe( 'Compatibility patches', () => {
it( 'Should update all changes to values for the synchronous multiple calls to `setValue`', async () => {
render(
<AdaptiveForm
initialValues={ {
firstName: 'Foo',
lastName: 'Bar',
email: '(empty)',
} }
validate={ alwaysValid }
>
{ ( { setValue, values } ) => {
return (
<>
<button
onClick={ () => {
setValue( 'firstName', 'Hey' );
setValue( 'lastName', 'Howdy' );
setValue( 'email', 'hi[at]greetings' );
} }
/>
<article>
{ `${ values.firstName } ${ values.lastName } ${ values.email }` }
</article>
</>
);
} }
</AdaptiveForm>
);

const article = screen.getByRole( 'article' );

expect( article.textContent ).toBe( 'Foo Bar (empty)' );

await act( async () => {
await userEvent.click( screen.getByRole( 'button' ) );
jest.runAllTimers();
} );

expect( article.textContent ).toBe( 'Hey Howdy hi[at]greetings' );
} );

it( 'Should call back to `onChange` for the changed value only', async () => {
const onChange = jest.fn();

render(
<AdaptiveForm
onChange={ onChange }
initialValues={ {
firstName: '',
lastName: '',
agreedTerms: false,
} }
validate={ alwaysValid }
>
{ ( { setValue, getInputProps } ) => {
return (
<>
<button
onClick={ () => {
setValue( 'firstName', 'Hey' );
} }
/>
<input
type="text"
{ ...getInputProps( 'lastName' ) }
/>
<input
type="checkbox"
{ ...getInputProps( 'agreedTerms' ) }
/>
</>
);
} }
</AdaptiveForm>
);

await act( async () => {
await userEvent.click( screen.getByRole( 'button' ) );
jest.runAllTimers();
} );

expect( onChange ).toHaveBeenCalledTimes( 1 );
expect( onChange ).toHaveBeenLastCalledWith(
{ name: 'firstName', value: 'Hey' },
expect.any( Object ),
true
);

await userEvent.type( screen.getByRole( 'textbox' ), 'a' );

expect( onChange ).toHaveBeenCalledTimes( 2 );
expect( onChange ).toHaveBeenLastCalledWith(
{ name: 'lastName', value: 'a' },
expect.any( Object ),
true
);

await userEvent.click( screen.getByRole( 'checkbox' ) );

expect( onChange ).toHaveBeenCalledTimes( 3 );
expect( onChange ).toHaveBeenLastCalledWith(
{ name: 'agreedTerms', value: true },
expect.any( Object ),
true
);
} );
} );
} );
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ export default function useCroppedImageSelector( {
// since `toolbar` will be triggered the refresh event at the end, so this function
// must be called after that.
if ( this === frame ) {
setImmediate( handleSelectionToggle );
setTimeout( handleSelectionToggle );
return;
}

Expand Down
45 changes: 0 additions & 45 deletions js/src/tasks/complete-setup/index.js

This file was deleted.

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "google-listings-and-ads",
"title": "Google Listings and Ads",
"version": "2.5.1",
"version": "2.5.2",
"description": "google-listings-and-ads",
"author": "Automattic",
"license": "GPL-3.0-or-later",
Expand Down Expand Up @@ -89,6 +89,7 @@
"check-licenses": "wp-scripts check-licenses",
"dev": "NODE_ENV=development wp-scripts build",
"dewps:woo": "node bin/list-woo-dewped.mjs",
"doc:hooks": "php bin/HooksDocsGenerator.php",
"doc:tracking": "woocommerce-grow-jsdoc ./js/src",
"docker:up": "WP_VERSION=6.1 npx wc-e2e docker:up",
"docker:down": "npx wc-e2e docker:down",
Expand Down
26 changes: 9 additions & 17 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
Contributors: automattic, google, woocommerce
Tags: woocommerce, google, listings, ads
Requires at least: 5.9
Tested up to: 6.2
Tested up to: 6.3
Requires PHP: 7.4
Requires PHP Architecture: 64 Bits
Stable tag: 2.5.1
Stable tag: 2.5.2
License: GPLv3
License URI: https://www.gnu.org/licenses/gpl-3.0.html

Expand Down Expand Up @@ -111,6 +111,13 @@ Yes, you can run both at the same time, and we recommend it! In the US, advertis

== Changelog ==

= 2.5.2 - 2023-08-08 =
* Fix - Remove `add_woocommerce_extended_task_list_item` and `remove_woocommerce_extended_task_list_item` hooks.
* Fix - WordPress 6.3 compatibility: The forms and image selector may not work due to "setImmediate" deprecation.
* Tweak - Use the latest API to add an item to the WC tasks list.
* Tweak - WC 8.0 compatibility.
* Tweak - WP 6.3 compatibility.

= 2.5.1 - 2023-08-01 =
* Dev - Setup wp-env for E2E tests.
* Dev - automate merging trunk to develop after a release.
Expand All @@ -123,19 +130,4 @@ Yes, you can run both at the same time, and we recommend it! In the US, advertis
* Tweak - Add Tip with information with Campaign assets are imported.
* Tweak - Provide more detailed error reasons when unable to complete site verification for the Google Merchant Center account being connected in the onboarding flow.

= 2.4.11 - 2023-07-11 =
* Add - Client name and plugin version to requests.
* Dev - Enable unit testing for PHP 8.1.
* Dev - Set engines for the repository.
* Fix - Avoid continuing to save settings to Google Merchant Center after the shipping time save failed on the Edit Free Listings page.
* Fix - Avoid errors when clearing all audience countries in the onboarding flow.
* Fix - Incorrectly display South America in the audience location selector after selecting Saudi Arabia.
* Fix - Remove deprecated $border-width-focus variable.
* Fix - Show a general error message when the phone number verification request is failed.
* Tweak - Add placeholder in the Attribute Mapping table when there are no rules available.
* Tweak - Changes for title, descriptions and FAQ in PMAX Optimized Campaigns.
* Tweak - Make some error messages clearer when errors occur in querying or modifying data.
* Tweak - Make the error message clearer for errors that occur in getting or updating a Google Merchant Center account.
* Tweak - WC 7.9 compatibility.

[See changelog for all versions](https://raw.githubusercontent.com/woocommerce/google-listings-and-ads/trunk/changelog.txt).
4 changes: 2 additions & 2 deletions src/Admin/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,12 @@ private function inject_fast_refresh_for_dev( $scripts ) {
$plugin_url = $this->get_plugin_url();

$scripts->add(
'gla-webpack-rumtime',
'gla-webpack-runtime',

Check warning on line 289 in src/Admin/Admin.php

View check run for this annotation

Codecov / codecov/patch

src/Admin/Admin.php#L289

Added line #L289 was not covered by tests
"{$plugin_url}/js/build/runtime.js",
[],
(string) filemtime( $runtime_path )
);
$react_script->deps[] = 'gla-webpack-rumtime';
$react_script->deps[] = 'gla-webpack-runtime';

Check warning on line 294 in src/Admin/Admin.php

View check run for this annotation

Codecov / codecov/patch

src/Admin/Admin.php#L294

Added line #L294 was not covered by tests

if ( ! in_array( 'wp-react-refresh-entry', $react_script->deps, true ) ) {
$scripts->add(
Expand Down
36 changes: 36 additions & 0 deletions src/Google/GlobalSiteTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ function () use ( $gtag_events ) {
]
);

$this->register_js_for_fast_refresh_dev();

Check warning on line 205 in src/Google/GlobalSiteTag.php

View check run for this annotation

Codecov / codecov/patch

src/Google/GlobalSiteTag.php#L205

Added line #L205 was not covered by tests
$this->assets_handler->enqueue( $gtag_events );
}
);
Expand Down Expand Up @@ -485,4 +486,39 @@ private static function is_first_time_customer( $customer_email ): bool {
$orders = $query->get_orders();
return count( $orders ) === 1 ? true : false;
}

/**
* This method ONLY works during development in the Fast Refresh mode.
*
* The runtime.js and react-refresh-runtime.js files are created when the front-end development is
* running `npm run start:hot`, and they need to be loaded to make the gtag-events scrips work.
*/
private function register_js_for_fast_refresh_dev() {

Check warning on line 496 in src/Google/GlobalSiteTag.php

View check run for this annotation

Codecov / codecov/patch

src/Google/GlobalSiteTag.php#L496

Added line #L496 was not covered by tests
// This file exists only when running `npm run start:hot`
$runtime_path = "{$this->get_root_dir()}/js/build/runtime.js";

Check warning on line 498 in src/Google/GlobalSiteTag.php

View check run for this annotation

Codecov / codecov/patch

src/Google/GlobalSiteTag.php#L498

Added line #L498 was not covered by tests

if ( ! file_exists( $runtime_path ) ) {
return;

Check warning on line 501 in src/Google/GlobalSiteTag.php

View check run for this annotation

Codecov / codecov/patch

src/Google/GlobalSiteTag.php#L500-L501

Added lines #L500 - L501 were not covered by tests
}

$plugin_url = $this->get_plugin_url();

Check warning on line 504 in src/Google/GlobalSiteTag.php

View check run for this annotation

Codecov / codecov/patch

src/Google/GlobalSiteTag.php#L504

Added line #L504 was not covered by tests

wp_enqueue_script(
'gla-webpack-runtime',
"{$plugin_url}/js/build/runtime.js",
[],
(string) filemtime( $runtime_path ),
false
);

Check warning on line 512 in src/Google/GlobalSiteTag.php

View check run for this annotation

Codecov / codecov/patch

src/Google/GlobalSiteTag.php#L506-L512

Added lines #L506 - L512 were not covered by tests

// This script is one of the gtag-events dependencies, and its handle is wp-react-refresh-runtime.
// Ref: js/build/gtag-events.asset.php
wp_register_script(
'wp-react-refresh-runtime',
"{$plugin_url}/js/build-dev/react-refresh-runtime.js",
[ 'gla-webpack-runtime' ],
$this->get_version(),
false
);

Check warning on line 522 in src/Google/GlobalSiteTag.php

View check run for this annotation

Codecov / codecov/patch

src/Google/GlobalSiteTag.php#L516-L522

Added lines #L516 - L522 were not covered by tests
}
}
Loading

0 comments on commit 0c095a6

Please sign in to comment.