Commit Graph

960 Commits

Author SHA1 Message Date
Alexandre Lara 3ecd34e01a Upgrade webpack to version 5 (https://github.com/woocommerce/woocommerce-blocks/pull/8013)
* Upgrade terser-webpack-plugin to version 4.2.3

* Upgrade webpack-bundle-analyzer to 4.7.0

* Upgrade to Webpack version 5

* Upgrade @wordpress/dependency-extraction-webpack-plugin to 4.6.0

* Upgrade dependency copy-webpack-plugin to version 11.0.0

* Upgrade dependency terser-webpack-plugin to version 5.3.6

* Replace webpack-rtl-plugin with the new @automattic/webpack-rtl-plugin

* Replace module.issuer with the new ModuleGraph API

There is a warning appearing in the console when running the application. This is due to the fact that the module.issuer has been deprecated on Webpack 5 and replaced with the new ModuleGraph API. This commit replaces the deprecated API with the new one.

* Upgrade babel and babel plugins to latest version

* Replace jsonpFunction with the new uniqueName property

Add a unique name of the webpack build to avoid multiple webpack runtimes to conflict when using globals. It defaults to output.library name or the package name from package.json in the context, if both aren't found, it is set to an ''.

* Replace cacheDirectory inline configuration with options.cacheDirectory

* Upgrade @wordpress/e2e-tests dependency to version 5.6.0

* Remove babel-plugin-transform-react-jsx dependency

Remove babel-plugin-transform-react-jsx dependency because it is already included in @wordpress/babel-preset-default

* Remove unnecessary Babel dependencies

Remove some unnecessary babel dependencies that are already included in the @babel/preset-env package.

* Upgrade puppeteer dependency to version 16.2.0

* Remove caret from package.json dependencies

* Fix Storybook build error

This commit fixes the Storybook build error that was being caused because of Storybook by default uses Webpack 4, but since we are currently upgrading our webpack to version 5, we need to install some required dependencies and also explicitly tell Storybook to use Webpack 5.

* Fix package-lock.json after merging with trunk

* Add own webpack-rtl-plugin implementation to the project

Before upgrading Webpack to version 5, we were using the original `webpack-rtl-plugin` released by Romain Berger; unfortunately, this plugin is not compatible with Webpack 5, so we replaced it with `@automattic/webpack-rtl-plugin`. The problem is that `@automattic/webpack-rtl-plugin` by default generates files with the '.rtl.css' suffix and does not provide a way to change that.

This commit adds our own implementation of the `webpack-rtl-plugin` (adapted from `@automattic/webpack-rtl-plugin`) that is compatible with Webpack 5 and allows us to change the suffix of the generated files to follow the recommended way defined by Wordpress (https://codex.wordpress.org/Right-to-Left_Language_Support)

* Change conditional clause to be multiline

* Fix package-lock.json after merge with trunk

* Fix package-lock.json after merge with trunk

* Rename files to fix ESLint errors

This commit renames files that have the .js extension but contain JSX code. This is causing ESLint to throw errors because by default our Eslint configuration expects only files with the .jsx extension to contain JSX code.

* Fix package-lock.json file

* Add is-plain-obj module to the transformIgnorePatterns of jest config

* Update package-lock.json

* Fix package-lock.json

* Upgrade @wordpress/i18n dependency to version 4.31.0

* Update package-lock.json

* Update composer lock file

* Fix Webpack config for Webpack 5

* Add the package-lock.json

* Remove unsupported config from webpack

* Fix error with Webpack build

* Add wait for network idle to the tests

* Attempt to fix e2e test

* Restore promise.all

* Upgrade puppeteer to v17.1.3

* Upgrade expect-puppeteer

* Update expect-puppeteer

* Downgrade expect-puppeteer

* Revert "Upgrade puppeteer to v17.1.3"

This reverts commit 61ed52a56f131961f3970b6fb22cdd8b540bada3.

* Upgrade Puppeteer to version 17.1.3

* Fix executionContext.frame is not a function error

* Fix e2e tests

* Remove isExperimentalBuild from Product Gallery inner blocks

* Upgrade Webpack and Webpack-cli to latest version

* Upgrade postcss and mini-css plugins

* Fix error with mini-cart block

* Fix styling error with filter blocks

* Fix issue when running unit tests

* Fix storybook script not loading

* Fix a11y issue in Storybook

* Fix error when multiple isExperimentalBuild was being used

* Prevent error when layout is not present in the attributes object

* Update `chunkIds` to `named` in Webpack

* Add cache groups to the Webpack configs
2023-09-20 17:31:52 -03:00
Mike Jolley edf4a95b23 Feature Branch: Blockified Order Confirmation (https://github.com/woocommerce/woocommerce-blocks/pull/10056)
* Main block types for confirmation

* Initial blocks

* Styling and placeholders

* Make blocks experimental

* Update summary icon

* Add name/description for status block and missing text descriptions in the block.

Closes woocommerce/woocommerce-blocks#10057

* Order confirmation: Convert Order Details Templates to Blocks (https://github.com/woocommerce/woocommerce-blocks/pull/10095)

* Move code from templates into the details block

* Details -> Totals

* Downloads block

* Sample content for downloads block

* Add block icon

* Add conversion template (https://github.com/woocommerce/woocommerce-blocks/pull/10077)

* Update inner block name

* Add default title constant

* Revert "Add default title constant"

This reverts commit 1dd3bbfecc1be83c367b1ab064f5032ea58cb678.

* Add global styles for order confirmation status block (https://github.com/woocommerce/woocommerce-blocks/pull/10164)

* Implement style controls

* Prevent link color spilling over onto wrapper

* Add styles and remove class names

* Remove __experimentalWritingMode

* Add global styles for order confirmation summary block (https://github.com/woocommerce/woocommerce-blocks/pull/10179)

* Styles for summary

* Remove __experimentalWritingMode

* Add table styles for order details (https://github.com/woocommerce/woocommerce-blocks/pull/10185)

* Add table styles for order details

* __experimentalFontWeight

* Add link styles

* Handle preview link styles

* Unauthenticated views for Order Confirmation template (https://github.com/woocommerce/woocommerce-blocks/pull/10414)

* Different views by permission

* check user id matches when logged out

* Add order confirmation wrapper block (https://github.com/woocommerce/woocommerce-blocks/pull/10286)

* Add a heading wrapper block

* Register the BillingWrapper Block server side

* Fix exception 'render_content' error

* Add the Billing Wrapper Block to the template

* Fix wrong block name error

* Fix php error

* Conditionally render Billing Address within the Wrapper

* Fix parent rendering

* Clean up code (remove billing address from the template)

* Update titles, descriptions, and icons of the billing Block and inner block

* Fix broken block by removing the "parent" keyword

* Use a user-friendly title and description for the Billing Wrapper

* Update Billing Wrapper Block's title case

Co-authored-by: Mike Jolley <mike.jolley@me.com>

* Fix PHP failing unit test

---------

Co-authored-by: Mike Jolley <mike.jolley@me.com>

* Remove "thanks" for authenticated page

* Introduce shipping wrapper based on billing wrapper

Closes woocommerce/woocommerce-blocks#10053

* Order confirmation block: Verify email address for guest customers (https://github.com/woocommerce/woocommerce-blocks/pull/10567)

* Add verify step for guest orders

* Render content to pass through block content

* Revert package changes

* Customer orders cannot use email to verify

* Add style controls for order shipping and billing address blocks (https://github.com/woocommerce/woocommerce-blocks/pull/10633)

* Order confirmation block styling (https://github.com/woocommerce/woocommerce-blocks/pull/10780)

* Add missing heading to order details

* Summary block spacing

* Update css variables

* table styles

* Inherit border styles for cells

* Alignment and address styles

* Add downloads wrapper

* Style controls

* Fix typo

* Update Download Wrapper's Icon

* Fix TS error

* Disable Download Block's server side rendering in the editor

This fixes the loading after each style change from the style controls

* Clean up Downloads render functions

* Fix client side Downloads Block's table border

* Download + Total wrappers and tables styling

* small screen

* Remove server side render for previews

---------

Co-authored-by: Saad Tarhi <saad.trh@gmail.com>

* Shorten template description

* Update test address data

* Avoid leaking order key in permission form

* Remove todo

* Make email form required.

* Remove edit page link

* Remove empty columns from address wrapper

* Remove IIFE

* typo

* Update description to mention billing

* Adjust link scss

* Fix wrapper markup and spacing controls

* Add link preview in editor

* Add initial E2E setup for the Order Confirmation Block (https://github.com/woocommerce/woocommerce-blocks/pull/10840)

* Fix WC_DateTime check

* Move form outside of block markup

* Add additional information block (https://github.com/woocommerce/woocommerce-blocks/pull/10842)

* Add block which contains hooks

* Use skeleton for placeholder instead of illustration

* Remove duplicate methods

* Remove duplicate align tag

* Update meta styles

* Tests for order confirmation conditional blocks (https://github.com/woocommerce/woocommerce-blocks/pull/10972)

* Add tests for conditional blocks

* Move setup into test

* Add E2E to the the Order Confirmation Block (https://github.com/woocommerce/woocommerce-blocks/pull/10863)

* Add editor util functions

* Update editor template E2E test

* Add the "exact" property for consistency

* Skip test

Can't get the element in the page. More investigation needed! Skipping
for now.

* Fix "transformIntoBlocks" logic

* Add tests for logged in user

* Fix "beforeAll" config

* Confirm downloads section is visible when logged in

* Create "verifyOrderConfirmationDetails" util function

* Add logged in test case

* Add Guest user test case

* Fix editor e2e testing

* Apply a proper teardown

* Fix failing tests after logout

* Ensure we are logged in before visiting the editor

* Ensure to have shipping selected

* Wait for changes to be saved on the editor

* Ensure shipping options is selected

* Remove comment

* Ensure we are logged in before going to the admin page

* Mark the Order Confirmation as a side effect test

* OrderConfirmation blocks are not experimental

* resolve merge conflict

* Revert package lock changes

* Fix enqueue_assets

* Fix CSS 404s

* Make template tests more robust

* Fix page URL for default confirmation page

* Try afterEach to log back in

* Skip guest/logout use cases

Login out causes other tests to fail. We will implement these case when
the multiple sign in roles are introduced in the codebase.

* Remove tests requiring login out & add comments

* Remove unused util functions

* Hide confirmation blocks from post editor

---------

Co-authored-by: Saad Tarhi <saad.trh@gmail.com>
Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com>
2023-09-20 13:56:00 +01:00
Karol Manijak e6bd74fd3c Fix JS Lint issues (https://github.com/woocommerce/woocommerce-blocks/pull/10866) 2023-09-07 12:01:15 +02:00
Sam Seay abd41cae11 Fixes for jest transpilation issues. (https://github.com/woocommerce/woocommerce-blocks/pull/10788)
* Fix bug where is-plain-obj is not transpiled by Jest, update lock.
* Update packages.
* Mock useSelect for a handful of RichText selectors in test.
* Resolve react to single version to avoid invalid hook errors.
* Patch trim-html locally to avoid a bug in the released npm source.
* Mock out resizeObserver to avoid https://github.com/FezVrasta/react-resize-aware/issues/58
* Don't transpile config package: https://github.com/node-config/node-config/issues/628
2023-09-05 04:03:35 +00:00
Sam Seay 44f48e41e9 Refactor errors util to TypeScript, minor typing fixes (https://github.com/woocommerce/woocommerce-blocks/pull/10754) 2023-08-30 18:56:28 +12:00
Karol Manijak dad3a41caa Fix UI misalignment of Filter by Price in TT1 theme (https://github.com/woocommerce/woocommerce-blocks/pull/10732)
* Fix UI misalignment of Filter by Price in TT1 theme

* Fix frontend Firefox styles

* Simplify the styles and fix them in Editor (Firefox/Safari)

* Align the background color and sizing in Firefox
2023-08-25 16:26:18 +02:00
Sam Seay a753a0f1d2 Add a generic arg to useCollection to improve typing of results. (https://github.com/woocommerce/woocommerce-blocks/pull/10696)
Closes woocommerce/woocommerce-blocks#5726
2023-08-24 04:49:41 +00:00
Sam Seay 9e24b0d91d Convert frontend-block.js to frontend-block.tsx and replace propTypes with TypeScript definitions (https://github.com/woocommerce/woocommerce-blocks/pull/10677) 2023-08-23 18:00:14 +12:00
Mike Jolley 4fd16267be Refactor Push Changes Readability and Performance (https://github.com/woocommerce/woocommerce-blocks/pull/10315)
* Add local state to address-form

* Update test with valid postcode and required fields

* Push changes refactoring

* Avoid loops due to retrying same data

* Callbacks to prevent rerenders

* Move validation functions

* Filter incoming values to only those included as fields to prevent errors

* Keep track of country changes to prevent excessive updates of addressFormFields.

* Use helpers in test

* Fill company

* Revert local state in address form

* Update address form to remove validation handling for postcode (country clears the field).

* Revert "Update test with valid postcode and required fields"

This reverts commit 718a6006df24f6e957297ad4d1ef9d6f690793bd.

* Clear postcode when country changes if invalid

* Revalidate fields when country changes

* Comment for pick

* Revert unneccessary test change

* Revery moving of functions to reduce diff size

* Increase push timeout in tests

* Revert test changes
2023-08-09 18:24:51 +01:00
Mike Jolley ab945e4a98 Performance: Optimise select shipping API calls (https://github.com/woocommerce/woocommerce-blocks/pull/10472)
* Support disabled inputs with styling

* Remove 1000ms debounce on selecting shipping rates and disable input when selecting

* Optimise rest api loading

* Fix analytics init

* Comments

* Unused after refactor

* More robust switching to prevent loop

* revert shipping controller change

* Remove ShippingAssets

* update test

* Comments
2023-08-08 11:56:19 +01:00
Lucio Giannotta 76b82000b3 Fix border color class names not being applied correctly (https://github.com/woocommerce/woocommerce-blocks/pull/10468) 2023-08-04 14:04:24 +02:00
Mike Jolley 2d530a7d5e Refactor ValidatedTextInput and AddressForm usage (https://github.com/woocommerce/woocommerce-blocks/pull/10309)
* Refactor ValidatedTextInput and AddressForm usage

* Remove formatting from onChange

* update useeffect dependencies

* Update validation text

* Style fields without floats (https://github.com/woocommerce/woocommerce-blocks/pull/10310)
2023-08-03 12:02:20 +01:00
Brian d46997a84f fix woocommerce/woocommerce-blocks#10027 (https://github.com/woocommerce/woocommerce-blocks/pull/10150) 2023-07-20 04:40:40 -07:00
Mike Jolley bd537e1008 Get latest cart when triggering events (https://github.com/woocommerce/woocommerce-blocks/pull/10254) 2023-07-19 10:42:25 +01:00
Karol Manijak 041d4ad4b1 Stop reading Product IDs from asset store in filter blocks (https://github.com/woocommerce/woocommerce-blocks/pull/10195)
* Remove queries that fetch all products for manipulating the results returned by the Store API for certain use-cases.

* Remove the code that's supposed to read product ids for filter context and logic around that in useCollectionData

* Fix incorrect merge

---------

Co-authored-by: Patricia Hillebrandt <patriciahillebrandt@gmail.com>
2023-07-14 11:18:10 +02:00
Alba Rincón d82a4b671f Add new `Ratings counter` block (https://github.com/woocommerce/woocommerce-blocks/pull/10114)
* Add new rating counter block

* Fix colors and register globally

* Add missing import

* Remove unused file

* Reorder blocks alphabetically

* Remove unnecessary html

* Change registration, fix classes

* Fix margin

* Remove icon from block.json, add ancestors

* Move icon and remove unused constants

* Fix classes

* Remove condition

* Allow to use block on product & product collection

* Enable block only on single product

* Move ancestors to block.json
2023-07-14 08:57:19 +02:00
Luigi Teschio 98a61d3a4d Enable declaration-block-no-duplicate-properties stylelint rule (https://github.com/woocommerce/woocommerce-blocks/pull/10163) 2023-07-11 13:03:05 +00:00
Alba Rincón 3ccfec1eee Fix `Product Rating` styles & alignment (https://github.com/woocommerce/woocommerce-blocks/pull/10097)
* Fix alignment not working on the editor

* Fix style regression on rating
2023-07-06 09:25:29 +02:00
Tarun Vijwani 6b8e4c38e0 Fix notice banner links for Legacy notices (https://github.com/woocommerce/woocommerce-blocks/pull/9996) 2023-07-04 04:16:26 -07:00
Albert Juhé Lluveras df3ff6793e Per block stylesheets (https://github.com/woocommerce/woocommerce-blocks/pull/9831)
* Clean up blank lines

* Update Webpack config

* Update PHP logic to load block styles

* Style fixes

* Style fixes (II)

* Style fixes (III)

* Style fixes (IV)

* Fix missing stylesheets in the Site Editor

* Fix wrong return values in some PHP method docs

* Fix missing ProductPrice stylesheet causing 404 in tests

* Fix missing ProductGallery stylesheet causing 404 in tests
2023-07-04 13:06:48 +02:00
Daniel Dudzic 8cacfce738 Rating: Fix TS error (https://github.com/woocommerce/woocommerce-blocks/pull/10001) 2023-07-03 10:50:06 +00:00
Mike Jolley a6b8e0e542 Hide "collection from" text when a location has an incomplete address. (https://github.com/woocommerce/woocommerce-blocks/pull/9808)
* Hide "collection from" text when a location has an incomplete address.

* Fix display on confirmation page

* has_valid_pickup_location helper

* Missing isset

* Update test

* Fix pickup text assertion

---------

Co-authored-by: Niels Lange <info@nielslange.de>
2023-07-03 10:10:18 +01:00
Albert Juhé Lluveras 559f712e35 Avoid usage of __experimentalUseFocusOutside (https://github.com/woocommerce/woocommerce-blocks/pull/10017)
* Avoid usage of __experimentalUseFocusOutside

* Remove unnecessary fix in QuantitySelector

* Add explanatory comment
2023-06-28 14:43:03 +02:00
Thomas Roberts 3ebcd7f601 Add `CartEventContext` and dispatch events when pressing proceed to checkout button (https://github.com/woocommerce/woocommerce-blocks/pull/7809)
* Add CartEventsContext with onProceedToCheckout event

* Wrap Cart in CartEventsProvider

* Dispatch onProceedToCheckout event when button is pressed

* Update type of children on CartEventsProvider

* Add test for ProceedToCheckout block

* Add tests for CartEventProvider

* Remove superfluous div

* Fix incorrect nesting after rebase

* Wrap mini cart in CartEventsProvider

* Dispatch onProceedToCheckout event when clicking button in mini cart

* Add tests for mini cart onProceedToCheckout emitter

* Make observer fail so navigation isn't attempted

* Prevent console error on navigation

* Try preventing navigation in unit tests

* Try preventing navigation in unit tests

* Try preventing navigation in unit tests

* Try preventing navigation in unit tests

* Try preventing navigation in unit tests

* Try preventing navigation in unit tests

* Try preventing navigation in unit tests
2023-06-19 08:44:37 -07:00
Alexandre Lara ba47d5dc40 Refactor: Convert All Products block file from Javascript to Typescript and replace propTypes with TypeScript definitions (https://github.com/woocommerce/woocommerce-blocks/pull/9802)
* Convert All Products block from Javascript to Typescript

* Replace BlockAttributes type with local interface
2023-06-16 12:48:47 -03:00
Mike Jolley ee4e0fac18 Keep change button visible even if prefersCollection is true (https://github.com/woocommerce/woocommerce-blocks/pull/9809) 2023-06-16 12:21:19 +01:00
Thomas Roberts aa1fe5c308 Add text limit to payment method descriptions in the page editor (https://github.com/woocommerce/woocommerce-blocks/pull/9708)
* Convert summary/utils to TS

* Add @wordpress/wordcount type defs

* Move trimWords, trimCharacters, remoteTags & appendMoreText to own file

* Add tests for trimWords and related functions

* Trim payment method description if it is longer than 30 words
2023-06-07 02:29:15 -07:00
Tom Cafferkey 0f59e3f698 Checkout block: Full width Place Order button when Return To Cart link is disabled. (https://github.com/woocommerce/woocommerce-blocks/pull/9721)
* When the Return To Cart link is disabled, make Place Order button full width

* Optional prop fullWidth has undefined type added to it
2023-06-05 15:31:32 +01:00
Karol Manijak 37d4823680 Product Collection - Add Inherit query from template control (https://github.com/woocommerce/woocommerce-blocks/pull/9485)
* Add columns control to product collection block editor settings

- `InspectorControls` from './inspector-controls' is now imported in `edit.tsx` and used in the returned JSX of `Edit` function.
- A new file `columns-control.tsx` is added under 'product-collection' block's 'inspector-controls' directory which exports a `ColumnsControl` component. This component uses `RangeControl` from '@wordpress/components' to control the number of columns in the product collection display layout when the layout type is 'flex'.
- The types file (`types.ts`) for 'product-collection' block is updated. The `Attributes` interface is renamed to `ProductCollectionAttributes` and the `ProductCollectionContext` interface is removed. The `ProductCollectionAttributes` now includes 'queryContext', 'templateSlug', and 'displayLayout' properties.

* Refactor: Simplify Fallback Return in ColumnsControl Component

This commit simplifies the fallback return value of the ColumnsControl component. Instead of returning an empty fragment (<> </>), it now returns null when the condition isn't met. This change improves readability and aligns with best practices for conditional rendering in React.

* Feature: Add 'Order By' Control to Product Collection Inspector

This commit adds a new 'Order By' control to the product collection inspector. The control allows users to specify the order of products in a collection by various attributes such as title and date. To support this, a new component 'OrderByControl' has been created and included in the product collection inspector. Additionally, the types for 'order' and 'orderBy' attributes have been updated and exported for reuse.

* Add more options to OrderBy type

* Add Inherit global query control to the Product Collection

* Add orderby handling on frontend & editor

The main changes include:
1. Added a new property 'isProductCollectionBlock' in the block.json to denote if a block is a product collection block.
2. In the ProductCollection PHP class, a new initialization function has been defined to hook into the WordPress lifecycle, register the block, and update the query based on this block.
3. Added methods to manage query parameters for both frontend rendering and the Editor.
4. Expanded allowed 'collection_params' for the REST API to include custom 'orderby' values.
5. Defined a function to build the query based on block attributes, filters, and global WP_Query.
6. Created utility functions to handle complex query operations such as merging queries, handling custom sort values, and merging arrays recursively.

These improvements allow for more flexible and robust handling of product collections in both the front-end display and the WordPress editor. It also extends support for custom 'orderby' values in the REST API, which allows for more advanced sorting options in product collections.

* Fix the condition to show query controls (they shoul appear if query is NOT inherited)

* Make Product Collection inheirt global query in product archive templates by default

* Add 'on sale' filter and enhance settings management in product collection block

This commit introduces several changes to the product collection block.
- First, it adds a new 'on sale' filter that can be used to display only the products that are currently on sale.
- It also refactors the settings management in the product collection block to use the experimental ToolsPanel component from WordPress, which provides a more flexible and intuitive way to manage block settings.
- It moves the 'Columns' control into the ToolsPanel, along with the 'Order by' control.
- A new utility function `setQueryAttribute` is introduced to simplify setting nested query parameters.
- The structure of the `ProductCollectionAttributes` and `ProductCollectionQuery` types have been adjusted to accommodate the changes.
- Finally, it makes corresponding changes in the PHP part to handle the new 'on sale' query parameter.

This should enhance the flexibility and user-friendliness of the product collection block.

* Revert "Make Product Collection inheirt global query in product archive templates by default"

This reverts commit d257e8bdb014742c40ef069110f6a2a35148fb7a.

* Updated 'inherit' behavior in the Product Collection block

This commit updates the 'inherit' behavior in the Product Collection block and its associated controls.

Changes include:
- Removed the 'inherit' attribute from the block's JSON definition
- Defined an array of 'archive product templates' which includes the WooCommerce product archive, taxonomy, attribute, and search results templates.
- Set the initial 'inherit' value based on the current template ID when the Product Collection block is first added to the page.
- Restored the query object value when toggling 'inherit' off.
- Conditionally rendered the InheritQueryControl based on the current editor being the site editor.

* Add stock status filter to WooCommerce product collection block

This commit introduces a stock status filter to the WooCommerce product collection block.

The changes include:
1. Added the ability to filter products based on their stock status within the 'product-collection' block. A new stock status control is created within the inspector-controls of the block.
2. A new 'get_stock_status_query' function is introduced in 'ProductCollection.php' which returns a query for products depending on their stock status.

Please note that the stock status filter will only appear in the experimental build for now.

* Refactor Stock Status control of Product Collection block

This commit refactors the Stock Status control. The changes aim to improve the code organization and make the behavior of the component more explicit.

The key modifications are:
1. Moved stock status related constants and functions from `inspector-controls/utils.tsx` to `inspector-controls/constants.ts`. This is done to ensure that all constants and similar utility functions are organized in one place.
2. Updated `product-collection/index.tsx` to import `getDefaultStockStatuses` from `inspector-controls/constants` instead of `inspector-controls/utils`.
3. Updated `stock-status-control.tsx` to determine whether the stock status has value or not by comparing with the default stock statuses using `fastDeepEqual`. If the stock status control is deselected, it resets the stock status to the default statuses.

These changes do not introduce any new functionalities, but improve the readability and maintainability of the code.

* Add keyword search control to Product Collection block

This commit introduces a keyword search functionality to the Product Collection block. The update is aimed to provide users with more flexibility and precision in product collection queries.

Key changes:
1. Introduced a new file `keyword-control.tsx` that creates a Keyword Control component. This component includes a TextControl field that allows inputting a search keyword. The keyword search is debounced to prevent unnecessary queries during input and updates the block's attributes accordingly.
2. Modified `inspector-controls/index.tsx` to include the KeywordControl in the ToolsPanel for the block's filters.
3. Adjusted `ProductCollection.php` to include the keyword search in the product query array.

With these changes, users can now search for products by keyword in the Product Collection block.

* Add product attributes filter control to ProductCollection block

- This commit introduces the ability to filter products by attributes in ProductCollection block.
- A new `woocommerceAttributes` key was added to the `block.json` file and the `ProductCollectionQuery` type. Also, a new file `attributes-control.tsx` was created, providing the UI component for the attribute filter control in the editor.
- In addition, updates were made to the `ProductCollection.php` file in the backend to support filtering products by attributes, and the tax query was updated to include attribute queries.
- Lastly, the `ProductCollectionInspectorControls` was updated to include the `AttributesControl` component, thus enabling users to filter products by attributes in the block editor."`

* remove unused import of getDefaultStockStatuses

* Delete a duplicate file

* Remove console log

* Add taxonomies control to Product collection block

The primary changes include:
1. `taxQuery` field in the `ProductCollectionAttributes` was changed from a string to an object in `assets/js/blocks/product-collection/types.ts` and `assets/js/blocks/product-collection/constants.ts`, accommodating the ability to query products by taxonomy terms.

2. `assets/js/blocks/product-collection/inspector-controls/utils.tsx` was moved to `assets/js/blocks/product-collection/utils.tsx` to make it available for broader use.

3. New component `TaxonomyControls` was created in `assets/js/blocks/product-collection/inspector-controls/taxonomy-controls.tsx`, which is included in `assets/js/blocks/product-collection/inspector-controls/index.tsx`. This new control allows users to filter products in the block by their taxonomy terms.

4. Updated the block's inspector controls in `assets/js/blocks/product-collection/inspector-controls/index.tsx` to use the new `TaxonomyControls` component.

Please note that the TaxonomyControls component uses experimental features of WordPress's FormTokenField. As a result, a comment has been added to disable eslint warnings regarding the use of experimental APIs.

* Address PR feedback & other improvements

1. Added `woocommerceAttributes` to `DEFAULT_FILTERS` in the `product-collection/constants.ts` file to fix `reset all` button issue.

2. Refactored `attributes-control.tsx` to make it more maintainable:
   - The constant `EDIT_ATTRIBUTES_URL` now uses `ADMIN_URL` from `@woocommerce/settings` for a more dynamic URL generation.
   - The interface `Props` has been renamed to `AttributesControlProps` for more explicit naming.
   - Removed the usage of `useState` and `useEffect` for selected attributes. Instead, `selectedAttributes` is now directly derived from `woocommerceAttributes`.
   - The CSS class `woocommerce-product-query-panel__external-link` was renamed to `wc-product-collection-panel__external-link`

3. Deleted the `product-collection/inspector-controls/constants.ts` file which was no longer necessary due to changes in product collection implementation.

These changes contribute to codebase quality, improving readability and maintainability.

* Address PR review comments

This commit involves a significant refactoring of the default product query inside the 'product-collection/constants.ts' file. A new constant `DEFAULT_QUERY` has been defined and used to replace the previously hard-coded default query settings. This refactoring aids in code readability and future modifications.

Changes also include adjustments in 'product-collection/inspector-controls' to enhance UI/UX. A new SCSS file 'editor.scss' has been created for custom styles related to the editor.

Additions include:
- Adding a class name `product-collection-inspector-toolspanel__filters` to ToolsPanel for additional styling.
- The experimental property `__experimentalShowHowTo` is set to false for `FormTokenField` and `StockStatusControl`, to hide some additional information.

In 'product-collection/inspector-controls/taxonomy-controls.tsx', the classname `product-collection-inspector__taxonomy-control` is added for improved CSS targeting.

* Add wc-block-editor prefix to className

* Make improvements to 'inherit' functionality in Product collection block.

Key changes are:

1. 'inherit' in 'ProductCollectionAttributes' within 'constants.ts' has been changed from 'false' to 'null'. This accommodates for situations when Product collection block is first added to the page.

2. Various improvements in 'index.tsx' file which include more robust null checking for the 'query' object, simplifying the way 'woocommerceAttributes' is obtained, and passing 'setQueryAttributeBind' and 'inherit' to the 'InheritQueryControl' component.

3. In 'inherit-query-control.tsx', 'InheritQueryControl' component has been refactored to use '__experimentalToolsPanelItem' from '@wordpress/components' instead of 'ToggleControl'. This adds more flexibility to the control.

4. Changes in 'ProductCollectionAttributes' and 'ProductCollectionQuery' types in 'types.ts'. The

* Improve product collection query inheritance and fix URL typo

This commit addresses two primary areas:
1. Fixed a typo in the URL used as a reference in the use-previous.ts file. The URL was incorrectly case-sensitive, which has been corrected.

2. The product-collection block in the JavaScript files has been refactored for better handling of query inheritance:

   - Changed the 'inherit' value from false to null in the DEFAULT_QUERY constant to handle initial state more accurately.

   - In product-collection/inspector-controls, implemented conditional rendering for Filters and Query Controls based on 'displayQueryControls'. Also, improved the 'InheritQueryControl' by using the 'usePrevious' hook to maintain the state before enabling the inheritance.

   - In inherit-query-control, enhanced the control to toggle the query inheritance. It now considers the 'inherit' state from the query object and keeps track of the query object state before enabling inheritance. If the inheritance is toggled off, it reverts the query to the previous state before inheritance was enabled.

* Minor improvemnets

* Add wc-block-editor- prefix with classNames

* Handle duplicate taxonomy names in Taxonomy controls

the taxonomy controls have been enhanced in the following ways:
1. Modified the BASE_QUERY object to include 'slug' in the '_fields' property. This will ensure that the 'slug' of the taxonomy term is fetched along with its 'id' and 'name'.

2. Added a 'slug' property to the Term type to store the 'slug' of each term.

3. Updated the useEffect hook inside the TaxonomyItem function to generate suggestions based on search results. The suggestions now include the 'slug' of a term if the term's name is not unique. This change will help users distinguish between terms with the same name but different slugs.

* Remove isset() in if condition as it's unnecessary

* Refactor TaxonomyItem component for better readability

Following changes were made:

1. The useSelect hooks which were being used to fetch existing terms and search results have been moved into their own custom hooks named 'useExistingTerms' and 'useSearchResults' respectively. This simplifies the TaxonomyItem function's body and makes the hooks' purposes clearer.

2. The comments and props destructuring for the TaxonomyItem function have been moved up to make it easier to understand the function's purpose and the props it receives.

3. This refactor does not introduce any changes in functionality. It only changes how the code is organized and presented, which will make future development easier.

* Handling for duplicate term names & other improvements

This commit enhances the `TaxonomyControls` component within `product-collection` block by adding memoization and improving term uniqueness handling.

Changes:

1. Imported `useMemo` from `@wordpress/element` for memoizing certain results.

2. `getTermIdByTermValue` function has been modified to use a `termIdToNameMap` (term ids as keys and term names as values). This provides a more efficient and direct mapping for term search.

3. Introduced `useTermIdToNameMap` function, which returns a `Map` where term ids are keys and term names are values. It handles duplicate term names by appending the term slug to the name, ensuring unique term names.

4. Updated the `useExistingTerms` and `useSearchResults` to include `taxonomy` in their dependency arrays for `useSelect` hook. This will force re-computation when `taxonomy` changes.

5. Changed `TaxonomyItem` from a function declaration to a const arrow function, consistent with the rest of the codebase.

6. Updated `onTermsChange` function in `TaxonomyItem` to accommodate the changes in `getTermIdByTermValue` and the introduction of `termIdToNameMap`.

7. Replaced `Set` with a standard array for storing new term IDs in `onTermsChange`. The `Set` was unnecessary as term IDs are unique by default.

8. Updated `TaxonomyItem`'s effects and rendering to work with `termIdToNameMap`, ensuring the displayed term names are unique.

This update will result in more efficient term search and handling, and it will solve issues related to duplicate term names.

* Restructure taxonomy controls in product collection block

This commit restructures the taxonomy controls in the product collection block for improved clarity and maintainability.
- The file `taxonomy-controls.tsx` has been deleted, and its functionality has been divided into two new files: `index.tsx` and `taxonomy-item.tsx`.

- The `index.tsx` file contains the main TaxonomyControls component, which is responsible for displaying taxonomy-related options in the block's inspector controls. It includes a custom hook `useTaxonomies` that fetches and returns taxonomies associated with product post type.

- The `taxonomy-item.tsx` file, on the other hand, contains a TaxonomyItem component that handles the rendering of individual taxonomy items. It also contains some utility functions for mapping term names and ids and fetching terms based on the search query.

This refactor aims to improve code readability and separation of concerns, thus making future changes and maintenance easier.

* Fix case insensitive search support for FormTokenField

This change enhances the search functionality of the FormTokenField by introducing support for case insensitive search. This has been achieved by adding a lower-case version of the term name to the 'termNameToIdMap'.

This is an important enhancement as it will make the search process more user-friendly and resilient to different casing inputs. Users will now be able to find the desired taxonomy term regardless of their input's case.

* Refactor getTermIdByTermValue function and update newSuggestions mapping

This commit does a couple of important things:
1. Reorders the definition of constants in `TaxonomyItemProps` for clarity.
2. Refactors the `getTermIdByTermValue` function. Instead of checking for an exact term name match in a convoluted manner, it now directly tries to fetch the `id` from the `searchTerm` if it is an object. If the `searchTerm` is not an object, the function tries to match it against the `termNameToIdMap` in both normal and lowercase forms. This simplification makes the function more readable and concise.
3. Updates the `newSuggestions` mapping in the `TaxonomyItem` component. It now has a fallback to `searchResult.name` if a term's name is not found in `termIdToNameMap`. This change ensures that even if the term's name is not in the map for some reason, we can still display a suggestion using the original name of the term.

* Optimize term fetching and initial search state in TaxonomyItem

This commit introduces a couple of improvements to the TaxonomyItem component.

1. The initial state of the 'search' state variable has been updated to 'undefined'. This change helps prevent unnecessary initial fetching of terms when the search input is empty.

2. Term fetching logic has been optimized to only enable term fetching when necessary:
   a) Fetching based on the search query is only enabled when 'search' is not 'undefined'.
   b) Fetching existing terms is only enabled when there are term IDs.

3. The block of code responsible for fetching existing terms and setting the current value has been moved upwards. This reordering of code does not change the functionality, but it groups together similar pieces of code, enhancing readability and maintainability.

These optimizations make the component more efficient by reducing unnecessary requests and computations, and they improve the code organization.

* Address PR comments and other improvements

This commit makes several changes:
1. The useEffect that sets the default attributes was moved and modified. This now includes a `query` attribute that utilizes the imported function `getDefaultValueOfInheritQueryFromTemplate`.
2. An early return was added in `edit.tsx` to prevent rendering until default attributes are set.
3. In `columns-control.tsx`, the early return was removed and a label was added to the `RangeControl` component.
4. In `inherit-query-control.tsx`, logic related to `inherit` value initial setting was refactored using a `useMemo` hook with `getDefaultValueOfInheritQueryFromTemplate` function. This logic was moved to a separate utility function in `utils`.
5. The `query` attribute is no longer optional in `types.ts`.
6. A new utility function `getDefaultValueOfInheritQueryFromTemplate` was created in `utils.tsx` to encapsulate the logic of deciding the default value of `inherit` query attribute based on the current template.

These changes aim to improve code clarity and maintainability.

* Add  with types import statement

---------

Co-authored-by: Manish Menaria <the.manish.menaria@gmail.com>
Co-authored-by: Alexandre Lara <allexandrelara@gmail.com>
2023-06-05 06:09:11 +00:00
Mike Jolley c6e0ca1d8b Combine country asset data to reduce the amount of data consumed by the cart and checkout blocks (https://github.com/woocommerce/woocommerce-blocks/pull/9552)
* Combine countryData using shared util

* Update tests for shared util

* Update client to use countryData

* Avoid duplication of country names

* Use cart version of deep_sort_with_accents

* Update assets/js/settings/blocks/constants.ts

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>

* Update LocaleSpecificAddressField type

* Support nested arrays

---------

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>
2023-05-31 10:30:44 +01:00
Mike Jolley 50ad36321a Use CSSProperties in place of Records for useStyleProps (https://github.com/woocommerce/woocommerce-blocks/pull/9483)
* Use CSSProperties in place of Records

* Update types from StyleEngine

* Remove parseStyle

* Combine StyleProps type
2023-05-30 14:45:59 +01:00
Albert Juhé Lluveras c267504bd6 Use a portal to render the Drawer close button to fix the alignment with the Mini-Cart Contents block (https://github.com/woocommerce/woocommerce-blocks/pull/9507) 2023-05-30 15:39:19 +02:00
Niels Lange 8a9bcd4d13 Adjust contributor docs (https://github.com/woocommerce/woocommerce-blocks/pull/9622)
* Adjust contributor docs

* Adjust contributor docs
2023-05-30 13:30:36 +07:00
Hritik Chaudhary edab9c00ab removed proptypes from product-list container (https://github.com/woocommerce/woocommerce-blocks/pull/9616)
Co-authored-by: Niels Lange <info@nielslange.de>
2023-05-28 15:11:28 +07:00
Saad Tarhi 4bdbdbf309 Fix total shipping display info when no shipping method is available (https://github.com/woocommerce/woocommerce-blocks/pull/8819)
* Fix total shipping info when no shipping are available

* Fix a logical error for displaying shipping info

* Fix failing unit tests

* Run unit test for the Cart instead of the Checkout

The calculator is only available for the Cart Block, so it doesn't make
sense to run this test for the Checkout Block

* Fix no shipping methods and incomplete address conflict

When there are no shipping methods (except for local pickup), we would
like to inform the shopper that there are no shipping options available
even though the address is complete

The solution we found is to check the address on the Cart Block only

* Refactor code

* Check whether rate is collectible without using hardcoded id

* Correctly negate hasCollectibleRate result

* Add notice when shipping is selected but no methods are available yet (https://github.com/woocommerce/woocommerce-blocks/pull/9171)

* Create useShippingTotalWarning hook

* Show notices above checkout sidebar

* Call hook to show notice in Checkout block

* Remove unused imports

* Update hook name to useShowShippingTotalWarning

* Move hook to its own file

* Import shipping data internally (without alias)

* Remove unused imports

* Move import to correct place

* Return early to avoid if else

* Refactor useShowShippingTotalWarning

* Get shipping rates directly from the cart instead of the hook

* Show shipping cost when price information is available

* Check if the passed rates are considered selected

* Prevent errors when no rates are available

---------

Co-authored-by: Thomas Roberts <thomas.roberts@automattic.com>
Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>
Co-authored-by: Tarun Vijwani <tarun.vijwani@automattic.com>
2023-05-25 06:31:15 +01:00
Tarun Vijwani 90e57bca11 Add unit test cases for Min and Max price for shipping methods (https://github.com/woocommerce/woocommerce-blocks/pull/9336)
* Add unit test cases for Min and Max price for shipping methods

* Move Test for Min and Max rates to shipping-rates

- Move Test for Min and Max rates to shipping-rates.
- Use single shippingRates object throughout the test cases.

* Update assets/js/base/utils/test/shipping-rates.ts

Co-authored-by: Niels Lange <info@nielslange.de>

* Update assets/js/base/utils/test/shipping-rates.ts

Co-authored-by: Niels Lange <info@nielslange.de>

* Add helper function to generate shipping rates

* Add a test for empty shipping rates

* Remove redundant attribute values from generateRate function

---------

Co-authored-by: Niels Lange <info@nielslange.de>
2023-05-22 12:48:12 +04:00
Tarun Vijwani 296a0b4360 Fix Checkout block stepped sections numbers overlapping (https://github.com/woocommerce/woocommerce-blocks/pull/9497)
- Fix the padding for checkout-step component
2023-05-22 11:03:50 +04:00
Albert Juhé Lluveras 5d6397b7b5 Prevent QuantitySelector stealing focus on page load (https://github.com/woocommerce/woocommerce-blocks/pull/9487) 2023-05-18 09:17:29 +02:00
Tarun Vijwani 21a356c58c Allow Shipping method prices to inherit global styles text color (https://github.com/woocommerce/woocommerce-blocks/pull/9456)
- Remove the hardcoded color for Shipping method prices
2023-05-17 21:52:20 +04:00
Albert Juhé Lluveras 3b28b74777 Mini Cart: stop using Modal component (https://github.com/woocommerce/woocommerce-blocks/pull/9345)
* Remove unused styles

* Replace usage of Modal component with custom Drawer

* Update MiniCart.php class structure

* Update tests

* Prevent focus styles to appear unnecessarily when opening the Mini Cart drawer

* Work-around issue with disabled buttons causing lose of focus inside the Mini-Cart drawer

* Revert "Work-around issue with disabled buttons causing lose of focus inside the Mini-Cart drawer"

This reverts commit 4360f77384ad1f1d90a3ba8a0385ad79da2449f2.

* QuantitySelector: focus text input field after decrease or increase button become disabled

* Move focus to the input field also when the body has focus, that fixes the issue in Chrome

* Add explanatory comment
2023-05-16 10:41:26 +02:00
Mike Jolley 6e3b1ac7fb Styling fixes for form step headings (https://github.com/woocommerce/woocommerce-blocks/pull/9437)
Co-authored-by: Niels Lange <info@nielslange.de>
2023-05-15 12:28:24 +01:00
Tarun Vijwani afa5406746 Fix radio control overlap when font-size is small (https://github.com/woocommerce/woocommerce-blocks/pull/9436)
Co-authored-by: Niels Lange <info@nielslange.de>
2023-05-15 14:46:42 +04:00
Mike Jolley 43eaed7620 Experiment: Replace style hooks coming from `@wordpress/block-editor` (https://github.com/woocommerce/woocommerce-blocks/pull/9251)
* Replace all style hooks with useStyleProps hook

* Remove border/color/spacing hooks

* Style Props Hook

* Make use of `change-case` package

* Tidy up block wrappers

* Attribute filter does not use frontend.ts nor styles within block

* Remove frontend from filter blocks and unused styleprops usage

* Tidy up variable names so its clearer attributes are not required specifically from blocks

* Update assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/mini-cart-title-label-block/block.tsx

Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com>

* Update assets/js/blocks/attribute-filter/block-wrapper.tsx

Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com>

* Update assets/js/blocks/active-filters/block-wrapper.tsx

Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com>

* Update assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/mini-cart-checkout-button-block/block.tsx

Co-authored-by: Tom Cafferkey <tjcafferkey@gmail.com>

* Update assets/js/blocks/rating-filter/block-wrapper.tsx

Co-authored-by: Tom Cafferkey <tjcafferkey@gmail.com>

* Update assets/js/blocks/stock-filter/block-wrapper.tsx

Co-authored-by: Tom Cafferkey <tjcafferkey@gmail.com>

* Update assets/js/blocks/price-filter/block-wrapper.tsx

Co-authored-by: Tom Cafferkey <tjcafferkey@gmail.com>

* Update assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/mini-cart-cart-button-block/block.tsx

Co-authored-by: Tom Cafferkey <tjcafferkey@gmail.com>

* Simplify styleprop

* Styleprops simplify

* Fix withFeaturedItem styles

* Like the original hook, flatten props and combine with parsed styles

---------

Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com>
Co-authored-by: Tom Cafferkey <tjcafferkey@gmail.com>
2023-05-12 13:42:16 +01:00
Dennis Jonda 1add6a146e Fix alignment issue with 'Add Coupon Code' button in WooCommerce Blocks checkout page (https://github.com/woocommerce/woocommerce-blocks/pull/9392)
Co-authored-by: Niels Lange <info@nielslange.de>
2023-05-12 12:28:08 +07:00
Seghir Nadir 4c2f024418 Only validate postcode if its required or filled (https://github.com/woocommerce/woocommerce-blocks/pull/9377)
* Only validate postcode if its required

* Clear postcode validation error if postcode is not required

---------

Co-authored-by: Niels Lange <info@nielslange.de>
2023-05-09 16:54:28 +07:00
Albert Juhé Lluveras 349ae658bb Mini Cart drawer: print width in PHP (https://github.com/woocommerce/woocommerce-blocks/pull/9329)
* Mini Cart drawer: print width in PHP

* Remove unnecessary timeout

* Make sure classic themes have a Mini Cart contents width value set up
2023-05-05 11:44:41 +02:00
Mike Jolley 1a0f209770 Fix shipping notices for multiple packages (https://github.com/woocommerce/woocommerce-blocks/pull/9285)
* Move notice to top and only show on cart page

* Missing setting on cart page prevents notice display

* Allow null in the select-shipping-rate endpoint to select all packages

* Only show the warning if different packages are selected

* Check if selected rates is an object before mapping it

---------

Co-authored-by: Thomas Roberts <thomas.roberts@automattic.com>
2023-05-02 16:04:29 +01:00
Mike Jolley 2d506f9f57 Fix/you do not need lodash (https://github.com/woocommerce/woocommerce-blocks/pull/9161)
* Remove lodash `without` usage

* isNumber

* Remove lodash `difference`

* Replace lodash isEmpty with type guard

* Replace isObject with type guard

* remove lodash noop

* Replace lodash clamp

* replace lodash uniqueId

* Remove uniqueId import

* Add eslint rule to restrict lodash import

* Replace lodash range

* Replace lodash has() function

Replace lodash has

* replace omitby

* Replace lodash isEqual with fastDeepEqual

* Replace kebabCase with change-case package

* Replace lodash camelCase

Replace lodash mapKeys with function

Move mapkeys to utility

Create camelCaseKeys which replaces usage of mapKeys

* Replace lodash debounce with custom utiity

* replace lodash keyby

* Replace lodash pick with native function

* Replace lodash cloneDeep with klona

* Replace snake case keys package with change case

* Replace sortBy with fast sort package

* replace isEmpty with type guard

* Replace pickBy usage in validation reducer

* Replace groupBy usage in search list control

* Replace flatten, uniqBy usage in getProducts()

* Remove setWith and clone from updateState

* Replace custom useThrottle with useThrottledCallback from use-debounce package

* onSelectRate can use-debounce

* Fix missing flatten

* Update assets/js/data/cart/test/push-changes.ts

Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com>

---------

Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com>
2023-04-28 11:29:45 +01:00
Tom Cafferkey a22ab08410 Remove min-height and padding for WP Button elements (https://github.com/woocommerce/woocommerce-blocks/pull/9260)
* Remove min-height and padding for WP Button elements

* Remove commented out code

* Add min-height style back in for .woocommerce-block-theme-has-button-styles themes
2023-04-28 10:49:12 +01:00
Albert Juhé Lluveras ce97f918ea Mini Cart block: fix slide in animation (https://github.com/woocommerce/woocommerce-blocks/pull/9195) 2023-04-25 13:39:21 +02:00