Commit Graph

5340 Commits

Author SHA1 Message Date
Tarun Vijwani 0833316129 Cherry-pick 10.4.0 testing steps 2023-06-08 14:51:50 +04:00
Tarun Vijwani 8bcbeb8c0e Cherry-pick 10.4.0 changelogs 2023-06-08 14:43:54 +04:00
Albert Juhé Lluveras aa912e31a8 Fix the order of enqueued scripts in the Mini-Cart block (https://github.com/woocommerce/woocommerce-blocks/pull/9749)
* Fix the order of enqueued scripts in the Mini-Cart block

* Use again wp_script_is() to detect is a script has been enqueued or not
2023-06-08 10:37:00 +02:00
Tarun Vijwani c6d0f30989 Remove experimental blocks from the changelog 2023-06-08 11:36:21 +04:00
Manish Menaria d91385e3b9 Product Collection: Hand picked products control in sidebar settings (https://github.com/woocommerce/woocommerce-blocks/pull/9733)
* Add support for hand-picked products in Product Collection block

This commit introduces the ability to manually select specific products in the Product Collection block.

Changes include:
- Added `woocommerceHandPickedProducts` to the `ProductCollectionQuery` and `DEFAULT_FILTERS` in `constants.ts`.
- Created a new control file `hand-picked-products-control.tsx` which introduces a token field where the user can search for and select specific products.
- Included `HandPickedProductsControl` in the Product Collection block's inspector controls in `index.tsx`.
- Updated `ProductCollectionQuery` in `types.ts` to accommodate handpicked products.
- Updated the PHP `ProductCollection` class to handle the hand-picked products query parameters.

These changes allow users to hand-pick products to be displayed in the Product Collection block. This allows for greater customization of the products shown in the block.

* Enhance handling of hand-picked products

- A Set data structure is now used to store 'newHandPickedProducts' instead of an Array, which will help prevent duplicate entries.
- Additionally, the suggestions for products to be hand-picked now excludes already selected products, enhancing the user experience by avoiding redundancy in the suggestions list.
- Lastly, the function name 'displayTransform' has been changed to 'transformTokenIntoProductName' to more accurately reflect its purpose, which is to transform a token into a product name.

* Update import & export of HandPickedProductsControl
2023-06-08 06:03:01 +00:00
Manish Menaria 1814bc95e5 Product Collection: Add author filter in sidebar settings (https://github.com/woocommerce/woocommerce-blocks/pull/9736)
* Add author filter to ProductCollection block

This commit adds an author filter to the ProductCollection block in WooCommerce Blocks.

- A new file, `author-control.tsx`, has been created inside the `inspector-controls` directory of the `product-collection` block. This file contains the React component for the author filter, which fetches the list of authors from the WordPress database using `useEntityRecords`. The filter provides an interface for selecting authors whose products should be displayed in the ProductCollection block.

- The author filter is added to the main component of the `inspector-controls` in `index.tsx`.

- In `ProductCollection.php`, the 'author' parameter is now included in the product query. This allows products from a specific author to be displayed in the ProductCollection block, depending on the user's selection in the Gutenberg editor.

This addition enhances the functionality of the ProductCollection block by allowing site administrators to create more customized and targeted displays of products.

* Update error handling

* Refactor 'Author' interfaces and fix offset calculation

This commit refactors the 'Author' interfaces in the 'author-control.tsx' file. The interface 'AuthorsMapping' has been removed and its properties have been merged into 'AuthorsInfo' for simplicity and maintainability.

In the PHP file 'ProductCollection.php', the offset calculation logic has been improved to handle pagination correctly. Now, the offset is calculated as '(per_page * (page - 1)) + offset', which correctly accounts for both the page number and the offset when determining the starting point for the product query.
2023-06-08 11:10:05 +05:30
Tarun Vijwani 0f3e9340f0 Cherry pick 9684 PR as it got merged after release branch was created 2023-06-07 23:37:49 +04:00
Luigi Teschio 460b8a5034 Product rating: improve preview style when the product doesn't have rating (https://github.com/woocommerce/woocommerce-blocks/pull/9684)
* product rating: improve preview style when no rating is visible

* fix class naming

* fix cutted star

* change variable

* fix cut border
2023-06-07 23:32:31 +04:00
Tarun Vijwani 5f60dbbd6c Update testing zip file to include 9748 PR 2023-06-07 21:52:06 +04:00
Tarun Vijwani 9468a9c0d8 Cherry-pick 9748 2023-06-07 21:44:20 +04:00
Alba Rincón 8eb7b16af0 Render the single product title as an h1 (https://github.com/woocommerce/woocommerce-blocks/pull/9748) 2023-06-07 21:31:24 +04:00
Alba Rincón 06a0ab94ce Render the single product title as an h1 (https://github.com/woocommerce/woocommerce-blocks/pull/9748) 2023-06-07 15:47:56 +02:00
Tarun Vijwani 76601b3971 Remove expiremental block from testing notes 2023-06-07 16:56:56 +04:00
Roy Ho 70e3533467 Prevent showing edit product details link when in multiple products context (https://github.com/woocommerce/woocommerce-blocks/pull/9741) 2023-06-07 05:43:04 -07:00
Tarun Vijwani 910cd98b58 Move 9691 PR to WC core 2023-06-07 16:11:46 +04:00
Hritik Chaudhary af09b0c9b8 Removed proptypes from grid-content-control (https://github.com/woocommerce/woocommerce-blocks/pull/9713)
Co-authored-by: Niels Lange <info@nielslange.de>
Co-authored-by: Alba Rincón <albarin@users.noreply.github.com>
2023-06-07 13:22:50 +02: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
Alba Rincón cbfd2977dd [Patterns] Update button color for `Hero Product 3 Split` (https://github.com/woocommerce/woocommerce-blocks/pull/9467)
* Add color to the search button, fix php notices

* Update button color

* Update button color

* Update button color

* Update button color

* Update button color

* Remove WooCommerce from the name to follow standards

* Remove colors from buttons in patterns without hardcoded bg color
2023-06-07 10:10:07 +02:00
Tom Cafferkey 24a293bde7 Fix/escape add query arg template url (https://github.com/woocommerce/woocommerce-blocks/pull/9715)
* Escape postId for template part within MiniCart

* Escape  url

* Change esc_url to esc_url_raw
2023-06-06 16:42:19 +01:00
Roy Ho dc6fa4a8c9 Fix value without onchaning warning (https://github.com/woocommerce/woocommerce-blocks/pull/9727) 2023-06-06 06:04:40 -07:00
Hritik Chaudhary 93119e9de6 Remove propTypes definitions from All Reviews block (https://github.com/woocommerce/woocommerce-blocks/pull/9631)
* converted all-reviews block to tsx and removed proptypes

* Update assets/js/blocks/reviews/all-reviews/index.tsx

Co-authored-by: Niels Lange <niels.lange@a8c.com>

* Update assets/js/blocks/reviews/all-reviews/edit.tsx

Co-authored-by: Niels Lange <niels.lange@a8c.com>

* Update assets/js/blocks/reviews/all-reviews/block.tsx

Co-authored-by: Niels Lange <niels.lange@a8c.com>

---------

Co-authored-by: Niels Lange <info@nielslange.de>
Co-authored-by: Niels Lange <niels.lange@a8c.com>
2023-06-06 14:46:49 +02:00
Tarun Vijwani bfa3cff71a Add more details in testing instructions for 9684 PR 2023-06-06 16:01:54 +04:00
Tarun Vijwani ce95cfea7c Update testing instructions for 9684 PR 2023-06-06 15:53:15 +04:00
Alba Rincón ceba20832f Update zip for testing 2023-06-06 11:35:15 +02:00
Tarun Vijwani 5ceb6e5b8c Cherry pick 9723 PR 2023-06-06 12:34:05 +04:00
dependabot[bot] 525bd58c74 Bump mockery/mockery from 1.5.1 to 1.6.1 (https://github.com/woocommerce/woocommerce-blocks/pull/9728)
Bumps [mockery/mockery](https://github.com/mockery/mockery) from 1.5.1 to 1.6.1.
- [Release notes](https://github.com/mockery/mockery/releases)
- [Changelog](https://github.com/mockery/mockery/blob/1.6.1/CHANGELOG.md)
- [Commits](https://github.com/mockery/mockery/compare/1.5.1...1.6.1)

---
updated-dependencies:
- dependency-name: mockery/mockery
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-06 10:27:55 +02:00
Luigi Teschio eddaf34918 Single Product Template: fix Compatibility Layer when the template implements the Single Product Template (https://github.com/woocommerce/woocommerce-blocks/pull/9723) 2023-06-06 12:27:17 +04:00
Tarun Vijwani b8fdeb4b68 Fix version number in testing notes 2023-06-06 12:23:14 +04:00
Tarun Vijwani 4cf62bd787 Add testing instructions for the release 2023-06-06 12:21:45 +04:00
Alba Rincón 643bdbe4df [Patterns] Add new `Footer with Simple Menu and Cart` pattern (https://github.com/woocommerce/woocommerce-blocks/pull/9176)
* Add new `Footer with Simple Menu and Cart` pattern

* Remove ref, overlay off

* Improve search, navigation and separator

* Improve the mobile view

* Make string translatable
2023-06-06 08:56:20 +02:00
Luigi Teschio a69f0874e5 Single Product Template: fix Compatibility Layer when the template implements the Single Product Template (https://github.com/woocommerce/woocommerce-blocks/pull/9723) 2023-06-05 17:48:36 +02:00
Luigi Teschio a27787fb17 Product rating: improve preview style when the product doesn't have rating (https://github.com/woocommerce/woocommerce-blocks/pull/9684)
* product rating: improve preview style when no rating is visible

* fix class naming

* fix cutted star

* change variable

* fix cut border
2023-06-05 17:27:55 +02:00
Alexandre Lara 27275b913e Refactor: Add useIsDescendentOfSingleProductTemplate hook (https://github.com/woocommerce/woocommerce-blocks/pull/9657)
* Add useIsDescendentOfSingleProductTemplate hook

* Replace logic with useIsDescendentOfSingleProductTemplate hook
2023-06-05 12:13:28 -03:00
Tarun Vijwani 7ccf34dcc4 Update readme and version details 2023-06-05 18:52:43 +04: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
dependabot[bot] 3d853d77d5 Bump automattic/jetpack-autoloader from 2.11.19 to 2.11.21 (https://github.com/woocommerce/woocommerce-blocks/pull/9639)
Bumps [automattic/jetpack-autoloader](https://github.com/Automattic/jetpack-autoloader) from 2.11.19 to 2.11.21.
- [Release notes](https://github.com/Automattic/jetpack-autoloader/releases)
- [Changelog](https://github.com/Automattic/jetpack-autoloader/blob/trunk/CHANGELOG.md)
- [Commits](https://github.com/Automattic/jetpack-autoloader/compare/v2.11.19...v2.11.21)

---
updated-dependencies:
- dependency-name: automattic/jetpack-autoloader
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-05 16:24:44 +02:00
dependabot[bot] 01ad02ffbe Bump tj-actions/branch-names from 6 to 7 (https://github.com/woocommerce/woocommerce-blocks/pull/9688)
Bumps [tj-actions/branch-names](https://github.com/tj-actions/branch-names) from 6 to 7.
- [Release notes](https://github.com/tj-actions/branch-names/releases)
- [Changelog](https://github.com/tj-actions/branch-names/blob/main/HISTORY.md)
- [Commits](https://github.com/tj-actions/branch-names/compare/v6...v7)

---
updated-dependencies:
- dependency-name: tj-actions/branch-names
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-05 16:22:55 +02:00
dependabot[bot] d14bd2f605 Bump dependabot/fetch-metadata from 1.4.0 to 1.5.1 (https://github.com/woocommerce/woocommerce-blocks/pull/9689)
Bumps [dependabot/fetch-metadata](https://github.com/dependabot/fetch-metadata) from 1.4.0 to 1.5.1.
- [Release notes](https://github.com/dependabot/fetch-metadata/releases)
- [Commits](https://github.com/dependabot/fetch-metadata/compare/v1.4.0...v1.5.1)

---
updated-dependencies:
- dependency-name: dependabot/fetch-metadata
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-05 16:21:17 +02:00
Roy Ho 5a5d5d315a Make mini cart icon RTL on RTL sites in editor (https://github.com/woocommerce/woocommerce-blocks/pull/9707)
* Make mini cart icon RTL on RTL sites in editor

* Use BEM convention
2023-06-05 06:36:57 -07:00
Alba Rincón 4cd22fb705 Create `Customer account` block e2e playwright tests (https://github.com/woocommerce/woocommerce-blocks/pull/9505)
* Create customer account block playwright tests

* Refactor after review

* Refacto after review
2023-06-05 14:39:11 +02:00
Luigi Teschio 4c3cb1ab17 Enable Single Product block (https://github.com/woocommerce/woocommerce-blocks/pull/9714)
* Enable Single Product block

* Single Product Block: remove experimental build flag
2023-06-05 12:11:21 +00:00
Luigi Teschio 5b862f3fb1 Product Rating: fix the filter woocommerce_product_get_rating_html is removed (https://github.com/woocommerce/woocommerce-blocks/pull/9719) 2023-06-05 13:41:35 +02:00
Luigi Teschio 57c5d4a89a Product Price: remove underline on sale price (https://github.com/woocommerce/woocommerce-blocks/pull/9702) 2023-06-05 07:56:25 +00:00
Alexandre Lara 2438ce41a6 Add to Cart with Options block: Prevent page redirection when clicking on Add to Cart button (https://github.com/woocommerce/woocommerce-blocks/pull/9691)
* Add isDescendentOfSingleProductBlock attribute to Add to Cart Form block

* Prevent notice from appearing when Add to Cart button is clicked

When the Add to Cart Form is added inside the Single Product Block, we
have to prevent the notice from appearing when the Add to Cart button is
clicked.

* Fix PHP CS errors

* Fix PHP CS errors

* Fix PHP CS errors

* Fix PHP CS errors

* Fix PHP CS errors

* Fix PHP CS errors

* Add phpcs:ignore WordPress.Security.NonceVerification.Recommended

* Fix Processing form data without nonce verification.

* PHP Ignore

* Improve doc comments

* Improve name for add_to_cart_message_html_filter hook

* Prevent page redirection when click on Add to Cart button

* Fix PHP CS errors
2023-06-05 09:50:48 +02: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
Tom Cafferkey ebffcf3031 Fix esc_html error in footer pattern (https://github.com/woocommerce/woocommerce-blocks/pull/9704) 2023-06-02 14:57:58 -04:00
Alexandre Lara 5f307e1097 Add to Cart Form block: Prevent notice from appearing after clicking on Add to Cart button inside Single Product block (https://github.com/woocommerce/woocommerce-blocks/pull/9685)
* Add isDescendentOfSingleProductBlock attribute to Add to Cart Form block

* Prevent notice from appearing when Add to Cart button is clicked

When the Add to Cart Form is added inside the Single Product Block, we
have to prevent the notice from appearing when the Add to Cart button is
clicked.

* Fix PHP CS errors

* Fix PHP CS errors

* Fix PHP CS errors

* Fix PHP CS errors

* Fix PHP CS errors

* Fix PHP CS errors

* Add phpcs:ignore WordPress.Security.NonceVerification.Recommended

* Fix Processing form data without nonce verification.

* PHP Ignore

* Improve doc comments

* Improve name for add_to_cart_message_html_filter hook

* Replace equal operator with identity operator in the conditional statement
2023-06-02 11:29:22 -03:00
Luigi Teschio d85a6ecbd2 Blockified Single Product Template: add product-classes via `wc_get_product_class` (https://github.com/woocommerce/woocommerce-blocks/pull/9697)
* Blockified Single Product Template: add product-classes via wc_get_product_class

* Update src/BlockTemplatesController.php

Co-authored-by: Karol Manijak <karol.manijak@automattic.com>

---------

Co-authored-by: Karol Manijak <karol.manijak@automattic.com>
2023-06-02 14:16:20 +00:00
Luigi Teschio 278f0ec0db Blockified Single Product Template: avoid to add another group block on the editor side when the user creates a template for a specific product (https://github.com/woocommerce/woocommerce-blocks/pull/9699)
* Blockified Single Product Template: avoid to add another group block on the editor side when the user creates a template for a specific product

* improve comment
2023-06-02 15:59:20 +02:00
Luigi Teschio 136762ee78 Blockified Single Product Template: use h1 for the Product Title (https://github.com/woocommerce/woocommerce-blocks/pull/9698) 2023-06-02 12:36:18 +00:00
Patricia Hillebrandt 4d1a490a18 Product Image Gallery > Reintroduce filters and override-restore the global product variable. (https://github.com/woocommerce/woocommerce-blocks/pull/9630)
* Reintroduce filters to the product gallery block and override/restore the global product variable.

* Restore the product global variable earlier and update docblock for the get_block_type_uses_context method.
2023-06-02 16:47:30 +05:30
Manish Menaria 9426102565 Product Collection: Add Taxonomy filters to sidebar settings (https://github.com/woocommerce/woocommerce-blocks/pull/9634)
* 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 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.

* 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.

* 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

* 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.

---------

Co-authored-by: Alexandre Lara <allexandrelara@gmail.com>
2023-06-02 15:31:29 +05:30
Hritik Chaudhary cec26fa849 Remove propTypes definitions from Reviews By Category (https://github.com/woocommerce/woocommerce-blocks/pull/9623)
* converted reviews-by-category block

* converted index.js to tsx

* fix imports

* removed unnecessary metadata

* added type explicitly
2023-06-02 07:53:16 +02:00
Roy Ho cd84b4bed3 Add e2e tests for attributes count (https://github.com/woocommerce/woocommerce-blocks/pull/9500)
* Add e2e tests for attributes count

* Add test with pricing filter and turn on debug to prevent cache

* Prevent tests from passing if test page is not loaded

* Use WP wrapper to call WC CLI

* Refactor to use more of PW methods

* Use existing active filters block post for testing

* Move prepareAttributes function to global setup
2023-06-01 07:14:50 -07:00
Mike Jolley 30b5a1107a Update test command so PHP unit tests can be ran locally again (https://github.com/woocommerce/woocommerce-blocks/pull/9678)
* Update test command so tests can be ran locally again

* Update mappings instead

* Put back ${PWD##*/ for current dir

* Try mapping both paths
2023-06-01 13:42:23 +01:00
Roy Ho a67948d7e1 Ensure aria-label is showing correct value based on setting (https://github.com/woocommerce/woocommerce-blocks/pull/9672)
* Ensure aria-label is showing correct value based on setting

* Reuse same format code
2023-06-01 05:41:43 -07:00
Saad Tarhi bdf9a5e218 Fix local pickup e2e test (https://github.com/woocommerce/woocommerce-blocks/pull/9643)
Co-authored-by: Niels Lange <info@nielslange.de>
2023-06-01 13:01:36 +01:00
Luigi Teschio f17a09340f Enable blockified templates (https://github.com/woocommerce/woocommerce-blocks/pull/9551)
* Enable blockified templates

* add html template

* fix function

* WIP

* Migrate Classic Block E2E tests to Playwright (https://github.com/woocommerce/woocommerce-blocks/pull/9575)

* Add E2E tests

* add comment

* set worker to 1

* try now

* add beforeAll and afterAll hook

* restore woocommerce-gutenberg-products-block.php

* enable plugin with .wp-env configuration

* remove waitForNetworkIdle

* Products block: Add e2e tests (https://github.com/woocommerce/woocommerce-blocks/pull/9577)

* migrate classic block to Playwright

* fix can be inserted more than once tests

* migrate classic block to Playwright

* fix command

* remove old tests

* improve E2E tests

* skip test

* Products block: add E2E pw tests

* Add E2E tests

* fix E2E test

* test now

* try now

* rename path

* set one worker

* try now

* try now

* try now

* set 1 worker
2023-06-01 11:51:59 +00:00
Albert Juhé Lluveras c45ac22b02 Add 10.2.2 testing steps 2023-05-31 17:13:55 +02:00
Albert Juhé Lluveras 28edcf308b Add 10.2.2 changelog 2023-05-31 17:12:44 +02:00
Albert Juhé Lluveras 73ffb371d2 Fix colors not being applied to Mini-Cart Proceed to Checkout Button in the editor (https://github.com/woocommerce/woocommerce-blocks/pull/9661) 2023-05-31 13:58:20 +02:00
Tom Cafferkey 801b7846e7 Product Categories List: Add show child categories only toggle (https://github.com/woocommerce/woocommerce-blocks/pull/9550)
* Add show child categories only toggle to Product Categories block

* Check if current page is a template editor before adding the toggle

* Show current category if show_children is enabled and its the last category in the hierarchy

* Update comment

* Fix typo

* Remove forward slash

* Add is-widget-editor utility and enable feature for block usage in widget editor

* Don't render anything if the child only option is enabled and there are no children
2023-05-31 12:49:31 +01: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
Roy Ho 5f5a0d4b54 Stack cart and checkout buttons on smaller screens (https://github.com/woocommerce/woocommerce-blocks/pull/9603) 2023-05-30 13:07:30 -07:00
Albert Juhé Lluveras b17cdaa1da Add 10.0.6 testing steps 2023-05-30 21:53:25 +02:00
Albert Juhé Lluveras 59f2175bae Add 10.0.6 changelog 2023-05-30 21:52:18 +02:00
Albert Juhé Lluveras 4da98fde56 Fix Mini-Cart block check to see whether a script has already been enqueued (https://github.com/woocommerce/woocommerce-blocks/pull/9649) 2023-05-30 18:37:43 +02:00
Thomas Roberts fcedb41bbc Remove `setFullAddressPushed` to prevent address continually pushing (https://github.com/woocommerce/woocommerce-blocks/pull/9606)
* Remove fullShippingAddressPushed action/selectors etc from wc/store/cart

* Remove setFullAddressPushed from push-changes
2023-05-30 08:46:18 -07:00
Albert Juhé Lluveras bc34d9faaf Prevent horizontal shift when opening the Mini-Cart drawer if scrollbars are visible (https://github.com/woocommerce/woocommerce-blocks/pull/9648)
* Fix wrong TS name

* Prevent page horizontal shift when opening the Mini-Cart drawer when scrollbars are visible
2023-05-30 17:09:11 +02: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
Alexandre Lara 6b105f0504 Product Rating block: Add the block to the Single Product template by default (https://github.com/woocommerce/woocommerce-blocks/pull/9510)
* Add Single Product template support to Product Rating block

* Add the Product Rating block to the Single Product Template by default

* Fix Product Rating block position on Single Product HTML template
2023-05-30 10:10:25 -03:00
Roy Ho 3f216104a2 Ensure inner content is not truncated on different widths (https://github.com/woocommerce/woocommerce-blocks/pull/9640) 2023-05-30 06:06:48 -07:00
Luigi Teschio 1ed5a06d86 Replace placeholder blockified templates with the right one (https://github.com/woocommerce/woocommerce-blocks/pull/9579)
* Add blockified templates

* removed queryId
2023-05-30 14:10:46 +02:00
Manish Menaria a6c31a7878 [Product Collection] Add `Attributes` filter control to sidebar settings (https://github.com/woocommerce/woocommerce-blocks/pull/9600)
* 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 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.

* 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.

* 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

* 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.

* Add wc-block-editor prefix to className

---------

Co-authored-by: Alexandre Lara <allexandrelara@gmail.com>
2023-05-30 11:06:26 +00:00
Albert Juhé Lluveras 27e3a9a3cc Fix invisible Mini-Cart badge in themes without <body> background (https://github.com/woocommerce/woocommerce-blocks/pull/9601) 2023-05-30 10:36:29 +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
Alexandre Lara 134b12bef7 Product Rating block: Add Single Product template support to the block (https://github.com/woocommerce/woocommerce-blocks/pull/9499)
* Add Single Product template support to Product Rating block

* Remove example attribute from block.json

Co-authored-by: Luigi Teschio <gigitux@gmail.com>

* Set isDescedentOfSingleProductTemplate attribute default to false

* Remove withProductSelector HOC

Since we are using the `ancestor` key then we don't need to use this HOC anymore

* Remove unused import on Product Rating Edit component

---------

Co-authored-by: Luigi Teschio <gigitux@gmail.com>
2023-05-29 16:54:36 -03:00
Luigi Teschio ec797e689f restore upsell products (https://github.com/woocommerce/woocommerce-blocks/pull/9636) 2023-05-29 15:46:55 +02:00
Hritik Chaudhary 86e96c0d0b Remove propTypes definitions from Newest Products block (https://github.com/woocommerce/woocommerce-blocks/pull/9613)
* converted product-new block

* converted product-new block

* filename changes in readme and checkstyle.xml

---------

Co-authored-by: Niels Lange <info@nielslange.de>
2023-05-29 13:12:36 +07:00
Hritik Chaudhary 2e1193b2a9 removed proptypes from add-to-cart (https://github.com/woocommerce/woocommerce-blocks/pull/9615)
Co-authored-by: Niels Lange <info@nielslange.de>
2023-05-29 11:13:25 +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
Niels Lange fdf81f6088 Update README.md 2023-05-27 20:31:15 +07:00
Daniel Dudzic 3e33914e87 Mini-Cart: Make error notifications non-dismissable. Closes woocommerce/woocommerce-blocks#8965. (https://github.com/woocommerce/woocommerce-blocks/pull/9578) 2023-05-26 19:39:33 +02:00
Niels Lange cb3a2cc056 Update README.md 2023-05-26 22:16:18 +07:00
Alexandre Lara 8a75ec8bc2 Fix magnifying glass appearing outside the product image gallery (https://github.com/woocommerce/woocommerce-blocks/pull/9594) 2023-05-26 11:23:24 -03:00
Tarun Vijwani f6a827b639 Fix Cambodian postal code validation (https://github.com/woocommerce/woocommerce-blocks/pull/9597)
-Fix the postal code validation for Cambodia to accept 6 digit postal code instead of 5 digit.
2023-05-26 17:56:55 +04:00
Luigi Teschio 40eb06a060 Fix PHP lint (https://github.com/woocommerce/woocommerce-blocks/pull/9608)
* fix CI on php linting errors

* not disable the linter rule at file level
2023-05-26 13:54:16 +00:00
Manish Menaria 3a4792150c Product Collection - Add keyword control to sidebar settings (https://github.com/woocommerce/woocommerce-blocks/pull/9583)
* 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 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.

* 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.

* 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.

* remove unused import of getDefaultStockStatuses
2023-05-26 13:21:51 +00:00
Manish Menaria c3060cff0e Product Collection: Add stock status filter (https://github.com/woocommerce/woocommerce-blocks/pull/9580)
* 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 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.

* 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.

* 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.

* Fix: Default values of attributes not saving as serialized block comment

This was happening because of this issue: https://github.com/WordPress/gutenberg/issues/7342

Therefore, I had to use `useEffect` to set the default values of the attributes.

Here is the list of changes I made:
1. Removed default values from `block.json` for `query`, `tagName`, and `displayLayout`.
2. Moved the default values to `constants.ts` and created a new object `DEFAULT_ATTRIBUTES` to store them.
3. Relocated `constants.ts` from `inspector-controls` to the parent directory.
4. Refactored `edit.tsx` to use `DEFAULT_ATTRIBUTES` from `constants.ts` to set default attributes using `useEffect`.
5. Removed the attributes assignment from `registerBlockType` in `index.tsx`.
6. Updated `columns-control.tsx`, `index.tsx`, `order-by-control.tsx`, and `stock-status-control.tsx` to import from the relocated `constants.ts`.
7. Updated `ProductCollectionAttributes` and `ProductCollectionQuery` in `types.ts` to include `tagName` and `isProductCollectionBlock` respectively.
8. Modified `ProductCollection.php` to match the updated `orderBy` key in the query parameter.

This refactor enhances the readability of the code and reduces duplication by keeping all constants and default values in one place.

* Replace usage of 'statii' with 'statuses' in stock status handling

This commit replaces all instances of 'statii' with the correct term 'statuses' in the context of handling stock status. This change affects three files:
1. `assets/js/blocks/product-collection/inspector-controls/stock-status-control.tsx` - The term is corrected in a comment block.
2. `assets/js/blocks/product-collection/types.ts` - Updated the name of a variable in the `ProductCollectionQuery` interface.
3. `src/BlockTypes/ProductCollection.php` - Here, the term is replaced in several locations including variable names, comments and the method `get_stock_status_query`.

This commit helps improve code readability and consistency across the repository.
2023-05-26 11:44:37 +00:00
Albert Juhé Lluveras e4f1dfdc22 Clarify step when bumping a release in WC core (https://github.com/woocommerce/woocommerce-blocks/pull/9605) 2023-05-26 12:05:10 +02:00
Hritik Chaudhary 5bd706edd9 Remove propTypes definitions from Top Rated Products block (https://github.com/woocommerce/woocommerce-blocks/pull/9595)
* replace propTypes and converted to tsx -  product-top-rated/block.js

* replace propTypes and converted to tsx -  product-top-rated/block.js

* converted product-top-rated to typescript

* added JSX.Element

---------

Co-authored-by: Niels Lange <info@nielslange.de>
2023-05-26 13:46:13 +07:00
Alexandre Lara 75d92b60b8 Remove Add Review link and hide rating when the Product has no rating (https://github.com/woocommerce/woocommerce-blocks/pull/9556) 2023-05-25 11:49:02 -03:00
Albert Juhé Lluveras 1817cfe179 Add 10.2.1 testing steps 2023-05-25 15:00:01 +02:00
Albert Juhé Lluveras a2cc867b62 Add 10.2.1 changelog 2023-05-25 14:58:53 +02:00
Luigi Teschio 4fb7da7962 Classic Product Template visible in the inserter (https://github.com/woocommerce/woocommerce-blocks/pull/9573) 2023-05-25 09:42:29 +02:00
Manish Menaria 0b3853090b Product Collection: Add 'on sale' filter and enhance settings management in product collection block (https://github.com/woocommerce/woocommerce-blocks/pull/9549)
* 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 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.

* 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.
2023-05-25 06:38:19 +00: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
Roy Ho b858f93628 Remove trailing comma (https://github.com/woocommerce/woocommerce-blocks/pull/9593) 2023-05-24 13:43:11 -07:00
Daniel W. Robert 80bfab6d76 Update lockfile for fresh installation. (https://github.com/woocommerce/woocommerce-blocks/pull/9574) 2023-05-24 13:00:13 -04:00
Albert Juhé Lluveras 31487e01b0 Add 10.0.5 testing notes 2023-05-24 17:49:32 +02:00
Albert Juhé Lluveras 90207c7cdc Add 10.0.5 changelog 2023-05-24 17:47:55 +02:00
Albert Juhé Lluveras 480750d20c Prevent Mini-Cart dependency scripts to lazy-load if they have already been enqueued (https://github.com/woocommerce/woocommerce-blocks/pull/9587) 2023-05-24 16:57:00 +02:00
Mike Jolley e66e683625 10.4.0-dev 2023-05-24 14:28:19 +01:00
Mike Jolley fc573a816c 10.3.0 Testing instructions and Changelog 2023-05-24 14:26:55 +01:00
Hritik Chaudhary ed2c17f16c Remove `propTypes` definitions from Product Search block (https://github.com/woocommerce/woocommerce-blocks/pull/9565)
* Remove propTypes definitions for product search

* Resolved TS errors

* Addressed review comments

---------

Co-authored-by: Niels Lange <info@nielslange.de>
2023-05-24 19:24:08 +07:00
Patricia Hillebrandt e6e908c483 Restore the global variable to its original value after being overriden. (https://github.com/woocommerce/woocommerce-blocks/pull/9581) 2023-05-24 14:08:32 +02:00
Manish Menaria 376aa1ebdb Add 'products-block-post-template' class to product templates (https://github.com/woocommerce/woocommerce-blocks/pull/9569) 2023-05-24 10:01:59 +00:00
Luigi Teschio a996ab7351 update @wordpress/env package (https://github.com/woocommerce/woocommerce-blocks/pull/9572) 2023-05-23 15:45:40 +00:00
Thomas Roberts 75785ea46a Update documentation for additionalCartCheckoutInnerBlockTypes filter (https://github.com/woocommerce/woocommerce-blocks/pull/8994) 2023-05-23 02:50:13 -07:00
Albert Juhé Lluveras a04c00a79f Make Mini-Cart block work well with caching plugins (https://github.com/woocommerce/woocommerce-blocks/pull/9493)
* Make Mini-Cart block work well with caching plugins

* Add tests

* Add back aria-label to Mini-Cart menu

* Fetch Mini-Cart data before page finishes loading

* Store and retrieve Mini-Cart values from localStorage for better performance

* Update styles as early as possible

* Reorder code

* Remove overrideTotals param from updateTotals() function

* Update tests

* Initialize local storage inside a function and add act to filter tests

* Replace void with undefined types in several funtions

* Fix 0 quantity badge appearing on page load
2023-05-23 09:28:40 +02:00
Patricia Hillebrandt 0dae17510d Fix > Product details listing pattern - Ensure the editor preview is properly rendered after page refresh (https://github.com/woocommerce/woocommerce-blocks/pull/9563)
* Fix editor render for a few paragraphs within the Product Listing Pattern.

* Update spacing and fontWeight.
2023-05-22 19:41:36 +00:00
Roy Ho 3fcbf43d60 Revert "Update the logic of disabling some blocks in the widget areas and post editor (https://github.com/woocommerce/woocommerce-blocks/pull/9462)" (https://github.com/woocommerce/woocommerce-blocks/pull/9561)
This reverts commit 2a4b78c150.
2023-05-22 08:59:51 -07:00
Luigi Teschio c919466a8c Enable blockified conversation to archive templates (https://github.com/woocommerce/woocommerce-blocks/pull/9509) 2023-05-22 12:17:56 +00:00
Thomas Roberts 56879a4861 Check if package rates is an array before filtering on it (https://github.com/woocommerce/woocommerce-blocks/pull/9351)
Co-authored-by: Niels Lange <info@nielslange.de>
2023-05-22 02:43:00 -07:00
Seghir Nadir 5457145c6a Trigger the set-billing-address when editing Shipping (https://github.com/woocommerce/woocommerce-blocks/pull/8841) 2023-05-22 09:30:49 +00: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
Alexandre Lara 410e041936 Remove the fill color of the Product Meta icon (https://github.com/woocommerce/woocommerce-blocks/pull/9506) 2023-05-19 16:59:18 -03:00
Alexandre Lara 0847c20f79 Remove the fill color of the Product Details icon and move it to the icons library (https://github.com/woocommerce/woocommerce-blocks/pull/9503) 2023-05-19 12:09:13 -03:00
Albert Juhé Lluveras b0af5ac12e Update Mini-Cart block logic to use isSiteEditorPage util (https://github.com/woocommerce/woocommerce-blocks/pull/9501)
* Revert "Mini-Cart: prevent 'Mini-Cart in cart and checkout pages' toggle from showing up in the post/page editor (https://github.com/woocommerce/woocommerce-blocks/pull/9442)"

This reverts commit 0bfc1b341e.

* Update Mini-Cart block logic to use isSiteEditorPage util
2023-05-18 15:53:01 +02:00
Patricia Hillebrandt 61fbf572cb Single Product Block > Only reset the post data if `setup_postdata` was invoked. (https://github.com/woocommerce/woocommerce-blocks/pull/9474)
* Only call wp_reset_postdata() if the global post variable was changed.

* Make global_post_variable_changed static.

* rely on the output of setup_postdata for verifying if the global variable was successfully changed.

* ditch the static var and defaulting to false instead.

* Rely on static as the post reset only happens when the loop of inner blocks ends and not right away.

* Update the  variable when the postdata is reset.
2023-05-18 15:35:46 +02:00
Luigi Teschio 0bf8048bd1 Fix compatibility layer when no products are displayed (https://github.com/woocommerce/woocommerce-blocks/pull/9464)
* POC

* add compatibility with the product recommendations extension

* improve readibility key

* improve readibility code

* improve readibility

* fix compatibility layer when no products are displayed

* remove duplicate code
2023-05-18 14:19:46 +02:00
Alexandre Lara bad4c30e36 Add to Cart with Options: Fix styles that are not being applied correctly (https://github.com/woocommerce/woocommerce-blocks/pull/9472)
* Add missing WooCommerce styles to Add to Cart with Options block

* Fix input style for Add to Cart with Options block

* Add comment about the input-text css class that was added to the Add To Cart Form
2023-05-18 08:02:51 -03:00
Manish Menaria 57d4ac529e Product Collection: Add 'Order By' Control to Product Collection Inspector (https://github.com/woocommerce/woocommerce-blocks/pull/9480)
* 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 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: handle undefined index for isProductCollectionBlock

This commit addresses a potential issue where the 'isProductCollectionBlock' index might not be defined in certain situations within the 'build_query' method of the ProductCollection class.

Previously, we directly accessed 'isProductCollectionBlock' from the 'query' context of the block. Now, we use the null coalescing operator (??) to ensure that we assign a default value of false if 'isProductCollectionBlock' is not set.

This change provides a safer way to handle the scenario when the 'isProductCollectionBlock' is not defined in the block context and helps prevent undefined index warnings.
2023-05-18 10:54:08 +00:00
Mike Jolley 715e63fbfd Revert changes in woocommerce/woocommerce-blocks#9332 and instead enqueue assets in correct place depending on admin vs frontend (https://github.com/woocommerce/woocommerce-blocks/pull/9495) 2023-05-18 10:46:17 +01:00
Luigi Teschio 86bb06a9a8 Product Archive Template: Fix compatibility Layer with Product Recommendations extension (https://github.com/woocommerce/woocommerce-blocks/pull/9452)
* POC

* add compatibility with the product recommendations extension

* improve readibility key

* improve readibility code

* improve readibility

* remove duplicate logic

* improve code readability
2023-05-18 11:41:44 +02: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
Alexandre Lara 2ef37db063 Add useIsDescendentOfSingleProductBlock hook to product rating block (https://github.com/woocommerce/woocommerce-blocks/pull/9489) 2023-05-17 10:58:12 -03:00
Luigi Teschio 689b5dd22a Fix undo button (https://github.com/woocommerce/woocommerce-blocks/pull/9478)
* fix undo button

* fix label
2023-05-17 13:25:02 +00:00
Mike Jolley bb1f578002 Store API: Fix payment method validation (fixes COD) (https://github.com/woocommerce/woocommerce-blocks/pull/9375)
* Widen enum for validation before cart is loaded

* Improve error message on checkout
2023-05-17 11:17:24 +01:00
Luigi Teschio 1b71b06b33 Product Search Results Template: fix compatibility layer when the Product Catalog is not blockified (https://github.com/woocommerce/woocommerce-blocks/pull/9492) 2023-05-17 10:10:58 +00:00
Alexandre Lara f22036af89 Fix Product Rating Block not showing when manually inserted to Single Product block (https://github.com/woocommerce/woocommerce-blocks/pull/9413) 2023-05-16 15:28:11 -03:00
Alexandre Lara 90573156fe Fix Product SKU not being displayed on frontend when outside Single Product template (https://github.com/woocommerce/woocommerce-blocks/pull/9446) 2023-05-16 15:25:34 -03:00
Luigi Teschio f8d46570ae Add isSiteEditorPage util (https://github.com/woocommerce/woocommerce-blocks/pull/9468)
* Add isSiteEditorPage util

* fix logic
2023-05-16 13:59:49 +02:00
Albert Juhé Lluveras 4c8baca475 Fix Filter by Price block making a 404 request in the frontend (https://github.com/woocommerce/woocommerce-blocks/pull/9481) 2023-05-16 12:05:24 +02:00
Luigi Teschio 150cde7d56 render Product Details block when it used along the Post Content block (https://github.com/woocommerce/woocommerce-blocks/pull/9479) 2023-05-16 11:31:13 +02:00
Manish Menaria 14f87be044 Product Collection: Add columns control to product collection block editor settings (https://github.com/woocommerce/woocommerce-blocks/pull/9466)
* 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.
2023-05-16 09:23:22 +00:00
Alba Rincón a24bf73c83 [Patterns] Improvements on `Product Collections: Featured Collection` (https://github.com/woocommerce/woocommerce-blocks/pull/9450)
* Hardcore text color

* Fix image margins
2023-05-16 11:06:04 +02: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
Patricia Hillebrandt 0bad9c81c9 Product Gallery Block > Remove global variable overwrite and keep support for the Single Product Block. (https://github.com/woocommerce/woocommerce-blocks/pull/9475)
* Remove call to the  global variable and add support for the gallery block to continue to work within the Single Product template without any problems.

* Make essential/required changes to guarantee the Product Gallery block works as expected without the relying on the global product.
2023-05-16 10:36:33 +02:00
Patricia Hillebrandt d26936bad7 Add to Cart with Options Block > Remove global variable overwrite. (https://github.com/woocommerce/woocommerce-blocks/pull/9457)
* Remove global variable overwrite from Add to Cart Form block.

* Rename single_product to product.
2023-05-16 10:18:36 +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
Manish Menaria 0e6141f5ed Foundation of New Product Collection Block (https://github.com/woocommerce/woocommerce-blocks/pull/9352)
* Add Products Collection block scaffolding

This commit adds the initial scaffolding for the new Products Collection block. It includes the creation of new files (block.json, edit.tsx, index.tsx and ProductsCollection.php) and additions to existing files (webpack-entries.js and BlockTypesController.php). The block is marked as experimental and currently displays a static "Product collection" text in both the editor and the frontend.

* Add Product Template block and integrate with Products Collection block

This commit introduces the new Product Template block and integrates it with the existing Products Collection block. The changes include:
- Creation of the Product Template block, including its block.json, edit.tsx, icon.tsx, index.tsx, and save.tsx files.
- Modification of the Products Collection block, adding an icon.tsx file and updating its edit.tsx and index.tsx files.
- Updates to the webpack-entries.js file to include the new Product Template block.
- Addition of the ProductTemplate class in the src/BlockTypes directory.
- Inclusion of the ProductTemplate class in the src/BlockTypesController.php file.

* Enhance product-template block with context and styling

This commit adds various enhancements to the product-template block. It includes:

- Introduce `usesContext` and `supports` properties to the block.json file
- Update the edit.tsx file to use BlockContextProvider and add query logic
- Add an editor.scss file for styling the product-template block in the editor
- Extend the products-collection block.json file with new properties
- Modify the products-collection edit.tsx file to include instanceId and useEffect

These changes improve the product-template block by providing better context handling and styling options.

* Add 'woocommerce/product-template' to supported inner blocks and improve product-template editing

This commit adds 'woocommerce/product-template' as a supported inner block for various product elements, including button, image, rating, sale-badge, SKU, and stock-indicator. It also improves the editing experience for the product-template block by memoizing the block previews and rendering them more efficiently. This should lead to a smoother editing experience and better performance in the block editor.

* Add product title and summary variations for Products Collection block

- Add default spacing between product elements in `style.scss`
- Register product title and summary element variations in `products-collection` block
- Create utility for registering element variations
- Extend core elements with WooCommerce namespace

* Set inherit to false by default and other improvements

This commit introduces several changes to the ProductsCollection block:
1. Set the "inherit" property to false in block.json, disabling inheritance by default.
2. Remove the default styles for inner blocks in the edit.tsx file.
3. Add a save function in the index.tsx file, and create a save.tsx file to handle saving the block.
4. Update the ProductTemplate.php file to properly render the block content based on the changes.
5. Remove the render function from the ProductsCollection.php file, as it is no longer necessary.

These changes improve the functionality and flexibility of the ProductsCollection block, allowing for better customization and control over the block's appearance and behavior.

* Fix pagination issue

* Minor code quality improvments

* Register product blocks only in experimental builds

- Wrap registerBlockType calls in product-template and products-collection with isExperimentalBuild check to enable block registration only in experimental builds.
- Update the default value for the perPage property in products-collection/block.json from null to 9, setting a default display of 9 items per page.

* Add experimental flag to PHP file

* Update documentation for feature flags

- Add Products Collection and Product Template blocks to the list of experimental flags in the feature-flags-and-experimental-interfaces.md file.
- Include references to PHP and webpack flags for both blocks.

* Change default order and orderBy values in block.json

- Update the default 'order' value from 'desc' to 'asc'.
- Update the default 'orderBy' value from 'date' to 'title'.

* Refactor experimental block registration and remove unused file

- Replace `isExperimentalBuild()` with `registerExperimentalBlockType()` in product-template/index.tsx.
- Remove unused file types.ts in product-template directory.
- Add `get_block_type_script()` function to ProductTemplate.php and ProductsCollection.php to return null.

* Update variation names in product summary and product title elements

Updated variation names for product summary and product title elements to match the new products-collection namespace. The previous variation names used the product-query namespace which will be deprecated. This change ensures that the correct variation names are used for these elements in the products-collection block.

* Rename 'Products Collection' to 'Product Collection'

- Renamed all instances of "products-collection" to "product-collection" across multiple files.
- Adjusted related types and method calls to match the new naming convention.
- Updated documentation and feature flags to reflect the name change.
- Made necessary changes in `BlockTypesController.php` and `bin/webpack-entries.js`.

* Hide product-template block from inserter

- Added "woocommerce/product-collection" to the list of parent blocks in `product-template/block.json`.
- Added `"inserter": false` to the "supports" section to disable the option of inserting this block through the editor inserter component.

* Fix Eslint error
2023-05-15 08:51:49 +00:00
Danilo Parra Jr 2a4b78c150 Update the logic of disabling some blocks in the widget areas and post editor (https://github.com/woocommerce/woocommerce-blocks/pull/9462)
* refactor: disable some blocks in widget areas and post editor

* refactor: add more checks on the disabling blocks logic
2023-05-15 08:36:06 +02:00
Daniel W. Robert 8621755f69 Update `Hero Product – Split` Pattern Color Settings (https://github.com/woocommerce/woocommerce-blocks/pull/9433)
* Update color settings to abide by designs.

* Update pattern heading to use inline style.

This ensures the heading color will be white by default and not take on
the heading color from the active theme.

* Translate and escape rendered text in pattern.
2023-05-12 11:00:16 -04:00
Roy Ho cd5490be6b Update/cleanup patterns (https://github.com/woocommerce/woocommerce-blocks/pull/9447)
* Update category cover image pattern

* Update featured category focus pattern

* Update featured category triple pattern

* Update product details pattern

* Update product hero pattern

* Update shop by price pattern

* Update testimonials single pattern
2023-05-12 06:05:36 -07: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