From db51f546949c3d67152ee85dc78890f6be8db933 Mon Sep 17 00:00:00 2001 From: Vladimir Reznichenko Date: Mon, 5 Aug 2024 17:01:04 +0200 Subject: [PATCH 001/276] Monorepo: added instructions on how to update report flaky tests action. (#50366) --- .github/actions/report-flaky-tests/UPDATE.md | 78 ++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 .github/actions/report-flaky-tests/UPDATE.md diff --git a/.github/actions/report-flaky-tests/UPDATE.md b/.github/actions/report-flaky-tests/UPDATE.md new file mode 100644 index 00000000000..49aeee9fb55 --- /dev/null +++ b/.github/actions/report-flaky-tests/UPDATE.md @@ -0,0 +1,78 @@ +# How to update + +## Source code + +This action is extracted and bundled version of the following: + +Repository: https://github.com/WordPress/gutenberg/tree/trunk/packages/report-flaky-tests +Commit ID: ce803384250671d01fde6c7d6d2aa83075fcc726 + +## How to build + +After checking out the repository, navigate to packages/report-flaky-tests and do some modifications: + +### package.json file + +Add the following dependency: `"ts-loader": "^9.5.1",`. + +### tsconfig.json file + +The file context should be updated to following state: + +``` +{ + "$schema": "https://json.schemastore.org/tsconfig.json", + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "dist", + "target": "es6", + "module": "commonjs", + "esModuleInterop": true, + "moduleResolution": "node", + "declarationDir": "build-types", + "rootDir": "src", + "emitDeclarationOnly": false, + }, + "include": [ "src/**/*" ], + "exclude": [ "src/__tests__/**/*", "src/__fixtures__/**/*" ] +} +``` + +### webpack.config.js file + +The file should be added with the following content: + +``` +const path = require( 'path' ); +const buildMode = process.env.NODE_ENV || 'production'; + +module.exports = { + entry: './src/index.ts', + target: 'node', + mode: buildMode, + module: { + rules: [ + { + test: /\.tsx?$/, + use: 'ts-loader', + exclude: /node_modules/, + }, + ], + }, + resolve: { + extensions: [ '.tsx', '.ts', '.js' ], + }, + plugins: [], + output: { + filename: 'index.js', + path: path.resolve( __dirname, 'dist' ), + clean: true, + }, +}; +``` + +### Build + +Run `webpack --config webpack.config.js` (don't forget about `npm install` before that). + +Use the generated files under `packages/report-flaky-tests/dist` to update the bundled distribution in this repository. From ef224a1a7050e18509afbacae6031d0ee5b99133 Mon Sep 17 00:00:00 2001 From: Seghir Nadir Date: Mon, 5 Aug 2024 17:08:46 +0200 Subject: [PATCH 002/276] Fix new account notice not showing in Checkout block. (#50138) * Correctly cast the account creation nag option * Add changefile(s) from automation for the following project(s): woocommerce --------- Co-authored-by: github-actions --- plugins/woocommerce/changelog/50138-fix-show-new-account-nag | 4 ++++ .../src/Blocks/BlockTypes/OrderConfirmation/Status.php | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 plugins/woocommerce/changelog/50138-fix-show-new-account-nag diff --git a/plugins/woocommerce/changelog/50138-fix-show-new-account-nag b/plugins/woocommerce/changelog/50138-fix-show-new-account-nag new file mode 100644 index 00000000000..0fd429c4fc1 --- /dev/null +++ b/plugins/woocommerce/changelog/50138-fix-show-new-account-nag @@ -0,0 +1,4 @@ +Significance: patch +Type: tweak +Comment: Fixes a regression in a new PR that's not yet shipped. + diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/OrderConfirmation/Status.php b/plugins/woocommerce/src/Blocks/BlockTypes/OrderConfirmation/Status.php index 6cdbbba4883..537ce904163 100644 --- a/plugins/woocommerce/src/Blocks/BlockTypes/OrderConfirmation/Status.php +++ b/plugins/woocommerce/src/Blocks/BlockTypes/OrderConfirmation/Status.php @@ -155,9 +155,9 @@ class Status extends AbstractOrderConfirmationBlock { protected function render_account_notice( $order = null ) { if ( $order && $order->get_customer_id() && 'store-api' === $order->get_created_via() ) { $nag = get_user_option( 'default_password_nag', $order->get_customer_id() ); - $generate = get_option( 'woocommerce_registration_generate_password', false ); + $generate = filter_var( get_option( 'woocommerce_registration_generate_password', false ), FILTER_VALIDATE_BOOLEAN ); - if ( $nag && ! $generate ) { + if ( $nag && $generate ) { return wc_print_notice( sprintf( // translators: %s: site name. From fd2dbf55170ee5c5658832a55fea74b352092dc7 Mon Sep 17 00:00:00 2001 From: Luigi Teschio Date: Mon, 5 Aug 2024 17:13:39 +0200 Subject: [PATCH 003/276] CYS: improve CTA (#50278) * CYS: improve CTA * Add changefile(s) from automation for the following project(s): woocommerce --------- Co-authored-by: github-actions --- .../customize-store/assembler-hub/sidebar/save-hub.tsx | 6 +++++- plugins/woocommerce/changelog/50278-fix-improve_label | 4 ++++ .../tests/customize-store/assembler/assembler.page.js | 2 +- .../tests/customize-store/assembler/color-picker.spec.js | 4 ++-- .../tests/customize-store/assembler/font-picker.spec.js | 2 +- .../e2e-pw/tests/customize-store/assembler/footer.spec.js | 2 +- .../e2e-pw/tests/customize-store/assembler/header.spec.js | 2 +- .../e2e-pw/tests/customize-store/assembler/homepage.spec.js | 2 +- .../assembler/logo-picker/logo-picker.page.js | 4 ++-- .../customize-store/loading-screen/loading-screen.spec.js | 4 +++- .../tests/e2e-pw/tests/customize-store/transitional.spec.js | 6 ++++-- 11 files changed, 25 insertions(+), 13 deletions(-) create mode 100644 plugins/woocommerce/changelog/50278-fix-improve_label diff --git a/plugins/woocommerce-admin/client/customize-store/assembler-hub/sidebar/save-hub.tsx b/plugins/woocommerce-admin/client/customize-store/assembler-hub/sidebar/save-hub.tsx index 4a840fafe94..1b5ef141c39 100644 --- a/plugins/woocommerce-admin/client/customize-store/assembler-hub/sidebar/save-hub.tsx +++ b/plugins/woocommerce-admin/client/customize-store/assembler-hub/sidebar/save-hub.tsx @@ -190,7 +190,11 @@ export const SaveHub = () => { // @ts-ignore No types for this exist yet. __next40pxDefaultSize > - { isResolving ? : __( 'Save', 'woocommerce' ) } + { isResolving ? ( + + ) : ( + __( 'Finish customizing', 'woocommerce' ) + ) } ); diff --git a/plugins/woocommerce/changelog/50278-fix-improve_label b/plugins/woocommerce/changelog/50278-fix-improve_label new file mode 100644 index 00000000000..0bc697665eb --- /dev/null +++ b/plugins/woocommerce/changelog/50278-fix-improve_label @@ -0,0 +1,4 @@ +Significance: patch +Type: enhancement + +CYS: improve CTA \ No newline at end of file diff --git a/plugins/woocommerce/tests/e2e-pw/tests/customize-store/assembler/assembler.page.js b/plugins/woocommerce/tests/e2e-pw/tests/customize-store/assembler/assembler.page.js index 64ee1de8f0d..1432f70568a 100644 --- a/plugins/woocommerce/tests/e2e-pw/tests/customize-store/assembler/assembler.page.js +++ b/plugins/woocommerce/tests/e2e-pw/tests/customize-store/assembler/assembler.page.js @@ -17,7 +17,7 @@ export class AssemblerPage { ); await frame - .getByRole( 'button', { name: 'Save' } ) + .getByRole( 'button', { name: 'Finish customizing' } ) .waitFor( { timeout: 25000 } ); } diff --git a/plugins/woocommerce/tests/e2e-pw/tests/customize-store/assembler/color-picker.spec.js b/plugins/woocommerce/tests/e2e-pw/tests/customize-store/assembler/color-picker.spec.js index 6a5a91e646b..d90a0f457ec 100644 --- a/plugins/woocommerce/tests/e2e-pw/tests/customize-store/assembler/color-picker.spec.js +++ b/plugins/woocommerce/tests/e2e-pw/tests/customize-store/assembler/color-picker.spec.js @@ -302,7 +302,7 @@ test.describe( 'Assembler -> Color Pickers', { tag: '@gutenberg' }, () => { await assembler.locator( '[aria-label="Back"]' ).click(); - const saveButton = assembler.getByText( 'Save' ); + const saveButton = assembler.getByText( 'Finish customizing' ); const waitResponse = page.waitForResponse( ( response ) => @@ -427,7 +427,7 @@ test.describe( 'Assembler -> Color Pickers', { tag: '@gutenberg' }, () => { await assembler.locator( '[aria-label="Back"]' ).click(); - const saveButton = assembler.getByText( 'Save' ); + const saveButton = assembler.getByText( 'Finish customizing' ); const waitResponseGlobalStyles = page.waitForResponse( ( response ) => diff --git a/plugins/woocommerce/tests/e2e-pw/tests/customize-store/assembler/font-picker.spec.js b/plugins/woocommerce/tests/e2e-pw/tests/customize-store/assembler/font-picker.spec.js index 57c25e6dca1..bea205eaac0 100644 --- a/plugins/woocommerce/tests/e2e-pw/tests/customize-store/assembler/font-picker.spec.js +++ b/plugins/woocommerce/tests/e2e-pw/tests/customize-store/assembler/font-picker.spec.js @@ -202,7 +202,7 @@ test.describe( 'Assembler -> Font Picker', { tag: '@gutenberg' }, () => { await assembler.locator( '[aria-label="Back"]' ).click(); - const saveButton = assembler.getByText( 'Save' ); + const saveButton = assembler.getByText( 'Finish customizing' ); const waitResponse = page.waitForResponse( ( response ) => diff --git a/plugins/woocommerce/tests/e2e-pw/tests/customize-store/assembler/footer.spec.js b/plugins/woocommerce/tests/e2e-pw/tests/customize-store/assembler/footer.spec.js index 926e13277c2..5a4f0fab315 100644 --- a/plugins/woocommerce/tests/e2e-pw/tests/customize-store/assembler/footer.spec.js +++ b/plugins/woocommerce/tests/e2e-pw/tests/customize-store/assembler/footer.spec.js @@ -108,7 +108,7 @@ test.describe( 'Assembler -> Footers', { tag: '@gutenberg' }, () => { await assembler.locator( '[aria-label="Back"]' ).click(); - const saveButton = assembler.getByText( 'Save' ); + const saveButton = assembler.getByText( 'Finish customizing' ); const waitResponse = page.waitForResponse( ( response ) => diff --git a/plugins/woocommerce/tests/e2e-pw/tests/customize-store/assembler/header.spec.js b/plugins/woocommerce/tests/e2e-pw/tests/customize-store/assembler/header.spec.js index e70140f6536..507724e0de1 100644 --- a/plugins/woocommerce/tests/e2e-pw/tests/customize-store/assembler/header.spec.js +++ b/plugins/woocommerce/tests/e2e-pw/tests/customize-store/assembler/header.spec.js @@ -108,7 +108,7 @@ test.describe( 'Assembler -> headers', { tag: '@gutenberg' }, () => { await assembler.locator( '[aria-label="Back"]' ).click(); - const saveButton = assembler.getByText( 'Save' ); + const saveButton = assembler.getByText( 'Finish customizing' ); const waitResponse = page.waitForResponse( ( response ) => diff --git a/plugins/woocommerce/tests/e2e-pw/tests/customize-store/assembler/homepage.spec.js b/plugins/woocommerce/tests/e2e-pw/tests/customize-store/assembler/homepage.spec.js index 66239125734..e6f9d9e2141 100644 --- a/plugins/woocommerce/tests/e2e-pw/tests/customize-store/assembler/homepage.spec.js +++ b/plugins/woocommerce/tests/e2e-pw/tests/customize-store/assembler/homepage.spec.js @@ -157,7 +157,7 @@ test.describe( 'Assembler -> Homepage', { tag: '@gutenberg' }, () => { await assembler.locator( '[aria-label="Back"]' ).click(); - const saveButton = assembler.getByText( 'Save' ); + const saveButton = assembler.getByText( 'Finish customizing' ); const waitResponse = page.waitForResponse( ( response ) => diff --git a/plugins/woocommerce/tests/e2e-pw/tests/customize-store/assembler/logo-picker/logo-picker.page.js b/plugins/woocommerce/tests/e2e-pw/tests/customize-store/assembler/logo-picker/logo-picker.page.js index 0fb8a38542f..c9423ff9659 100644 --- a/plugins/woocommerce/tests/e2e-pw/tests/customize-store/assembler/logo-picker/logo-picker.page.js +++ b/plugins/woocommerce/tests/e2e-pw/tests/customize-store/assembler/logo-picker/logo-picker.page.js @@ -80,11 +80,11 @@ export class LogoPickerPage { ); await assemblerLocator.locator( '[aria-label="Back"]' ).click(); await assemblerLocator - .getByRole( 'button', { name: 'Save', exact: true } ) + .getByRole( 'button', { name: 'Finish customizing', exact: true } ) .waitFor(); await Promise.all( [ waitForLogoResponse, - assemblerLocator.getByText( 'Save' ).click(), + assemblerLocator.getByText( 'Finish customizing' ).click(), ] ); await assemblerLocator.getByText( 'Your store looks great!' ).waitFor(); } diff --git a/plugins/woocommerce/tests/e2e-pw/tests/customize-store/loading-screen/loading-screen.spec.js b/plugins/woocommerce/tests/e2e-pw/tests/customize-store/loading-screen/loading-screen.spec.js index 52ce5b1b669..62290c1f80e 100644 --- a/plugins/woocommerce/tests/e2e-pw/tests/customize-store/loading-screen/loading-screen.spec.js +++ b/plugins/woocommerce/tests/e2e-pw/tests/customize-store/loading-screen/loading-screen.spec.js @@ -123,7 +123,9 @@ test.describe( 'Assembler - Loading Page', { tag: '@gutenberg' }, () => { await pageObject.waitForLoadingScreenFinish(); const assembler = await pageObject.getAssembler(); - await assembler.getByRole( 'button', { name: 'Save' } ).click(); + await assembler + .getByRole( 'button', { name: 'Finish customizing' } ) + .click(); await assembler.getByText( 'Your store looks great!' ).waitFor(); // Abort any additional unnecessary requests await page.evaluate( () => window.stop() ); diff --git a/plugins/woocommerce/tests/e2e-pw/tests/customize-store/transitional.spec.js b/plugins/woocommerce/tests/e2e-pw/tests/customize-store/transitional.spec.js index fd11179c79b..b156bec00aa 100644 --- a/plugins/woocommerce/tests/e2e-pw/tests/customize-store/transitional.spec.js +++ b/plugins/woocommerce/tests/e2e-pw/tests/customize-store/transitional.spec.js @@ -72,7 +72,7 @@ test.describe( await expect( page.url() ).toBe( `${ baseURL }${ INTRO_URL }` ); } ); - test( 'Clicking on "Save" in the assembler should go to the transitional page', async ( { + test( 'Clicking on "Finish customizing" in the assembler should go to the transitional page', async ( { pageObject, baseURL, } ) => { @@ -80,7 +80,9 @@ test.describe( await pageObject.waitForLoadingScreenFinish(); const assembler = await pageObject.getAssembler(); - await assembler.getByRole( 'button', { name: 'Save' } ).click(); + await assembler + .getByRole( 'button', { name: 'Finish customizing' } ) + .click(); await expect( assembler.locator( 'text=Your store looks great!' ) From f7f280fd1bcf85dca31c70c5c98a0c5975b81b78 Mon Sep 17 00:00:00 2001 From: piinthecloud Date: Mon, 5 Aug 2024 17:51:32 +0200 Subject: [PATCH 004/276] create product collection category and move to main docs folder (#50368) * create product collection category and move to main docs folder * add readme * update title * update title * add changelog and remove emojis * Update docs/product-collection-block/register-product-collection.md Co-authored-by: Karol Manijak <20098064+kmanijak@users.noreply.github.com> --------- Co-authored-by: Shani Co-authored-by: Karol Manijak <20098064+kmanijak@users.noreply.github.com> --- docs/docs-manifest.json | 19 ++++++++++++++++++- docs/product-collection-block/README.md | 5 +++++ .../register-product-collection.md | 14 ++++++++++---- .../changelog/move-product-collection | 4 ++++ 4 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 docs/product-collection-block/README.md rename {plugins/woocommerce-blocks/docs/third-party-developers/extensibility => docs/product-collection-block}/register-product-collection.md (94%) create mode 100644 plugins/woocommerce/changelog/move-product-collection diff --git a/docs/docs-manifest.json b/docs/docs-manifest.json index cf69b715e95..a994f533f1d 100644 --- a/docs/docs-manifest.json +++ b/docs/docs-manifest.json @@ -997,6 +997,23 @@ ], "categories": [] }, + { + "content": "", + "category_slug": "product-collection", + "category_title": "Product Collection Block", + "posts": [ + { + "post_title": "Registering custom collections in product collection block", + "menu_title": "Registering custom collections", + "tags": "how-to", + "edit_url": "https://github.com/woocommerce/woocommerce/edit/trunk/docs/product-collection-block/register-product-collection.md", + "hash": "88445929a9f76512e1e8ff60be7beff7e912f31fbad552abf18862ed85f00585", + "url": "https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/docs/product-collection-block/register-product-collection.md", + "id": "3bf26fc7c56ae6e6a56e1171f750f5204fcfcece" + } + ], + "categories": [] + }, { "content": "\nDiscover how to customize the WooCommerce product editor, from extending product data to adding unique functionalities.\n\nThis handbook is a guide for extension developers looking to add support for the new product editor in their extensions. The product editor uses [Gutenberg's Block Editor](https://github.com/WordPress/gutenberg/tree/trunk/packages/block-editor), which is going to help WooCommerce evolve alongside the WordPress ecosystem.", "category_slug": "product-editor", @@ -1680,5 +1697,5 @@ "categories": [] } ], - "hash": "aba0ae4b152f1007f64966aa21601ba73786ce4b1be4219f18ecbf295ee10221" + "hash": "c24136612fe16fc7dee435a2ad2198ce242ab63dbba483fd0a18efd88dc3a289" } \ No newline at end of file diff --git a/docs/product-collection-block/README.md b/docs/product-collection-block/README.md new file mode 100644 index 00000000000..d49163534c8 --- /dev/null +++ b/docs/product-collection-block/README.md @@ -0,0 +1,5 @@ +--- +category_title: Product Collection Block +category_slug: product-collection +post_title: Product collection block +--- diff --git a/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/register-product-collection.md b/docs/product-collection-block/register-product-collection.md similarity index 94% rename from plugins/woocommerce-blocks/docs/third-party-developers/extensibility/register-product-collection.md rename to docs/product-collection-block/register-product-collection.md index 56b346b4c71..9f96f791262 100644 --- a/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/register-product-collection.md +++ b/docs/product-collection-block/register-product-collection.md @@ -1,6 +1,12 @@ +--- +post_title: Registering custom collections in product collection block +menu_title: Registering custom collections +tags: how-to +--- + # Register Product Collection -The `__experimentalRegisterProductCollection` function is part of the `@woocommerce/blocks-registry` package. This function allows 3PDs to register a new collection. This function accepts most of the arguments that are accepted by [Block Variation](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-variations/#defining-a-block-variation). +The `__experimentalRegisterProductCollection` function is part of the `@woocommerce/blocks-registry` package. This function allows third party developers to register a new collection. This function accepts most of the arguments that are accepted by [Block Variation](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-variations/#defining-a-block-variation). > [!WARNING] > It's experimental and may change in the future. Please use it with caution. @@ -34,8 +40,8 @@ A Collection is defined by an object that can contain the following fields: - `title` (type `string`): The title of the collection, which will be displayed in various places including the block inserter and collection chooser. - `description` (optional, type `string`): A human-readable description of the collection. - `innerBlocks` (optional, type `Array[]`): An array of inner blocks that will be added to the collection. If not provided, the default inner blocks will be used. -- `isDefault`: ⚠️ It's set to `false` for all collections. 3PDs doesn't need to pass this argument. -- `isActive`: ⚠️ It will be managed by us. 3PDs doesn't need to pass this argument. +- `isDefault`: It's set to `false` for all collections. Third party developers don't need to pass this argument. +- `isActive`: It will be managed by us. Third party developers don't need to pass this argument. - `usesReference` (optional, type `Array[]`): An array of strings specifying the required reference for the collection. Acceptable values are `product`, `archive`, `cart`, and `order`. When the required reference isn't available on Editor side but will be available in Frontend, we will show a preview label. ### Attributes @@ -91,7 +97,7 @@ The `preview` attribute is optional, and it is used to set the preview state of - `attributes` (type `object`): The current attributes of the collection. - `location` (type `object`): The location of the collection. Accepted values are `product`, `archive`, `cart`, `order`, `site`. -For more info, you may check PR #46369, in which the Preview feature was added +For more info, you may check [PR #46369](https://github.com/woocommerce/woocommerce/pull/46369), in which the Preview feature was added ## Examples diff --git a/plugins/woocommerce/changelog/move-product-collection b/plugins/woocommerce/changelog/move-product-collection new file mode 100644 index 00000000000..c7dcdc00e9c --- /dev/null +++ b/plugins/woocommerce/changelog/move-product-collection @@ -0,0 +1,4 @@ +Significance: minor +Type: dev + +moving product collection docs to main docs folder From ec6711346bd7856796441c109c7bbe014f90f26c Mon Sep 17 00:00:00 2001 From: DAnn2012 Date: Tue, 6 Aug 2024 02:36:17 +0200 Subject: [PATCH 005/276] Fix typo (sidebar-navigation-screen-typography.tsx) (#50332) * Update sidebar-navigation-screen-typography.tsx * Add changefile(s) from automation for the following project(s): woocommerce --------- Co-authored-by: github-actions --- .../sidebar-navigation-screen-typography.tsx | 2 +- plugins/woocommerce/changelog/50332-patch-19 | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 plugins/woocommerce/changelog/50332-patch-19 diff --git a/plugins/woocommerce-admin/client/customize-store/assembler-hub/sidebar/sidebar-navigation-screen-typography/sidebar-navigation-screen-typography.tsx b/plugins/woocommerce-admin/client/customize-store/assembler-hub/sidebar/sidebar-navigation-screen-typography/sidebar-navigation-screen-typography.tsx index 88f66bc0caa..a9202a4da37 100644 --- a/plugins/woocommerce-admin/client/customize-store/assembler-hub/sidebar/sidebar-navigation-screen-typography/sidebar-navigation-screen-typography.tsx +++ b/plugins/woocommerce-admin/client/customize-store/assembler-hub/sidebar/sidebar-navigation-screen-typography/sidebar-navigation-screen-typography.tsx @@ -183,7 +183,7 @@ export const SidebarNavigationScreenTypography = ( { className="core-profiler__checkbox" label={ interpolateComponents( { mixedString: __( - 'More fonts are available! Opt in to connect your store and access the full font library, plus get more relevant content and a tailored store setup experience. Opting in will enable {{link}}usage tracking{{/link}}, which you can opt out of at any time via WooCommerece settings.', + 'More fonts are available! Opt in to connect your store and access the full font library, plus get more relevant content and a tailored store setup experience. Opting in will enable {{link}}usage tracking{{/link}}, which you can opt out of at any time via WooCommerce settings.', 'woocommerce' ), components: { diff --git a/plugins/woocommerce/changelog/50332-patch-19 b/plugins/woocommerce/changelog/50332-patch-19 new file mode 100644 index 00000000000..043fa2f15ca --- /dev/null +++ b/plugins/woocommerce/changelog/50332-patch-19 @@ -0,0 +1,4 @@ +Significance: patch +Type: tweak +Comment: Fix typo (sidebar-navigation-screen-typography.tsx) + From 3d16f16ae199e6ec858d6756fab0751b2ce1de9b Mon Sep 17 00:00:00 2001 From: Adrian Duffell <9312929+adrianduffell@users.noreply.github.com> Date: Tue, 6 Aug 2024 10:29:01 +0800 Subject: [PATCH 006/276] Use admin password reset link on admin login screen (#50200) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Use admin password reset link on admin login screen * Add changelog * Take a different approach that’s compatible with JN * Update code comment * use existing variable * Update tests * Lintfix * Change to alternative aproach for detecting admin login form * Whitespace * Update test * Lint fix --- .../changelog/update-admin-reset-password | 4 +++ .../includes/wc-account-functions.php | 5 +++ .../legacy/unit-tests/account/functions.php | 31 +++++++++++++++++-- 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 plugins/woocommerce/changelog/update-admin-reset-password diff --git a/plugins/woocommerce/changelog/update-admin-reset-password b/plugins/woocommerce/changelog/update-admin-reset-password new file mode 100644 index 00000000000..a0d9de4f7e4 --- /dev/null +++ b/plugins/woocommerce/changelog/update-admin-reset-password @@ -0,0 +1,4 @@ +Significance: minor +Type: update + +Use admin password reset on admin login screen diff --git a/plugins/woocommerce/includes/wc-account-functions.php b/plugins/woocommerce/includes/wc-account-functions.php index 3f34a3a5801..0abfaba1b4d 100644 --- a/plugins/woocommerce/includes/wc-account-functions.php +++ b/plugins/woocommerce/includes/wc-account-functions.php @@ -22,6 +22,11 @@ function wc_lostpassword_url( $default_url = '' ) { return $default_url; } + // Don't change the admin form. + if ( did_action( 'login_form_login' ) ) { + return $default_url; + } + // Don't redirect to the woocommerce endpoint on global network admin lost passwords. if ( is_multisite() && isset( $_GET['redirect_to'] ) && false !== strpos( wp_unslash( $_GET['redirect_to'] ), network_admin_url() ) ) { // WPCS: input var ok, sanitization ok, CSRF ok. return $default_url; diff --git a/plugins/woocommerce/tests/legacy/unit-tests/account/functions.php b/plugins/woocommerce/tests/legacy/unit-tests/account/functions.php index 1cb8dae1a22..db1a701439f 100644 --- a/plugins/woocommerce/tests/legacy/unit-tests/account/functions.php +++ b/plugins/woocommerce/tests/legacy/unit-tests/account/functions.php @@ -11,12 +11,39 @@ class WC_Tests_Account_Functions extends WC_Unit_Test_Case { /** - * Test wc_lostpassword_url(). + * Test wc_lostpassword_url() from admin screen. * * @since 3.3.0 */ public function test_wc_lostpassword_url() { - $this->assertEquals( 'http://' . WP_TESTS_DOMAIN . '?lost-password', wc_lostpassword_url() ); + // phpcs:disable WooCommerce.Commenting.CommentHooks.MissingHookComment + do_action( 'login_form_login' ); // Simulate admin login screen. + + // Admin URL is expected. + $expected_url = admin_url( '/wp-login.php?action=lostpassword' ); + + $this->assertEquals( $expected_url, wc_lostpassword_url( $expected_url ) ); + } + + /** + * Test wc_lostpassword_url() from my account page. + */ + public function test_wc_lostpassword_url_from_account_page() { + // Create the account page, since other tests may delete it. + $page = wc_create_page( + 'myaccount', + 'woocommerce_myaccount_page_id', + 'My Account', + '', + '', + 'publish' + ); + $this->go_to( wc_get_page_permalink( 'myaccount' ) ); + + // Front-end URL is expected. + $expected_url = wc_get_endpoint_url( 'lost-password', '', get_the_permalink( 'myaccount' ) ); + + $this->assertEquals( $expected_url, wc_lostpassword_url() ); } /** From 328d9442882b6952c1c41671b066d9d27667cc9d Mon Sep 17 00:00:00 2001 From: Vladimir Reznichenko Date: Tue, 6 Aug 2024 09:30:10 +0200 Subject: [PATCH 007/276] Monorepo: update packageManager version in package.json file. (#50384) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bb3c76374b5..2920ad9d71d 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "title": "WooCommerce Monorepo", "description": "Monorepo for the WooCommerce ecosystem", "homepage": "https://woocommerce.com/", - "packageManager": "pnpm@^9.1.0", + "packageManager": "pnpm@9.6.0", "engines": { "node": "^20.11.1", "pnpm": "^9.1.0" From 52119dfcc9cdd98ec21fd6189b2d51f4d4957f62 Mon Sep 17 00:00:00 2001 From: Bart Kalisz Date: Tue, 6 Aug 2024 11:23:04 +0200 Subject: [PATCH 008/276] Fix CI Metrics job (#50214) --- .github/workflows/ci.yml | 9 ----- .github/workflows/scripts/run-metrics.sh | 21 ++++++++---- .../woocommerce/changelog/fix-ci-metrics-job | 4 +++ plugins/woocommerce/package.json | 8 +++-- .../tests/e2e-pw/utils/simple-products.js | 34 ++++++++++++------- .../tests/metrics/playwright.config.js | 9 ++--- .../tests/metrics/specs/editor.spec.js | 1 - .../metrics/specs/product-editor.spec.js | 8 ++--- tools/compare-perf/config.js | 18 +++++----- 9 files changed, 65 insertions(+), 47 deletions(-) create mode 100644 plugins/woocommerce/changelog/fix-ci-metrics-job diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f9d43842306..c4ca04202cc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -194,15 +194,6 @@ jobs: name: flaky-tests-${{ strategy.job-index }} path: ${{ env.ARTIFACTS_PATH }}/flaky-tests if-no-files-found: ignore - - - name: 'Archive metrics results' - if: ${{ success() && startsWith(matrix.name, 'Metrics') }} # this seems too fragile, we should update the reporting path and use the generic upload step above - uses: actions/upload-artifact@v4 - env: - WP_ARTIFACTS_PATH: ${{ github.workspace }}/artifacts - with: - name: metrics-results - path: ${{ env.WP_ARTIFACTS_PATH }}/*.performance-results*.json evaluate-project-jobs: # In order to add a required status check we need a consistent job that we can grab onto. diff --git a/.github/workflows/scripts/run-metrics.sh b/.github/workflows/scripts/run-metrics.sh index 4bbe85ee470..7086646a4ae 100755 --- a/.github/workflows/scripts/run-metrics.sh +++ b/.github/workflows/scripts/run-metrics.sh @@ -7,25 +7,34 @@ if [[ -z "$GITHUB_EVENT_NAME" ]]; then exit 1 fi +echo "Installing dependencies" +pnpm install --filter="compare-perf" + if [[ "$GITHUB_EVENT_NAME" == "pull_request" ]]; then echo "Comparing performance with trunk" pnpm --filter="compare-perf" run compare perf $GITHUB_SHA trunk --tests-branch $GITHUB_SHA elif [[ "$GITHUB_EVENT_NAME" == "push" ]]; then echo "Comparing performance with base branch" - # The base hash used here need to be a commit that is compatible with the current WP version - # The current one is 19f3d0884617d7ecdcf37664f648a51e2987cada - # it needs to be updated every time it becomes unsupported by the current wp-env (WP version). - # It is used as a base comparison point to avoid fluctuation in the performance metrics. WP_VERSION=$(awk -F ': ' '/^Tested up to/{print $2}' readme.txt) + # Updating the WP version used for performance jobs means there’s a high + # chance that the reference commit used for performance test stability + # becomes incompatible with the WP version. So, every time the "Tested up + # to" flag is updated in the readme.txt, we also have to update the + # reference commit below (BASE_SHA). The new reference needs to meet the + # following requirements: + # - Be compatible with the new WP version used in the “Tested up to” flag. + # - Be tracked on https://www.codevitals.run/project/woo for all existing + # metrics. + BASE_SHA=3d7d7f02017383937f1a4158d433d0e5d44b3dc9 echo "WP_VERSION: $WP_VERSION" IFS=. read -ra WP_VERSION_ARRAY <<< "$WP_VERSION" WP_MAJOR="${WP_VERSION_ARRAY[0]}.${WP_VERSION_ARRAY[1]}" - pnpm --filter="compare-perf" run compare perf $GITHUB_SHA 19f3d0884617d7ecdcf37664f648a51e2987cada --tests-branch $GITHUB_SHA --wp-version "$WP_MAJOR" + pnpm --filter="compare-perf" run compare perf $GITHUB_SHA $BASE_SHA --tests-branch $GITHUB_SHA --wp-version "$WP_MAJOR" echo "Publish results to CodeVitals" COMMITTED_AT=$(git show -s $GITHUB_SHA --format="%cI") - pnpm --filter="compare-perf" run log $CODEVITALS_PROJECT_TOKEN trunk $GITHUB_SHA 19f3d0884617d7ecdcf37664f648a51e2987cada $COMMITTED_AT + pnpm --filter="compare-perf" run log $CODEVITALS_PROJECT_TOKEN trunk $GITHUB_SHA $BASE_SHA $COMMITTED_AT else echo "Unsupported event: $GITHUB_EVENT_NAME" fi diff --git a/plugins/woocommerce/changelog/fix-ci-metrics-job b/plugins/woocommerce/changelog/fix-ci-metrics-job new file mode 100644 index 00000000000..d743f02743a --- /dev/null +++ b/plugins/woocommerce/changelog/fix-ci-metrics-job @@ -0,0 +1,4 @@ +Significance: patch +Type: dev + +Fix Metrics CI job diff --git a/plugins/woocommerce/package.json b/plugins/woocommerce/package.json index 0506a8a3dbe..6c41b1cead1 100644 --- a/plugins/woocommerce/package.json +++ b/plugins/woocommerce/package.json @@ -529,8 +529,12 @@ ".wp-env.json" ], "events": [ - "disabled" - ] + "push" + ], + "report": { + "resultsBlobName": "core-metrics-report", + "resultsPath": "../../tools/compare-perf/artifacts/" + } }, { "name": "Blocks e2e tests", diff --git a/plugins/woocommerce/tests/e2e-pw/utils/simple-products.js b/plugins/woocommerce/tests/e2e-pw/utils/simple-products.js index 1e9af15844b..a37c31ce486 100644 --- a/plugins/woocommerce/tests/e2e-pw/utils/simple-products.js +++ b/plugins/woocommerce/tests/e2e-pw/utils/simple-products.js @@ -22,22 +22,32 @@ async function isBlockProductEditorEnabled( page ) { /** * This function is typically used for enabling/disabling the block product editor in settings page. * - * @param {string} action The action that will be performed. - * @param {import('@playwright/test').Page} page + * @param {string} action The action that will be performed. + * @param {import('@playwright/test').Page} page */ async function toggleBlockProductEditor( action = 'enable', page ) { await page.goto( SETTINGS_URL ); - if ( action === 'disable' ) { - await page - .locator( '#woocommerce_feature_product_block_editor_enabled' ) - .uncheck(); - } else { - await page - .locator( '#woocommerce_feature_product_block_editor_enabled' ) - .check(); + + const enableProductEditor = page.locator( + '#woocommerce_feature_product_block_editor_enabled' + ); + const isEnabled = await enableProductEditor.isChecked(); + + if ( + ( action === 'enable' && isEnabled ) || + ( action === 'disable' && ! isEnabled ) + ) { + // No need to toggle the setting. + return; } + + if ( action === 'enable' ) { + await enableProductEditor.check(); + } else if ( action === 'disable' ) { + await enableProductEditor.uncheck(); + } + await page - .locator( '.submit' ) .getByRole( 'button', { name: 'Save changes', } ) @@ -81,7 +91,7 @@ async function expectBlockProductEditor( page ) { /** * Click on a block editor tab. * - * @param {string} tabName + * @param {string} tabName * @param {import('@playwright/test').Page} page */ async function clickOnTab( tabName, page ) { diff --git a/plugins/woocommerce/tests/metrics/playwright.config.js b/plugins/woocommerce/tests/metrics/playwright.config.js index 20043d2088c..053ea9231d2 100644 --- a/plugins/woocommerce/tests/metrics/playwright.config.js +++ b/plugins/woocommerce/tests/metrics/playwright.config.js @@ -1,3 +1,6 @@ +/** + * External dependencies + */ import path from 'path'; import { fileURLToPath } from 'url'; import { defineConfig, devices } from '@playwright/test'; @@ -11,9 +14,7 @@ process.env.STORAGE_STATE_PATH ??= path.join( process.env.WP_BASE_URL ??= 'http://localhost:8086'; const config = defineConfig( { - reporter: process.env.CI - ? './config/performance-reporter.ts' - : [ [ 'list' ], [ './config/performance-reporter.ts' ] ], + reporter: [ [ 'list' ], [ './config/performance-reporter.ts' ] ], forbidOnly: !! process.env.CI, fullyParallel: false, workers: 1, @@ -24,7 +25,7 @@ const config = defineConfig( { testDir: './specs', outputDir: path.join( process.env.WP_ARTIFACTS_PATH, 'test-results' ), snapshotPathTemplate: - '{testDir}/{testFileDir}/__snapshots__/{arg}-{projectName}{ext}', + '{testDir}/{testFileDir}/__snapshots__/{arg}-{projectName}{ext}', globalSetup: fileURLToPath( new URL( './config/global-setup.ts', 'file:' + __filename ).href ), diff --git a/plugins/woocommerce/tests/metrics/specs/editor.spec.js b/plugins/woocommerce/tests/metrics/specs/editor.spec.js index 62d0432e78a..30307a4d022 100644 --- a/plugins/woocommerce/tests/metrics/specs/editor.spec.js +++ b/plugins/woocommerce/tests/metrics/specs/editor.spec.js @@ -146,7 +146,6 @@ test.describe( 'Editor Performance', () => { await perfUtils.loadBlocksForLargePost(); await editor.insertBlock( { name: 'core/paragraph' } ); draftId = await perfUtils.saveDraft(); - console.log( draftId ); } ); test( 'Run the test', async ( { admin, page, perfUtils, metrics } ) => { diff --git a/plugins/woocommerce/tests/metrics/specs/product-editor.spec.js b/plugins/woocommerce/tests/metrics/specs/product-editor.spec.js index ce5eebb090f..b23eab5dda9 100644 --- a/plugins/woocommerce/tests/metrics/specs/product-editor.spec.js +++ b/plugins/woocommerce/tests/metrics/specs/product-editor.spec.js @@ -30,10 +30,6 @@ test.describe( 'Product editor performance', () => { }, } ); - test.beforeEach( async ( { page } ) => { - await toggleBlockProductEditor( 'enable', page ); - } ); - test.afterAll( async ( {}, testInfo ) => { const medians = {}; Object.keys( results ).forEach( ( metric ) => { @@ -45,6 +41,10 @@ test.describe( 'Product editor performance', () => { } ); } ); + test( 'Enable Product Editor', async ( { page } ) => { + await toggleBlockProductEditor( 'enable', page ); + } ); + test.describe( 'Loading', () => { const samples = 2; const throwaway = 1; diff --git a/tools/compare-perf/config.js b/tools/compare-perf/config.js index e8f1e5b2e0d..a84d788b392 100644 --- a/tools/compare-perf/config.js +++ b/tools/compare-perf/config.js @@ -2,13 +2,13 @@ const path = require( 'path' ); const getPnpmPackage = ( sourceDir ) => { const packageJson = require( path.join( sourceDir, 'package.json' ) ); - let pnpm_package = 'pnpm'; + let pnpmPackage = 'pnpm'; if ( packageJson.engines.pnpm ) { - pnpm_package = `pnpm@${ packageJson.engines.pnpm }`; + pnpmPackage = `pnpm@${ packageJson.engines.pnpm }`; } - return pnpm_package; + return pnpmPackage; }; const config = { @@ -16,18 +16,18 @@ const config = { pluginPath: '/plugins/woocommerce', testsPath: '/plugins/woocommerce/tests/metrics/specs', getSetupTestRunner: ( sourceDir ) => { - const pnpm_package = getPnpmPackage( sourceDir ); + const pnpmPackage = getPnpmPackage( sourceDir ); - return `npm install -g ${ pnpm_package } && pnpm install --filter="@woocommerce/plugin-woocommerce" &> /dev/null && cd plugins/woocommerce && pnpm exec playwright install chromium`; + return `npm install -g ${ pnpmPackage } && pnpm install --frozen-lockfile --filter="@woocommerce/plugin-woocommerce" &> /dev/null && cd plugins/woocommerce && pnpm exec playwright install chromium`; }, getSetupCommand: ( sourceDir ) => { - const pnpm_package = getPnpmPackage( sourceDir ); + const pnpmPackage = getPnpmPackage( sourceDir ); - return `npm install -g ${ pnpm_package } && pnpm install &> /dev/null && pnpm build &> /dev/null`; + return `npm install -g ${ pnpmPackage } && pnpm install --frozen-lockfile &> /dev/null && pnpm build &> /dev/null`; }, getTestCommand: ( sourceDir ) => { - const pnpm_package = getPnpmPackage( sourceDir ); - return `npm install -g ${ pnpm_package } && cd plugins/woocommerce && pnpm test:metrics`; + const pnpmPackage = getPnpmPackage( sourceDir ); + return `npm install -g ${ pnpmPackage } && cd plugins/woocommerce && pnpm test:metrics`; }, }; From c410610c6212acb89911f630cfb2d88b93eb1c5d Mon Sep 17 00:00:00 2001 From: Fernando Marichal Date: Tue, 6 Aug 2024 06:39:35 -0300 Subject: [PATCH 009/276] Rename and move errorHandler method (#50277) * Rename and move errorHandler method * Add changelog --- .../dev-50276_rename_and_move_error_handler | 4 ++ .../edit.tsx | 9 ++-- .../header/hooks/use-preview/use-preview.tsx | 7 ++- .../hooks/use-save-draft/use-save-draft.tsx | 7 ++- .../use-product-manager.ts | 38 ++-------------- .../src/utils/format-product-error.ts | 43 +++++++++++++++++++ 6 files changed, 67 insertions(+), 41 deletions(-) create mode 100644 packages/js/product-editor/changelog/dev-50276_rename_and_move_error_handler create mode 100644 packages/js/product-editor/src/utils/format-product-error.ts diff --git a/packages/js/product-editor/changelog/dev-50276_rename_and_move_error_handler b/packages/js/product-editor/changelog/dev-50276_rename_and_move_error_handler new file mode 100644 index 00000000000..0951cfcbedc --- /dev/null +++ b/packages/js/product-editor/changelog/dev-50276_rename_and_move_error_handler @@ -0,0 +1,4 @@ +Significance: minor +Type: dev + +Rename and move errorHandler method #50277 diff --git a/packages/js/product-editor/src/blocks/product-fields/product-details-section-description/edit.tsx b/packages/js/product-editor/src/blocks/product-fields/product-details-section-description/edit.tsx index a11376f0840..de6995726a4 100644 --- a/packages/js/product-editor/src/blocks/product-fields/product-details-section-description/edit.tsx +++ b/packages/js/product-editor/src/blocks/product-fields/product-details-section-description/edit.tsx @@ -42,7 +42,7 @@ import type { import { ProductDetailsSectionDescriptionBlockAttributes } from './types'; import * as wooIcons from '../../../icons'; import isProductFormTemplateSystemEnabled from '../../../utils/is-product-form-template-system-enabled'; -import { errorHandler } from '../../../hooks/use-product-manager'; +import { formatProductError } from '../../../utils/format-product-error'; export function ProductDetailsSectionDescriptionBlockEdit( { attributes, @@ -189,7 +189,7 @@ export function ProductDetailsSectionDescriptionBlockEdit( { } catch ( error ) { const { message, errorProps } = await getProductErrorMessageAndProps( - errorHandler( + formatProductError( error as WPError, productStatus ) as WPError, @@ -311,7 +311,10 @@ export function ProductDetailsSectionDescriptionBlockEdit( { } catch ( error ) { const { message, errorProps } = await getProductErrorMessageAndProps( - errorHandler( error as WPError, productStatus ) as WPError, + formatProductError( + error as WPError, + productStatus + ) as WPError, selectedTab ); createErrorNotice( message, errorProps ); diff --git a/packages/js/product-editor/src/components/header/hooks/use-preview/use-preview.tsx b/packages/js/product-editor/src/components/header/hooks/use-preview/use-preview.tsx index e3302b6be98..33af470f52f 100644 --- a/packages/js/product-editor/src/components/header/hooks/use-preview/use-preview.tsx +++ b/packages/js/product-editor/src/components/header/hooks/use-preview/use-preview.tsx @@ -16,7 +16,7 @@ import { useValidations } from '../../../../contexts/validation-context'; import { WPError } from '../../../../hooks/use-error-handler'; import { useProductURL } from '../../../../hooks/use-product-url'; import { PreviewButtonProps } from '../../preview-button'; -import { errorHandler } from '../../../../hooks/use-product-manager'; +import { formatProductError } from '../../../../utils/format-product-error'; export function usePreview( { productStatus, @@ -129,7 +129,10 @@ export function usePreview( { } catch ( error ) { if ( onSaveError ) { onSaveError( - errorHandler( error as WPError, productStatus ) as WPError + formatProductError( + error as WPError, + productStatus + ) as WPError ); } } diff --git a/packages/js/product-editor/src/components/header/hooks/use-save-draft/use-save-draft.tsx b/packages/js/product-editor/src/components/header/hooks/use-save-draft/use-save-draft.tsx index d1e2a64bc0b..7379ced3471 100644 --- a/packages/js/product-editor/src/components/header/hooks/use-save-draft/use-save-draft.tsx +++ b/packages/js/product-editor/src/components/header/hooks/use-save-draft/use-save-draft.tsx @@ -18,7 +18,7 @@ import { useValidations } from '../../../../contexts/validation-context'; import { WPError } from '../../../../hooks/use-error-handler'; import { SaveDraftButtonProps } from '../../save-draft-button'; import { recordProductEvent } from '../../../../utils/record-product-event'; -import { errorHandler } from '../../../../hooks/use-product-manager'; +import { formatProductError } from '../../../../utils/format-product-error'; export function useSaveDraft( { productStatus, @@ -108,7 +108,10 @@ export function useSaveDraft( { } catch ( error ) { if ( onSaveError ) { onSaveError( - errorHandler( error as WPError, productStatus ) as WPError + formatProductError( + error as WPError, + productStatus + ) as WPError ); } } diff --git a/packages/js/product-editor/src/hooks/use-product-manager/use-product-manager.ts b/packages/js/product-editor/src/hooks/use-product-manager/use-product-manager.ts index 584bdc3fae7..cb9e6afd57e 100644 --- a/packages/js/product-editor/src/hooks/use-product-manager/use-product-manager.ts +++ b/packages/js/product-editor/src/hooks/use-product-manager/use-product-manager.ts @@ -12,37 +12,7 @@ import { Product, ProductStatus, PRODUCTS_STORE_NAME } from '@woocommerce/data'; import { useValidations } from '../../contexts/validation-context'; import type { WPError } from '../../hooks/use-error-handler'; import { AUTO_DRAFT_NAME } from '../../utils/constants'; - -export function errorHandler( error: WPError, productStatus: ProductStatus ) { - if ( error.code ) { - return error; - } - - const errorObj = Object.values( error ).find( - ( value ) => value !== undefined - ) as WPError | undefined; - - if ( 'variations' in error && error.variations ) { - return { - ...errorObj, - code: 'variable_product_no_variation_prices', - }; - } - - if ( errorObj !== undefined ) { - return { - ...errorObj, - code: 'product_form_field_error', - }; - } - - return { - code: - productStatus === 'publish' || productStatus === 'future' - ? 'product_publish_error' - : 'product_create_error', - }; -} +import { formatProductError } from '../../utils/format-product-error'; export function useProductManager< T = Product >( postType: string ) { const [ id ] = useEntityProp< number >( 'postType', postType, 'id' ); @@ -107,7 +77,7 @@ export function useProductManager< T = Product >( postType: string ) { return savedProduct as T; } catch ( error ) { - throw errorHandler( error as WPError, status ); + throw formatProductError( error as WPError, status ); } finally { setIsSaving( false ); } @@ -128,7 +98,7 @@ export function useProductManager< T = Product >( postType: string ) { return duplicatedProduct as T; } catch ( error ) { - throw errorHandler( error as WPError, status ); + throw formatProductError( error as WPError, status ); } finally { setIsSaving( false ); } @@ -174,7 +144,7 @@ export function useProductManager< T = Product >( postType: string ) { return deletedProduct as T; } catch ( error ) { - throw errorHandler( error as WPError, status ); + throw formatProductError( error as WPError, status ); } finally { setTrashing( false ); } diff --git a/packages/js/product-editor/src/utils/format-product-error.ts b/packages/js/product-editor/src/utils/format-product-error.ts new file mode 100644 index 00000000000..6ac039c838b --- /dev/null +++ b/packages/js/product-editor/src/utils/format-product-error.ts @@ -0,0 +1,43 @@ +/** + * External dependencies + */ +import { ProductStatus } from '@woocommerce/data'; + +/** + * Internal dependencies + */ +import type { WPError } from '../hooks/use-error-handler'; + +export function formatProductError( + error: WPError, + productStatus: ProductStatus +) { + if ( error.code ) { + return error; + } + + const errorObj = Object.values( error ).find( + ( value ) => value !== undefined + ) as WPError | undefined; + + if ( 'variations' in error && error.variations ) { + return { + ...errorObj, + code: 'variable_product_no_variation_prices', + }; + } + + if ( errorObj !== undefined ) { + return { + ...errorObj, + code: 'product_form_field_error', + }; + } + + return { + code: + productStatus === 'publish' || productStatus === 'future' + ? 'product_publish_error' + : 'product_create_error', + }; +} From 5e5378e444527df7dc5bf794899aa9399c7c38ab Mon Sep 17 00:00:00 2001 From: Tarun Vijwani <11503784+tarunvijwani@users.noreply.github.com> Date: Tue, 6 Aug 2024 13:41:26 +0400 Subject: [PATCH 010/276] Remove Active Shipping Zones check for displaying shipping calculator on Cart Page (#49214) * Remove active shipping zones check for displaying shipping calculator - Remove active shipping zones check for displaying shipping calculator on Cart Page * Add changefile(s) from automation for the following project(s): woocommerce-blocks, woocommerce --------- Co-authored-by: Tarun Vijwani Co-authored-by: github-actions Co-authored-by: Seghir Nadir --- .../totals/shipping/shipping-address.tsx | 29 +------------------ ...emove-active-shipping-zone-check-cart-page | 4 +++ .../src/Blocks/BlockTypes/Cart.php | 1 - 3 files changed, 5 insertions(+), 29 deletions(-) create mode 100644 plugins/woocommerce/changelog/49214-fix-remove-active-shipping-zone-check-cart-page diff --git a/plugins/woocommerce-blocks/assets/js/base/components/cart-checkout/totals/shipping/shipping-address.tsx b/plugins/woocommerce-blocks/assets/js/base/components/cart-checkout/totals/shipping/shipping-address.tsx index dd9eb92adf7..2c3e645eabb 100644 --- a/plugins/woocommerce-blocks/assets/js/base/components/cart-checkout/totals/shipping/shipping-address.tsx +++ b/plugins/woocommerce-blocks/assets/js/base/components/cart-checkout/totals/shipping/shipping-address.tsx @@ -3,11 +3,7 @@ */ import { __ } from '@wordpress/i18n'; import { formatShippingAddress } from '@woocommerce/base-utils'; -import { useEditorContext } from '@woocommerce/base-context'; -import { - ShippingAddress as ShippingAddressType, - getSetting, -} from '@woocommerce/settings'; +import { ShippingAddress as ShippingAddressType } from '@woocommerce/settings'; import PickupLocation from '@woocommerce/base-components/cart-checkout/pickup-location'; import { CHECKOUT_STORE_KEY } from '@woocommerce/block-data'; import { useSelect } from '@wordpress/data'; @@ -25,41 +21,18 @@ export interface ShippingAddressProps { shippingAddress: ShippingAddressType; } -export type ActiveShippingZones = { - description: string; -}[]; - export const ShippingAddress = ( { showCalculator, isShippingCalculatorOpen, setIsShippingCalculatorOpen, shippingAddress, }: ShippingAddressProps ): JSX.Element | null => { - const { isEditor } = useEditorContext(); const prefersCollection = useSelect( ( select ) => select( CHECKOUT_STORE_KEY ).prefersCollection() ); - const activeShippingZones: ActiveShippingZones = getSetting( - 'activeShippingZones' - ); - - const hasMultipleAndDefaultZone = - activeShippingZones.length > 1 && - activeShippingZones.some( - ( zone: { description: string } ) => - zone.description === 'Everywhere' || - zone.description === 'Locations outside all other zones' - ); const hasFormattedAddress = !! formatShippingAddress( shippingAddress ); - // If there is no default customer location set in the store, - // and the customer hasn't provided their address, - // and only one default shipping method is available for all locations, - // then the shipping calculator will be hidden to avoid confusion. - if ( ! hasFormattedAddress && ! isEditor && ! hasMultipleAndDefaultZone ) { - return null; - } const label = hasFormattedAddress ? __( 'Change address', 'woocommerce' ) : __( 'Calculate shipping for your location', 'woocommerce' ); diff --git a/plugins/woocommerce/changelog/49214-fix-remove-active-shipping-zone-check-cart-page b/plugins/woocommerce/changelog/49214-fix-remove-active-shipping-zone-check-cart-page new file mode 100644 index 00000000000..985ae712a88 --- /dev/null +++ b/plugins/woocommerce/changelog/49214-fix-remove-active-shipping-zone-check-cart-page @@ -0,0 +1,4 @@ +Significance: minor +Type: fix + +Remove Active Shipping Zones check for displaying shipping calculator on the Cart Page. \ No newline at end of file diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/Cart.php b/plugins/woocommerce/src/Blocks/BlockTypes/Cart.php index b3cabefb20c..11f8bdb2d26 100644 --- a/plugins/woocommerce/src/Blocks/BlockTypes/Cart.php +++ b/plugins/woocommerce/src/Blocks/BlockTypes/Cart.php @@ -245,7 +245,6 @@ class Cart extends AbstractBlock { $this->asset_data_registry->add( 'hasDarkEditorStyleSupport', current_theme_supports( 'dark-editor-style' ) ); $this->asset_data_registry->register_page_id( isset( $attributes['checkoutPageId'] ) ? $attributes['checkoutPageId'] : 0 ); $this->asset_data_registry->add( 'isBlockTheme', wc_current_theme_is_fse_theme() ); - $this->asset_data_registry->add( 'activeShippingZones', CartCheckoutUtils::get_shipping_zones() ); $pickup_location_settings = LocalPickupUtils::get_local_pickup_settings(); $this->asset_data_registry->add( 'localPickupEnabled', $pickup_location_settings['enabled'] ); From 657a3fb99acff25805f51c484e372105de11000e Mon Sep 17 00:00:00 2001 From: Adrian Moldovan <3854374+adimoldovan@users.noreply.github.com> Date: Tue, 6 Aug 2024 11:39:57 +0100 Subject: [PATCH 011/276] [testing workflows] Update concurrency to not cancel the workflow when running on trunk (#50397) --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c4ca04202cc..e9eecfb8193 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ on: concurrency: group: '${{ github.workflow }}-${{ github.ref }}-${{ inputs.trigger }}' - cancel-in-progress: true + cancel-in-progress: ${{ github.ref != 'trunk' }} env: FORCE_COLOR: 1 From 1488a028171e86ca3ea114d97e11342583b5e215 Mon Sep 17 00:00:00 2001 From: Sam Seay Date: Tue, 6 Aug 2024 19:20:31 +0800 Subject: [PATCH 012/276] Remove unused php imports from BlockTemplatesRegistry that were accidentally left in a previous commit (#49757) * Remove unused php imports that were accidentally left in ddabdb1bc2b0c29f53008ce7418f6a36bbcf5252 --- plugins/woocommerce/changelog/49757-dev-remove-unused-imports | 4 ++++ plugins/woocommerce/src/Blocks/BlockTemplatesRegistry.php | 2 -- 2 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 plugins/woocommerce/changelog/49757-dev-remove-unused-imports diff --git a/plugins/woocommerce/changelog/49757-dev-remove-unused-imports b/plugins/woocommerce/changelog/49757-dev-remove-unused-imports new file mode 100644 index 00000000000..983bf338098 --- /dev/null +++ b/plugins/woocommerce/changelog/49757-dev-remove-unused-imports @@ -0,0 +1,4 @@ +Significance: patch +Type: dev +Comment: Removal of an unused import is a non-functional change. + diff --git a/plugins/woocommerce/src/Blocks/BlockTemplatesRegistry.php b/plugins/woocommerce/src/Blocks/BlockTemplatesRegistry.php index 966af6dfd05..76cec00b179 100644 --- a/plugins/woocommerce/src/Blocks/BlockTemplatesRegistry.php +++ b/plugins/woocommerce/src/Blocks/BlockTemplatesRegistry.php @@ -10,8 +10,6 @@ use Automattic\WooCommerce\Blocks\Templates\CartTemplate; use Automattic\WooCommerce\Blocks\Templates\CheckoutTemplate; use Automattic\WooCommerce\Blocks\Templates\CheckoutHeaderTemplate; use Automattic\WooCommerce\Blocks\Templates\ComingSoonTemplate; -use Automattic\WooCommerce\Blocks\Templates\ComingSoonEntireSiteTemplate; -use Automattic\WooCommerce\Blocks\Templates\ComingSoonStoreOnlyTemplate; use Automattic\WooCommerce\Blocks\Templates\OrderConfirmationTemplate; use Automattic\WooCommerce\Blocks\Templates\ProductAttributeTemplate; use Automattic\WooCommerce\Blocks\Templates\ProductCatalogTemplate; From 783f6dd3c2955008803f53c9e62ffa6fe956fbaf Mon Sep 17 00:00:00 2001 From: Vladimir Reznichenko Date: Tue, 6 Aug 2024 14:17:24 +0200 Subject: [PATCH 013/276] Monorepo: update pinned pnpm version to 9.1.3 in packageManager property. (#50402) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2920ad9d71d..ed0db1d6f99 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "title": "WooCommerce Monorepo", "description": "Monorepo for the WooCommerce ecosystem", "homepage": "https://woocommerce.com/", - "packageManager": "pnpm@9.6.0", + "packageManager": "pnpm@9.1.3", "engines": { "node": "^20.11.1", "pnpm": "^9.1.0" From b74bd01ca1d300a1dd5ad06f236e5ff0e0bd7578 Mon Sep 17 00:00:00 2001 From: RJ <27843274+rjchow@users.noreply.github.com> Date: Tue, 6 Aug 2024 20:20:45 +0800 Subject: [PATCH 014/276] fix: remove defaultProps in prep for react 19 (#50266) --- ...-remove-functional-component-default-props | 4 +++ packages/js/components/src/calendar/input.js | 18 +++------- packages/js/components/src/date/index.js | 13 ++++--- packages/js/components/src/summary/index.js | 10 +++--- packages/js/components/src/summary/number.js | 24 ++++--------- packages/js/components/src/timeline/index.js | 24 ++++++------- .../components/src/timeline/timeline-group.js | 17 ++++----- .../components/src/timeline/timeline-item.js | 9 +---- .../js/components/src/view-more-list/index.js | 6 +--- .../client/activity-panel/activity-panel.js | 6 +--- .../client/activity-panel/panels/help.js | 19 +++++----- .../components/report-table/index.js | 36 +++++++------------ .../homescreen/activity-panel/orders/index.js | 9 ----- .../marketing/coupons/knowledge-base/index.js | 15 +++----- .../coupons/recommended-extensions/index.js | 15 +++----- .../products-control/index.js | 15 +++----- ...-remove-functional-component-default-props | 4 +++ 17 files changed, 86 insertions(+), 158 deletions(-) create mode 100644 packages/js/components/changelog/50266-fix-remove-functional-component-default-props create mode 100644 plugins/woocommerce/changelog/50266-fix-remove-functional-component-default-props diff --git a/packages/js/components/changelog/50266-fix-remove-functional-component-default-props b/packages/js/components/changelog/50266-fix-remove-functional-component-default-props new file mode 100644 index 00000000000..6e876bf13d2 --- /dev/null +++ b/packages/js/components/changelog/50266-fix-remove-functional-component-default-props @@ -0,0 +1,4 @@ +Significance: minor +Type: dev + +Removed defaultProps from React functional components since they will be deprecated for React 19 \ No newline at end of file diff --git a/packages/js/components/src/calendar/input.js b/packages/js/components/src/calendar/input.js index 1b3c433dd18..049b529954b 100644 --- a/packages/js/components/src/calendar/input.js +++ b/packages/js/components/src/calendar/input.js @@ -9,17 +9,17 @@ import { uniqueId, noop } from 'lodash'; import PropTypes from 'prop-types'; const DateInput = ( { - disabled, + disabled = false, value, onChange, dateFormat, label, describedBy, error, - onFocus, - onBlur, - onKeyDown, - errorPosition, + onFocus = () => {}, + onBlur = () => {}, + onKeyDown = noop, + errorPosition = 'bottom center', } ) => { const classes = classnames( 'woocommerce-calendar__input', { 'is-empty': value.length === 0, @@ -73,12 +73,4 @@ DateInput.propTypes = { onKeyDown: PropTypes.func, }; -DateInput.defaultProps = { - disabled: false, - onFocus: () => {}, - onBlur: () => {}, - errorPosition: 'bottom center', - onKeyDown: noop, -}; - export default DateInput; diff --git a/packages/js/components/src/date/index.js b/packages/js/components/src/date/index.js index e67a986039f..281d54ed538 100644 --- a/packages/js/components/src/date/index.js +++ b/packages/js/components/src/date/index.js @@ -15,7 +15,12 @@ import { createElement } from '@wordpress/element'; * @param {string} props.visibleFormat * @return {Object} - */ -const Date = ( { date, machineFormat, screenReaderFormat, visibleFormat } ) => { +const Date = ( { + date, + machineFormat = 'Y-m-d H:i:s', + screenReaderFormat = 'F j, Y', + visibleFormat = 'Y-m-d', +} ) => { return (