Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Product Query Block POC (Phase 1) #6812

Merged
merged 8 commits into from
Aug 18, 2022
Merged

Product Query Block POC (Phase 1) #6812

merged 8 commits into from
Aug 18, 2022

Conversation

gigitux
Copy link
Contributor

@gigitux gigitux commented Aug 2, 2022

Note
This PR implements Phase 1 of the Product Query block as described here.

The Product Query block is supposed to be the basis for all future blocks that will allow the merchants to select which products to show and how they are going to look. The block is based on creating a variation of the Gutenberg provided Query Loop block, and will have several WooCommerce-specific options.

Phase 1 is the first proof of concept, under an experimental flag, and will only be available within the experimental builds of the repo.

This PR introduces 3 main changes:

  1. On the Editor side, merchants will be able to select the Product Query directly from the inserter (icon TBD). This block is a variation of the Query Loop block and shows all the settings from that one, alongside the default inner blocks of title and image, which will work out of the box with WooCommerce. This block will furthermore show an additional setting to “Show only products on sale” to demonstrate a proof of concept of how adding settings on the sidebar will be possible.
  2. Still on the Editor side, another variation called “Products on Sale” will demonstrate how such settings can, not only be enabled by default on certain variations, but also be completely disabled and hidden from the users, as to create more specific and targeted blocks, which will require less effort from the users.
  3. On the front-end side, the block is fully SSR'ed and has support for custom, WooCommerce related, queries by hooking into a filter that we hope to merge into Gutenberg core as soon as possible. In order to use the changes on this PR, you will need to have a custom fork of Gutenberg installed.

In order to achieve all of these three things, we had to extend the attributes that can be passed to the Query Loop block with our own. The way we decided to design this new API is the following:

  1. We want to make sure those new attributes do not conflict with anything present and future, so we went ahead and namespaced everything under a double-underscore prefixed property name (__woocommerceVariationProps).
  2. We named it in such a way that this is not going to be limited to only this specific use-case, but that can be the way we extend all block variations from core in the future.
  3. We wanted to keep the API consistent with existing blocks and also predictable. So we decided that __woocommerceVariationProps will have the shape of any other BlockInstance, except for the fact that all the props are optional. This allows to have things such as names, version, supports and other things that might be useful in the future (for now, we mostly use the name, as variations can't otherwise have names that are readable at runtime to check if a variation itself is active). Inside of it, we have an attributes object which will contain any further custom attributes that we might add in the future, making it very flexible. All of this is fully typed, to make sure we make our interfaces clear.
Screen.Capture.on.2022-08-16.at.18-22-11.mp4

Testing

Warning
In order to use the changes on this PR, you will need to have a custom fork of Gutenberg installed.

  1. Create a post/page and add the Product Query block.
  2. Save it. On the front-end be sure that the products are rendered correctly.
  3. Edit the same post/page and enable the setting Show only products on sale.
  4. On the front-end be sure that only the on-sale products are rendered correctly.
  5. Create another post/page and add the Products on sale block.
  6. Save it. On the front end be sure that only the on-sale products are rendered correctly.

WooCommerce Visibility

  • WooCommerce Core
  • Feature plugin
  • Experimental

Changelog

Product Query block: added a first experimental proof of concept of a Product Query block.

@gigitux gigitux force-pushed the try/new-product-grid-demo branch from 8639605 to 169296f Compare August 2, 2022 08:19
@github-actions
Copy link
Contributor

github-actions bot commented Aug 2, 2022

The release ZIP for this PR is accessible via:

https://wcblocks.wpcomstaging.com/wp-content/uploads/woocommerce-gutenberg-products-block-6812.zip

@github-actions
Copy link
Contributor

github-actions bot commented Aug 2, 2022

Script Dependencies Report

The compare-assets action has detected some changed script dependencies between this branch and trunk. Please review and confirm the following are correct before merging.

Script Handle Added Removed
product-query.js wp-hooks, wp-polyfill ⚠️

This comment was automatically generated by the ./github/compare-assets action.

@github-actions
Copy link
Contributor

github-actions bot commented Aug 2, 2022

Script Dependencies Report

The compare-assets action has detected some changed script dependencies between this branch and trunk. Please review and confirm the following are correct before merging.

Script Handle Added Removed
reviews-frontend.js react, wc-settings, wp-a11y, wp-api-fetch, wp-compose, wp-element, wp-html-entities, wp-i18n, wp-is-shallow-equal, wp-polyfill ⚠️
all-products-frontend.js lodash, react, wc-blocks-data-store, wc-blocks-registry, wc-blocks-shared-context, wc-blocks-shared-hocs, wc-price-format, wc-settings, wp-a11y, wp-api-fetch, wp-autop, wp-block-editor, wp-blocks, wp-compose, wp-data, wp-deprecated, wp-dom, wp-element, wp-hooks, wp-html-entities, wp-i18n, wp-is-shallow-equal, wp-polyfill, wp-primitives, wp-url, wp-warning, wp-wordcount ⚠️
price-filter-frontend.js lodash, react, wc-blocks-data-store, wc-price-format, wc-settings, wp-data, wp-element, wp-i18n, wp-is-shallow-equal, wp-polyfill, wp-url ⚠️
attribute-filter-frontend.js lodash, react, wc-blocks-data-store, wc-settings, wp-a11y, wp-block-editor, wp-blocks, wp-compose, wp-data, wp-deprecated, wp-dom, wp-element, wp-html-entities, wp-i18n, wp-is-shallow-equal, wp-keycodes, wp-polyfill, wp-primitives, wp-url, wp-warning ⚠️
stock-filter-frontend.js lodash, react, wc-blocks-data-store, wc-settings, wp-a11y, wp-data, wp-element, wp-html-entities, wp-i18n, wp-is-shallow-equal, wp-polyfill, wp-url ⚠️
active-filters-frontend.js lodash, react, wc-blocks-data-store, wc-price-format, wc-settings, wp-data, wp-element, wp-html-entities, wp-i18n, wp-is-shallow-equal, wp-polyfill, wp-primitives, wp-url ⚠️
cart-frontend.js lodash, react, wc-blocks-checkout, wc-blocks-data-store, wc-blocks-registry, wc-blocks-shared-hocs, wc-price-format, wc-settings, wp-a11y, wp-api-fetch, wp-autop, wp-compose, wp-data, wp-deprecated, wp-dom, wp-element, wp-hooks, wp-html-entities, wp-i18n, wp-is-shallow-equal, wp-keycodes, wp-plugins, wp-polyfill, wp-primitives, wp-url, wp-warning, wp-wordcount ⚠️
checkout-frontend.js lodash, react, wc-blocks-checkout, wc-blocks-data-store, wc-blocks-registry, wc-blocks-shared-hocs, wc-price-format, wc-settings, wp-a11y, wp-api-fetch, wp-autop, wp-compose, wp-data, wp-deprecated, wp-dom, wp-element, wp-hooks, wp-html-entities, wp-i18n, wp-is-shallow-equal, wp-keycodes, wp-plugins, wp-polyfill, wp-primitives, wp-url, wp-warning, wp-wordcount ⚠️
mini-cart-frontend.js wc-settings, wp-polyfill ⚠️
single-product-frontend.js lodash, react, wc-blocks-checkout, wc-blocks-data-store, wc-blocks-registry, wc-blocks-shared-context, wc-blocks-shared-hocs, wc-price-format, wc-settings, wp-a11y, wp-api-fetch, wp-autop, wp-block-editor, wp-blocks, wp-compose, wp-data, wp-deprecated, wp-dom, wp-element, wp-hooks, wp-html-entities, wp-i18n, wp-is-shallow-equal, wp-polyfill, wp-primitives, wp-url, wp-warning, wp-wordcount ⚠️
mini-cart-component-frontend.js lodash, react, wc-blocks-checkout, wc-blocks-data-store, wc-blocks-registry, wc-price-format, wc-settings, wp-a11y, wp-autop, wp-components, wp-compose, wp-data, wp-deprecated, wp-dom, wp-element, wp-hooks, wp-html-entities, wp-i18n, wp-is-shallow-equal, wp-keycodes, wp-polyfill, wp-primitives, wp-url, wp-warning, wp-wordcount ⚠️

This comment was automatically generated by the ./github/compare-assets action.

@github-actions
Copy link
Contributor

github-actions bot commented Aug 2, 2022

Size Change: -102 B (0%)

Total Size: 867 kB

Filename Size Change
build/active-filters-frontend.js 7.33 kB +10 B (0%)
build/all-products-frontend.js 18.1 kB -14 B (0%)
build/all-products.js 33.7 kB +1 B (0%)
build/all-reviews.js 7.8 kB +6 B (0%)
build/attribute-filter-frontend.js 21.9 kB +9 B (0%)
build/attribute-filter.js 12.9 kB +13 B (0%)
build/cart-blocks/cart-accepted-payment-methods-frontend.js 1.16 kB +1 B (0%)
build/cart-blocks/cart-express-payment-frontend.js 5.1 kB +6 B (0%)
build/cart-blocks/cart-items-frontend.js 298 B -1 B (0%)
build/cart-blocks/cart-line-items--mini-cart-contents-block/products-table-frontend.js 5.27 kB -2 B (0%)
build/cart-blocks/empty-cart-frontend.js 345 B -2 B (-1%)
build/cart-blocks/filled-cart-frontend.js 781 B -1 B (0%)
build/cart-blocks/order-summary-heading-frontend.js 455 B -1 B (0%)
build/cart-blocks/order-summary-shipping--checkout-blocks/order-summary-shipping-frontend.js 6.37 kB -1 B (0%)
build/cart-blocks/order-summary-shipping-frontend.js 425 B -1 B (0%)
build/cart.js 41.3 kB -15 B (0%)
build/checkout-blocks/actions-frontend.js 1.42 kB +4 B (0%)
build/checkout-blocks/billing-address--checkout-blocks/shipping-address-frontend.js 4.12 kB +2 B (0%)
build/checkout-blocks/billing-address-frontend.js 891 B -1 B (0%)
build/checkout-blocks/contact-information-frontend.js 2.84 kB -1 B (0%)
build/checkout-blocks/express-payment-frontend.js 5.39 kB +6 B (0%)
build/checkout-blocks/fields-frontend.js 344 B -1 B (0%)
build/checkout-blocks/order-note-frontend.js 1.08 kB -1 B (0%)
build/checkout-blocks/order-summary-cart-items-frontend.js 3.66 kB -1 B (0%)
build/checkout-blocks/order-summary-coupon-form-frontend.js 2.8 kB +2 B (0%)
build/checkout-blocks/order-summary-discount-frontend.js 2.27 kB -1 B (0%)
build/checkout-blocks/order-summary-shipping-frontend.js 601 B -1 B (0%)
build/checkout-blocks/order-summary-taxes-frontend.js 433 B +1 B (0%)
build/checkout-blocks/payment-frontend.js 7.7 kB +5 B (0%)
build/checkout-blocks/shipping-address-frontend.js 1.03 kB -2 B (0%)
build/checkout-blocks/shipping-methods-frontend.js 4.75 kB +1 B (0%)
build/checkout-blocks/terms-frontend.js 1.23 kB -2 B (0%)
build/checkout.js 42.6 kB -17 B (0%)
build/featured-category.js 13.2 kB +11 B (0%)
build/featured-product.js 13.5 kB +6 B (0%)
build/handpicked-products.js 7.37 kB +2 B (0%)
build/legacy-template.js 2.79 kB -4 B (0%)
build/mini-cart-component-frontend.js 16.8 kB -1 B (0%)
build/mini-cart-contents-block/footer-frontend.js 6.99 kB +8 B (0%)
build/mini-cart-contents.js 22.9 kB -10 B (0%)
build/price-filter-frontend.js 13.2 kB +127 B (+1%)
build/price-filter.js 9.09 kB +82 B (+1%)
build/product-add-to-cart-frontend.js 6.96 kB +2 B (0%)
build/product-add-to-cart.js 6.88 kB -3 B (0%)
build/product-best-sellers.js 7.71 kB +2 B (0%)
build/product-button--product-image--product-rating--product-sale-badge--product-title.js 300 B -2 B (-1%)
build/product-button-frontend.js 1.88 kB +3 B (0%)
build/product-button.js 1.57 kB -2 B (0%)
build/product-category-list-frontend.js 881 B +2 B (0%)
build/product-category-list.js 504 B +1 B (0%)
build/product-category.js 8.68 kB -1 B (0%)
build/product-image-frontend.js 1.88 kB +1 B (0%)
build/product-image.js 1.59 kB -2 B (0%)
build/product-new.js 7.71 kB +1 B (0%)
build/product-on-sale.js 8.02 kB +1 B (0%)
build/product-price.js 1.51 kB +2 B (0%)
build/product-rating-frontend.js 1.17 kB +2 B (0%)
build/product-rating.js 742 B +1 B (0%)
build/product-sale-badge-frontend.js 1.13 kB +2 B (0%)
build/product-sale-badge.js 803 B +1 B (0%)
build/product-search.js 2.18 kB -1 B (0%)
build/product-stock-indicator-frontend.js 995 B +2 B (0%)
build/product-stock-indicator.js 625 B +1 B (0%)
build/product-summary-frontend.js 1.29 kB +1 B (0%)
build/product-tag-list-frontend.js 876 B +3 B (0%)
build/product-tag-list.js 500 B +1 B (0%)
build/product-tag.js 8.08 kB -2 B (0%)
build/product-title-frontend.js 1.31 kB +1 B (0%)
build/product-top-rated.js 7.95 kB +3 B (0%)
build/products-by-attribute.js 8.63 kB -1 B (0%)
build/reviews-by-category.js 11.2 kB +3 B (0%)
build/reviews-by-product.js 12.3 kB +6 B (0%)
build/reviews-frontend.js 7.02 kB +2 B (0%)
build/single-product-frontend.js 21.4 kB -4 B (0%)
build/single-product.js 10 kB +6 B (0%)
build/stock-filter-frontend.js 7.39 kB +13 B (0%)
build/stock-filter.js 7.3 kB +15 B (0%)
build/vendors--cart-blocks/order-summary-shipping--checkout-blocks/billing-address--checkout-blocks/order--decc3dc6-frontend.js 19.1 kB +1 B (0%)
build/vendors--product-add-to-cart-frontend.js 7.53 kB -1 B (0%)
build/wc-blocks-editor-style-rtl.css 5.07 kB +28 B (+1%)
build/wc-blocks-editor-style.css 5.07 kB +29 B (+1%)
build/wc-blocks-style-rtl.css 22.2 kB -543 B (-2%)
build/wc-blocks-style.css 22.2 kB -543 B (-2%)
build/wc-blocks-vendors.js 54.5 kB -2 B (0%)
build/product-query.js 647 B +647 B (new file) 🆕
ℹ️ View Unchanged
Filename Size
build/active-filters.js 7.99 kB
build/blocks-checkout.js 17.4 kB
build/cart-blocks/cart-line-items-frontend.js 430 B
build/cart-blocks/cart-order-summary-frontend.js 1.1 kB
build/cart-blocks/cart-totals-frontend.js 321 B
build/cart-blocks/order-summary-coupon-form-frontend.js 2.65 kB
build/cart-blocks/order-summary-discount-frontend.js 2.14 kB
build/cart-blocks/order-summary-fee-frontend.js 273 B
build/cart-blocks/order-summary-subtotal-frontend.js 274 B
build/cart-blocks/order-summary-taxes-frontend.js 433 B
build/cart-blocks/proceed-to-checkout-frontend.js 1.15 kB
build/cart-frontend.js 47 kB
build/checkout-blocks/order-summary-fee-frontend.js 276 B
build/checkout-blocks/order-summary-frontend.js 1.1 kB
build/checkout-blocks/order-summary-subtotal-frontend.js 274 B
build/checkout-blocks/totals-frontend.js 325 B
build/checkout-frontend.js 49.2 kB
build/general-style-rtl.css 1.29 kB
build/general-style.css 1.29 kB
build/mini-cart-contents-block/empty-cart-frontend.js 365 B
build/mini-cart-contents-block/filled-cart-frontend.js 229 B
build/mini-cart-contents-block/footer--mini-cart-contents-block/products-table-frontend.js 4.69 kB
build/mini-cart-contents-block/items-frontend.js 237 B
build/mini-cart-contents-block/products-table-frontend.js 289 B
build/mini-cart-contents-block/shopping-button-frontend.js 288 B
build/mini-cart-contents-block/title-frontend.js 367 B
build/mini-cart-frontend.js 1.72 kB
build/mini-cart.js 4.58 kB
build/price-format.js 1.19 kB
build/product-add-to-cart--product-button--product-category-list--product-image--product-price--product-r--a0326d00.js 223 B
build/product-add-to-cart--product-button--product-image--product-title.js 2.66 kB
build/product-button--product-category-list--product-image--product-price--product-rating--product-sale-b--e17c7c01.js 436 B
build/product-categories.js 2.41 kB
build/product-price-frontend.js 1.9 kB
build/product-sku-frontend.js 380 B
build/product-sku.js 381 B
build/product-summary.js 922 B
build/product-title.js 921 B
build/vendors--cart-blocks/cart-line-items--cart-blocks/cart-order-summary--cart-blocks/order-summary-shi--c02aad66-frontend.js 5.26 kB
build/vendors--cart-blocks/cart-line-items--checkout-blocks/order-summary-cart-items--mini-cart-contents---233ab542-frontend.js 3.14 kB
build/vendors--cart-blocks/order-summary-shipping--checkout-blocks/billing-address--checkout-blocks/order--5b8feb0b-frontend.js 4.85 kB
build/vendors--mini-cart-contents-block/footer-frontend.js 6.86 kB
build/wc-blocks-data.js 9.87 kB
build/wc-blocks-google-analytics.js 1.56 kB
build/wc-blocks-middleware.js 930 B
build/wc-blocks-registry.js 2.7 kB
build/wc-blocks-shared-context.js 1.52 kB
build/wc-blocks-shared-hocs.js 1.14 kB
build/wc-blocks-vendors-style-rtl.css 1.95 kB
build/wc-blocks-vendors-style.css 1.95 kB
build/wc-blocks.js 2.63 kB
build/wc-payment-method-bacs.js 816 B
build/wc-payment-method-cheque.js 811 B
build/wc-payment-method-cod.js 909 B
build/wc-payment-method-paypal.js 837 B
build/wc-settings.js 2.6 kB

compressed-size-action

@gigitux gigitux force-pushed the try/new-product-grid-demo branch from 169296f to b9f23a0 Compare August 2, 2022 08:41
@github-actions
Copy link
Contributor

github-actions bot commented Aug 2, 2022

Script Dependencies Report

The compare-assets action has detected some changed script dependencies between this branch and trunk. Please review and confirm the following are correct before merging.

Script Handle Added Removed
product-query.js wp-block-editor, wp-blocks, wp-components, wp-compose, wp-element, wp-hooks, wp-i18n, wp-polyfill, wp-primitives ⚠️

This comment was automatically generated by the ./github/compare-assets action.

@gigitux gigitux force-pushed the try/new-product-grid-demo branch from b9f23a0 to 014a16c Compare August 2, 2022 08:50
@github-actions
Copy link
Contributor

github-actions bot commented Aug 2, 2022

Script Dependencies Report

The compare-assets action has detected some changed script dependencies between this branch and trunk. Please review and confirm the following are correct before merging.

Script Handle Added Removed
product-query.js wp-block-editor, wp-blocks, wp-components, wp-compose, wp-element, wp-hooks, wp-i18n, wp-polyfill, wp-primitives ⚠️

This comment was automatically generated by the ./github/compare-assets action.

2 similar comments
@github-actions
Copy link
Contributor

github-actions bot commented Aug 3, 2022

Script Dependencies Report

The compare-assets action has detected some changed script dependencies between this branch and trunk. Please review and confirm the following are correct before merging.

Script Handle Added Removed
product-query.js wp-block-editor, wp-blocks, wp-components, wp-compose, wp-element, wp-hooks, wp-i18n, wp-polyfill, wp-primitives ⚠️

This comment was automatically generated by the ./github/compare-assets action.

@github-actions
Copy link
Contributor

github-actions bot commented Aug 3, 2022

Script Dependencies Report

The compare-assets action has detected some changed script dependencies between this branch and trunk. Please review and confirm the following are correct before merging.

Script Handle Added Removed
product-query.js wp-block-editor, wp-blocks, wp-components, wp-compose, wp-element, wp-hooks, wp-i18n, wp-polyfill, wp-primitives ⚠️

This comment was automatically generated by the ./github/compare-assets action.

@github-actions
Copy link
Contributor

github-actions bot commented Aug 5, 2022

Import from @wordpress/element

Import from @wordpress/element


import { ElementType } from 'react'; // TODO: Import from @wordpress/element
/**
* Internal dependencies
*/
import { ProductQueryBlock } from './types';
import { isWooQueryBlockVariation, setCustomQueryAttribute } from './utils';
export const INSPECTOR_CONTROLS = {
onSale: ( props: ProductQueryBlock ) => (
<ToggleControl
label={ __(

🚀 This comment was generated by the automations bot based on a todo comment in d7344dd in #6812. cc @gigitux

@github-actions
Copy link
Contributor

github-actions bot commented Aug 5, 2022

Script Dependencies Report

The compare-assets action has detected some changed script dependencies between this branch and trunk. Please review and confirm the following are correct before merging.

Script Handle Added Removed
product-query.js wp-hooks, wp-polyfill ⚠️

This comment was automatically generated by the ./github/compare-assets action.

@gigitux gigitux force-pushed the try/new-product-grid-demo branch 5 times, most recently from 543bf24 to 91739d9 Compare August 16, 2022 16:42
sunyatasattva and others added 7 commits August 16, 2022 19:10
`EditorBlock` was scoped under the `featured-items` directory at the time of its creation. It is, however, a useful type that should be shared repo-wide. For this reason, I am moving it into the `blocks` type-defs and updating all the references.
Also defines a more generic `WooCommerceBlockVariation` type which should be also useful in the future to implement a similar pattern.
Add two utility functions:

 1. `isWooQueryBlockVariation`: is used to check whether a given block is a variation of the core Query Loop block, and also one of the allowed variations within our repo. See: `QueryVariation` enum type.
2. `setCustomQueryAttribute`: is a shorthand to set an attribute within the variation query attribute.
Specifically:

1. Creates a `constant.ts` file to store all shared constants. Currently, the default variation attributes.
2. Move the variations to their own directory. One file per variation.
3. Move the inspector controls into own file and create a conditional logic to allow showing only certain settings.
We had changed the Products on Sale variation slug to something else,
but we had forgotten to update the proper enum.
@sunyatasattva sunyatasattva force-pushed the try/new-product-grid-demo branch from 91739d9 to 4ffd40a Compare August 16, 2022 17:15
@sunyatasattva sunyatasattva changed the title POC: Product Query Product Query Block POC (Phase 1) Aug 16, 2022
@sunyatasattva sunyatasattva added type: enhancement The issue is a request for an enhancement. block-type: product-grid Issues related to/affecting all product-grid type blocks. labels Aug 16, 2022
@sunyatasattva sunyatasattva marked this pull request as ready for review August 16, 2022 21:54
@rubikuserbot rubikuserbot requested review from a team and albarin and removed request for a team August 16, 2022 21:56
The filter we added to Gutenberg will pass the block and the page,
as we might need them in the future and we want to minimize the
amount of changes we'll have to do upstream.

However, we currently do not use those, so I removed
them from our own inner function.
@albarin
Copy link
Contributor

albarin commented Aug 17, 2022

I've tested and the only thing I've found is that when you use Product Query with Show only products on sale or Products on sale what you see on the edit page does not match what the frontend renders. Maybe this is expected on this PoC, but mentioning it just in case:

Screen.Capture.on.2022-08-17.at.12-07-41.mp4

@gigitux
Copy link
Contributor Author

gigitux commented Aug 18, 2022

Thanks for testing this PR, @albarin! Glad that you didn't find any issues :D
Regarding no live preview on the edit page, it is expected 👍

@github-actions github-actions bot added this to the 8.4.0 milestone Aug 18, 2022
@gigitux gigitux merged commit 7757b85 into trunk Aug 18, 2022
@gigitux gigitux deleted the try/new-product-grid-demo branch August 18, 2022 08:02
@gigitux gigitux added the skip-changelog PRs that you don't want to appear in the changelog. label Aug 18, 2022
senadir pushed a commit to senadir/woocommerce-blocks that referenced this pull request Aug 18, 2022
* Move `EditorBlock` to general `type-defs`

`EditorBlock` was scoped under the `featured-items` directory at the time of its creation. It is, however, a useful type that should be shared repo-wide. For this reason, I am moving it into the `blocks` type-defs and updating all the references.

* Define types for the Product Query block

Also defines a more generic `WooCommerceBlockVariation` type which should be also useful in the future to implement a similar pattern.

* Add Product Query utils

Add two utility functions:

 1. `isWooQueryBlockVariation`: is used to check whether a given block is a variation of the core Query Loop block, and also one of the allowed variations within our repo. See: `QueryVariation` enum type.
2. `setCustomQueryAttribute`: is a shorthand to set an attribute within the variation query attribute.

* Refactor and cleanup the JS demo code

Specifically:

1. Creates a `constant.ts` file to store all shared constants. Currently, the default variation attributes.
2. Move the variations to their own directory. One file per variation.
3. Move the inspector controls into own file and create a conditional logic to allow showing only certain settings.

* Update webpack config

* Add ProductQuery class

* Fix `QueryVariation` enum

We had changed the Products on Sale variation slug to something else,
but we had forgotten to update the proper enum.

* Remove unused params from `update_query`

The filter we added to Gutenberg will pass the block and the page,
as we might need them in the future and we want to minimize the
amount of changes we'll have to do upstream.

However, we currently do not use those, so I removed
them from our own inner function.

Co-authored-by: Lucio Giannotta <lucio.giannotta@a8c.com>
@nerrad
Copy link
Contributor

nerrad commented Aug 19, 2022

@gigitux or @sunyatasattva, where is(are) the relevant PR(s) for the GB fork mentioned in this pull request? I recall someone sharing the PR link with me at some point but I've spent a few minutes trying to find it and I can't. If you could add it to the description in this PR to link the two together that'd be great!

Also, it doesn't look like this PR was attached to the current Zenhub sprint, and Epic (no estimate either). Was that intentional?

@gigitux
Copy link
Contributor Author

gigitux commented Aug 22, 2022

@gigitux or @sunyatasattva, where is(are) the relevant PR(s) for the GB fork mentioned in this pull request? I recall someone sharing the PR link with me at some point but I've spent a few minutes trying to find it and I can't. If you could add it to the description in this PR to link the two together that'd be great!

We didn't create any PR. We linked the branch that we have created. In any case, we can create it! @sunyatasattva can you take care of this? I don't have permission to create the PR.

Also, it doesn't look like this PR was attached to the current Zenhub sprint, and Epic (no estimate either). Was that intentional?

Good point! I forgot to attach it to the current sprint. I'm going to update it! Thanks for catching it!

@nerrad
Copy link
Contributor

nerrad commented Aug 22, 2022

We didn't create any PR.

Why not? Even if it's created as a draft, it can help with discussion around implementation for this use case. Code freeze for WP 6.1 will be coming soon, so it's important to surface API needs and begin these discussions early. Of course, it's possible I'm missing context around why the PR hasn't been created yet 😄

@sunyatasattva
Copy link
Contributor

Yep, I'm taking care of the Gutenberg side of things. @nerrad The PR wasn't created yet as I am exploring the side-effects of our decisions. As a matter of fact, I have already found a pretty significant bug with our implementation. I thought it might have been blocking (as in, we needed to rethink the approach on the Gutenberg change a bit), but actually I managed to come up with a fix (PR coming soon), although I'm not too happy with that.

The PR for this change doesn't worry me much, as we had already discussed it with the Gutenberg team and it's literally 1 LOC. I'll publish it as soon as I finish my in-depth exploration.

The other PR which is required for us is going to be more interesting and will need to start as a draft. I have already got something and will publish that ASAP to start the discussion as you have mentioned.

@sunyatasattva
Copy link
Contributor

More info here: #6952

This is the only problem I have encountered with our approach of adding the filter there. The solution I've found doesn't sit with me really well, so if there are alternative suggestions, I'm glad to hear about them. Otherwise, we'll have to accept the trade-off and I'll open the first PR on Gutenberg as soon as we agree about this.

cc @nerrad @gigitux

@ntsekouras
Copy link

This is related to this GB issue and I think it would be good to have a consistent way of Query Loop extenders to do some things.

I've just created: WordPress/gutenberg#43632 to start some discussions. Do you think something like that in core would simplify extending the block?

@nerrad
Copy link
Contributor

nerrad commented Aug 30, 2022

Nik, I'm really liking the direction of your PR to address the issue. I've left a comment in the PR. @gigitux and @sunyatasattva it'd be good to test & provide feedback on Nik's PR.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
block-type: product-grid Issues related to/affecting all product-grid type blocks. skip-changelog PRs that you don't want to appear in the changelog. type: enhancement The issue is a request for an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants