* Update data store docs
* Link related docs to /docs/third-party-developers/extensibility/data-store
* Improve data store overview
* Remove obsolete entry
* Update TOC of docs/third-party-developers/extensibility/data-store/store-notices.md
* Update TOCs
* Update link titles
* Replace primary key with import statement
* Optimise Validation Store description
* Keep store IDs in title
* Correct wrong key
* Optimise data store docs overview
* Explain the difference between cart and checkout store
* Add example to Validation Store
* Add example to Validation Store
* Add overview text to collections.md
* Add example to store-notices.md
* Update TOC of store-notices.md
* Update overview description of store-notices.md
* Add code snippets for displaying the validationError message
* Update data store docs
* Link related docs to /docs/third-party-developers/extensibility/data-store
* Improve data store overview
* Remove obsolete entry
* Update TOC of docs/third-party-developers/extensibility/data-store/store-notices.md
* Update TOCs
* Update link titles
* Replace primary key with import statement
* Optimise Validation Store description
* Keep store IDs in title
* Correct wrong key
* Optimise data store docs overview
* Explain the difference between cart and checkout store
* Add example to Validation Store
* Add example to Validation Store
* Add overview text to collections.md
* Add example to store-notices.md
* Update TOC of store-notices.md
* Update overview description of store-notices.md
* Add code snippets for displaying the validationError message
* Mention full link in assets/js/data/cart/README.md
* Changed Store-Notices to Store Notices
* Display shipping calculator when formatted address is present
- Earlier, shipping calculator was getting displayed based on the isAddressComplete value.
- For the scenarios where address was incomplete but formatted address was present shipping calculator was not getting displayed.
- This made shipping calculator not getting displayed for guest shoppers.
- With this, conditions are changed from isAddressComplete to formatShippingAddress to display shipping calculator if formatted address is present.
- Add unit test case for the condition for formatted address.
* Update comments to explain the condition to hide shipping calculator
- Update the comments to add the reason to hide shipping calculator.
- When there is no default customer location in the store and the customer has not entered their address, but there is a default shipping method available for all locations, then we will hide the shipping calculator.
* Remove authors filter from Product Collection block
* Remove author filed in query
* Add back the author query argument in the final query builder
---------
Co-authored-by: Manish Menaria <the.manish.menaria@gmail.com>
- Earlier, shipping calculator was getting displayed based on the isAddressComplete value.
- For the scenarios where address was incomplete but formatted address was present shipping calculator was not getting displayed.
- This made shipping calculator not getting displayed for guest shoppers.
- With this, conditions are changed from isAddressComplete to formatShippingAddress to display shipping calculator if formatted address is present.
- Add unit test case for the condition for formatted address.
* Add Toggle to inspector controls allowing shrinking number of columns
* Add logic to allow columns to shrink in Product Collection
* Rename SCSS variable
* Make sure the value provided to component is a boolean
* Rename onChange callback name to better reflect its purpose
* Add slide animation
* Remove placeholder and pagination (https://github.com/woocommerce/woocommerce-blocks/pull/11145)
* Add titles to patterns and set the aligment to Wide
* Replace product query patterns with product collection ones
* Remove pagination and no results query from product query patterns
* Add aspect ratio to the product image attributes
* Add portrait aspect ratio to product X column and product gallery patterns
* improve animation
* improve naming
* fix regression
* fix css
* improve code style
* remove check on tag image
* align image
* fix crash when zoom is disabled
* fix E2E tests
* improve CSS
---------
Co-authored-by: Alba Rincón <albarin@users.noreply.github.com>
* Add transforms for checkout block
* Block to shortcode switcher in notice
* cart transforms
* Fix target block for switching
* Remove switcher UI for classic cart/checkout
* Set isPreview when generating block preview in switcher
* Onboarding task
* Action on click
* Focus on block after replacement
* Update notice styling and wording
* Undo functionality
* Look for woocommerce/classic-shortcode when determining if task list item should display
* Enable focus on the cart/checkout block when visiting from the task list
* Classic Cart/Checkout Updated Title
* Add missing translations
* Refactor modal content to avoid sprintf
* Improve pickBlockClientId
* Tracks events for switching to classic shortcode block
* TaskList support for non-block themes
* Updated placeholder to work on non-white page backgrounds
* Find blocks using findBlock utility
* Add TabbableContainer for buttons
* Add align to wrapper
* Update modal content
* Update modal usage
* Removed undo link when converting from classic shortcode
* Check if block was selected
* Revert "Removed undo link when converting from classic shortcode"
This reverts commit 2babbab4c1e69861a0371ff745e85d80ff6bbab1.
* update snackbar text
* Remove block level options in favour of settings
* Remove calculator toggle test
* Update assets/js/blocks/cart/inner-blocks/cart-order-summary-shipping/block.tsx
Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>
* Remove unused attributes
---------
Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>
This commit addresses an issue where layout attributes could become undefined during the block migration process. Alongside this fix, several updates were made to align the migration logic with the new `ProductCollectionDisplayLayout` types:
- Added logic to handle `undefined` layout attributes, defaulting to `DEFAULT_ATTRIBUTES.displayLayout`.
- Removed `ProductGridLayout` and `ProductGridLayoutTypes` from the types file.
- Imported `LayoutOptions` and `ProductCollectionDisplayLayout` from the product-collection module.
- Updated the `mapLayoutType` and `mapLayoutPropertiesFrom...` functions to use the new layout types.
- Updated transformation functions like `transformProductTemplate` and `transformPostSummary` to use the new types.
These changes not only resolve the issue with undefined layout attributes but also align the codebase with the new layout options, enhancing code maintainability.
* Add titles to patterns and set the aligment to Wide
* Replace product query patterns with product collection ones
* Remove pagination and no results query from product query patterns
* Add aspect ratio to the product image attributes
* Add portrait aspect ratio to product X column and product gallery patterns
* Adkust text of sidebar notice
* Adjust text of sidebar notice
* Rename folder to “incompatible-extension-notice”
* Rename main component and interface
* Rename constants
* Add new files for splitting logic
* WIP: Semi-hardcoded solution
* WIP: Add new data store
* Fetch incompatible extensions dynamically
* Fix broken dismiss notice functionality
* Minor refactor
* Remove data store
* Remove console.log
* Remove obsolete data store fragment
* Update package-lock.json and composer.lock
* Change wording from “might be” to “may be”
* Show single incompatible extension within notice instead of as list
* Fix *.md linting error
* Remove data attributes from being saved in html of All products block
* added old save in deprecated
* Addressed review comments
---------
Co-authored-by: Tung Du <dinhtungdu@gmail.com>
Co-authored-by: Roy Ho <roykho77@gmail.com>
* Add condition to register blocks and variation in single product template
* Improve the fix by providing default ancestor value to block registered for single product
* add E2E test
* add insert block
---------
Co-authored-by: Luigi Teschio <gigitux@gmail.com>
* Product Gallery: Fix conflicts between block settings and CSS
* Product Gallery: Final CSS polishes
* Product Gallery: Minor CSS refactor
* Product Gallery: Revert the minor css refactor
* add custom class on the main div
* Product Gallery: Combine inner block styles and optimize them
* Product Gallery Inner Blocks: Remove imports to no longer existing stylesheet files
* Product Gallery: Change all references from wp-block to wc-block
* Product Gallery Inner Blocks: Remove loading of non-existent inner blocks stylesheet files
* Product Gallery: Add additional class to ensure correct width for single product gallery despite of the Next/Previous mode selected
* Product Gallery: Add final polishing
* fix zoom
* Product Gallery Thumbnails: Fix css
* Product Gallery Large Image Next Previous Buttons: Skip failing tests
---------
Co-authored-by: Luigi <gigitux@gmail.com>
* Upgrade terser-webpack-plugin to version 4.2.3
* Upgrade webpack-bundle-analyzer to 4.7.0
* Upgrade to Webpack version 5
* Upgrade @wordpress/dependency-extraction-webpack-plugin to 4.6.0
* Upgrade dependency copy-webpack-plugin to version 11.0.0
* Upgrade dependency terser-webpack-plugin to version 5.3.6
* Replace webpack-rtl-plugin with the new @automattic/webpack-rtl-plugin
* Replace module.issuer with the new ModuleGraph API
There is a warning appearing in the console when running the application. This is due to the fact that the module.issuer has been deprecated on Webpack 5 and replaced with the new ModuleGraph API. This commit replaces the deprecated API with the new one.
* Upgrade babel and babel plugins to latest version
* Replace jsonpFunction with the new uniqueName property
Add a unique name of the webpack build to avoid multiple webpack runtimes to conflict when using globals. It defaults to output.library name or the package name from package.json in the context, if both aren't found, it is set to an ''.
* Replace cacheDirectory inline configuration with options.cacheDirectory
* Upgrade @wordpress/e2e-tests dependency to version 5.6.0
* Remove babel-plugin-transform-react-jsx dependency
Remove babel-plugin-transform-react-jsx dependency because it is already included in @wordpress/babel-preset-default
* Remove unnecessary Babel dependencies
Remove some unnecessary babel dependencies that are already included in the @babel/preset-env package.
* Upgrade puppeteer dependency to version 16.2.0
* Remove caret from package.json dependencies
* Fix Storybook build error
This commit fixes the Storybook build error that was being caused because of Storybook by default uses Webpack 4, but since we are currently upgrading our webpack to version 5, we need to install some required dependencies and also explicitly tell Storybook to use Webpack 5.
* Fix package-lock.json after merging with trunk
* Add own webpack-rtl-plugin implementation to the project
Before upgrading Webpack to version 5, we were using the original `webpack-rtl-plugin` released by Romain Berger; unfortunately, this plugin is not compatible with Webpack 5, so we replaced it with `@automattic/webpack-rtl-plugin`. The problem is that `@automattic/webpack-rtl-plugin` by default generates files with the '.rtl.css' suffix and does not provide a way to change that.
This commit adds our own implementation of the `webpack-rtl-plugin` (adapted from `@automattic/webpack-rtl-plugin`) that is compatible with Webpack 5 and allows us to change the suffix of the generated files to follow the recommended way defined by Wordpress (https://codex.wordpress.org/Right-to-Left_Language_Support)
* Change conditional clause to be multiline
* Fix package-lock.json after merge with trunk
* Fix package-lock.json after merge with trunk
* Rename files to fix ESLint errors
This commit renames files that have the .js extension but contain JSX code. This is causing ESLint to throw errors because by default our Eslint configuration expects only files with the .jsx extension to contain JSX code.
* Fix package-lock.json file
* Add is-plain-obj module to the transformIgnorePatterns of jest config
* Update package-lock.json
* Fix package-lock.json
* Upgrade @wordpress/i18n dependency to version 4.31.0
* Update package-lock.json
* Update composer lock file
* Fix Webpack config for Webpack 5
* Add the package-lock.json
* Remove unsupported config from webpack
* Fix error with Webpack build
* Add wait for network idle to the tests
* Attempt to fix e2e test
* Restore promise.all
* Upgrade puppeteer to v17.1.3
* Upgrade expect-puppeteer
* Update expect-puppeteer
* Downgrade expect-puppeteer
* Revert "Upgrade puppeteer to v17.1.3"
This reverts commit 61ed52a56f131961f3970b6fb22cdd8b540bada3.
* Upgrade Puppeteer to version 17.1.3
* Fix executionContext.frame is not a function error
* Fix e2e tests
* Remove isExperimentalBuild from Product Gallery inner blocks
* Upgrade Webpack and Webpack-cli to latest version
* Upgrade postcss and mini-css plugins
* Fix error with mini-cart block
* Fix styling error with filter blocks
* Fix issue when running unit tests
* Fix storybook script not loading
* Fix a11y issue in Storybook
* Fix error when multiple isExperimentalBuild was being used
* Prevent error when layout is not present in the attributes object
* Update `chunkIds` to `named` in Webpack
* Add cache groups to the Webpack configs
* Main block types for confirmation
* Initial blocks
* Styling and placeholders
* Make blocks experimental
* Update summary icon
* Add name/description for status block and missing text descriptions in the block.
Closeswoocommerce/woocommerce-blocks#10057
* Order confirmation: Convert Order Details Templates to Blocks (https://github.com/woocommerce/woocommerce-blocks/pull/10095)
* Move code from templates into the details block
* Details -> Totals
* Downloads block
* Sample content for downloads block
* Add block icon
* Add conversion template (https://github.com/woocommerce/woocommerce-blocks/pull/10077)
* Update inner block name
* Add default title constant
* Revert "Add default title constant"
This reverts commit 1dd3bbfecc1be83c367b1ab064f5032ea58cb678.
* Add global styles for order confirmation status block (https://github.com/woocommerce/woocommerce-blocks/pull/10164)
* Implement style controls
* Prevent link color spilling over onto wrapper
* Add styles and remove class names
* Remove __experimentalWritingMode
* Add global styles for order confirmation summary block (https://github.com/woocommerce/woocommerce-blocks/pull/10179)
* Styles for summary
* Remove __experimentalWritingMode
* Add table styles for order details (https://github.com/woocommerce/woocommerce-blocks/pull/10185)
* Add table styles for order details
* __experimentalFontWeight
* Add link styles
* Handle preview link styles
* Unauthenticated views for Order Confirmation template (https://github.com/woocommerce/woocommerce-blocks/pull/10414)
* Different views by permission
* check user id matches when logged out
* Add order confirmation wrapper block (https://github.com/woocommerce/woocommerce-blocks/pull/10286)
* Add a heading wrapper block
* Register the BillingWrapper Block server side
* Fix exception 'render_content' error
* Add the Billing Wrapper Block to the template
* Fix wrong block name error
* Fix php error
* Conditionally render Billing Address within the Wrapper
* Fix parent rendering
* Clean up code (remove billing address from the template)
* Update titles, descriptions, and icons of the billing Block and inner block
* Fix broken block by removing the "parent" keyword
* Use a user-friendly title and description for the Billing Wrapper
* Update Billing Wrapper Block's title case
Co-authored-by: Mike Jolley <mike.jolley@me.com>
* Fix PHP failing unit test
---------
Co-authored-by: Mike Jolley <mike.jolley@me.com>
* Remove "thanks" for authenticated page
* Introduce shipping wrapper based on billing wrapper
Closeswoocommerce/woocommerce-blocks#10053
* Order confirmation block: Verify email address for guest customers (https://github.com/woocommerce/woocommerce-blocks/pull/10567)
* Add verify step for guest orders
* Render content to pass through block content
* Revert package changes
* Customer orders cannot use email to verify
* Add style controls for order shipping and billing address blocks (https://github.com/woocommerce/woocommerce-blocks/pull/10633)
* Order confirmation block styling (https://github.com/woocommerce/woocommerce-blocks/pull/10780)
* Add missing heading to order details
* Summary block spacing
* Update css variables
* table styles
* Inherit border styles for cells
* Alignment and address styles
* Add downloads wrapper
* Style controls
* Fix typo
* Update Download Wrapper's Icon
* Fix TS error
* Disable Download Block's server side rendering in the editor
This fixes the loading after each style change from the style controls
* Clean up Downloads render functions
* Fix client side Downloads Block's table border
* Download + Total wrappers and tables styling
* small screen
* Remove server side render for previews
---------
Co-authored-by: Saad Tarhi <saad.trh@gmail.com>
* Shorten template description
* Update test address data
* Avoid leaking order key in permission form
* Remove todo
* Make email form required.
* Remove edit page link
* Remove empty columns from address wrapper
* Remove IIFE
* typo
* Update description to mention billing
* Adjust link scss
* Fix wrapper markup and spacing controls
* Add link preview in editor
* Add initial E2E setup for the Order Confirmation Block (https://github.com/woocommerce/woocommerce-blocks/pull/10840)
* Fix WC_DateTime check
* Move form outside of block markup
* Add additional information block (https://github.com/woocommerce/woocommerce-blocks/pull/10842)
* Add block which contains hooks
* Use skeleton for placeholder instead of illustration
* Remove duplicate methods
* Remove duplicate align tag
* Update meta styles
* Tests for order confirmation conditional blocks (https://github.com/woocommerce/woocommerce-blocks/pull/10972)
* Add tests for conditional blocks
* Move setup into test
* Add E2E to the the Order Confirmation Block (https://github.com/woocommerce/woocommerce-blocks/pull/10863)
* Add editor util functions
* Update editor template E2E test
* Add the "exact" property for consistency
* Skip test
Can't get the element in the page. More investigation needed! Skipping
for now.
* Fix "transformIntoBlocks" logic
* Add tests for logged in user
* Fix "beforeAll" config
* Confirm downloads section is visible when logged in
* Create "verifyOrderConfirmationDetails" util function
* Add logged in test case
* Add Guest user test case
* Fix editor e2e testing
* Apply a proper teardown
* Fix failing tests after logout
* Ensure we are logged in before visiting the editor
* Ensure to have shipping selected
* Wait for changes to be saved on the editor
* Ensure shipping options is selected
* Remove comment
* Ensure we are logged in before going to the admin page
* Mark the Order Confirmation as a side effect test
* OrderConfirmation blocks are not experimental
* resolve merge conflict
* Revert package lock changes
* Fix enqueue_assets
* Fix CSS 404s
* Make template tests more robust
* Fix page URL for default confirmation page
* Try afterEach to log back in
* Skip guest/logout use cases
Login out causes other tests to fail. We will implement these case when
the multiple sign in roles are introduced in the codebase.
* Remove tests requiring login out & add comments
* Remove unused util functions
* Hide confirmation blocks from post editor
---------
Co-authored-by: Saad Tarhi <saad.trh@gmail.com>
Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com>
* Rename checkout template slug
* Remove redirect and custom title
* Classic shortcode block for checkout
* Empty title
* WIP placeholder
* Change blockified template
* Prefix cart and checkout templates with "Page: "
* Template migration routine
* Apply same treatment to cart template
* Notices
* Update placeholder text
* Classic shortcodes block
* Page content wrapper for templates
* Update default
* Do not save attributes
* Update templates
* Remove cart classic template
* Reverted endpoints for Cart & Checkout templates. This reverts PR 9406
* Migrate page content wrapper.
* Removed useless method arg. Minor tweaks.
* Skip migration if the theme has a template file for this page.
* Removed impossible condition.
* Migrate page content wrapper.
* Remove TemplateNotice in favour of DefaultNotice
* Documentation links in shortcode placeholder
* Hide cart and checkout page selector when using block themes
* Unused var
* Add tests for template changes
* Revert changes to classic-template
* Allow frontend redirect
* Unused file
* Bump version for updater
* Support x template naming as well as page-x
* Need to add item to cart to test checkout
* Fix header test by fixing utility for adding to cart
* Remove permalink tests
* Click body
* Wait for content to finish loading
* Wait for add to cart response when adding to cart without item name
* Wait for save before visiting frontend
* Set content instead of inserting block
* Perform test in site editor rather than page editor
* Prevent notice to set the default cart/checkout page from showing on the site editor.
---------
Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com>
Co-authored-by: Thomas Roberts <thomas.roberts@automattic.com>
In this update, the layout options for the Product Collection block are transferred from the Toolbar to the Inspector controls. Below is the breakdown of the changes:
1. **Constants Update**
- `LayoutOptions` enumeration has been imported into `constants.ts`, facilitating a more structured approach to managing layout types (grid and stack).
- The default display layout type has been updated from 'flex' to reference `LayoutOptions.GRID`.
- The `getDefaultQuery` function now uses the `getDefaultValueOfInheritQueryFromTemplate` utility to set the default `inherit` value. (This is mainly done to fix a bug)
2. **Display Layout Control Removal**
- The `display-layout-control.tsx` file has been removed, discontinuing the previous method of layout management.
3. **New Layout Options Control**
- A new component `LayoutOptionsControl` has been introduced in the `layout-options-control.tsx` file, utilizing the experimental `ToggleGroupControl` and `ToggleGroupControlOption` components from the WordPress package to provide a more intuitive layout selection experience.
- The `types.ts` file has been updated to define the `LayoutOptions` enum, effectively mapping 'flex' to 'GRID' and 'list' to 'STACK'.
4. **Inspector Controls Update**
- In `inspector-controls/index.tsx`, the obsolete `DisplayLayoutControl` has been replaced with the new `LayoutOptionsControl`, integrating it into the `ProductCollectionInspectorControls` component.
- The `BlockControls` wrapper has been removed, and layout options have been relocated to the Inspector controls, presented as a toggle group within the ToolsPanel.
5. **Inherit Query Control Modification**
- The `inherit-query-control.tsx` file sees a change in the reset value for the `inherit` query attribute to employ a default value which fix one bug.
These changes aim to streamline the user experience by relocating the layout options from the Toolbar to the Inspector controls, offering a centralized location for block settings. Leveraging an enum for layout options fosters code readability and maintainability.
Do note that the update uses experimental components, hence it would be prudent to keep an eye on potential alterations or deprecations in upcoming WordPress releases.
* Enable Product Collection patterns in inserter and kick off the layout control button
* Add Choose Pattern button
* Move Toolbar settings to related directory
* Display Pattern Selection modal with available patterns after clicking the button
* Make Pattern Chooser always visible
Patterns can be changed no matter if the Inherit Query from Template option in enabled or not
* Add pattern replacement mechanism
* Switch from Gutenberg styles to internal ones
* Fix "On sale" badge class for shop
* Add class to sale badge
* Move the thumbnails featching logic to an utils file. Add context directive with thumbnails data to the Product Gallery block. Add on-click directives to the Thumbnails block
* Product Gallery Thumbnails: Remove the legacy thumbnail markup
* Product Gallery Thumbnails: Add Large Image replacing
* update the main image when the thumbnail is clicked
* add E2E tests
* fix typo
* fix warning on the frontend
* address feedback
* update E2E test
* improve comment
* fix indentation
* improve E2E test
* improve flaky test
* improve E2E test
* improve comments
* improve E2E test
* try now
* add comment
* skip test
* reset script
* update todo comment
---------
Co-authored-by: Alba Rincón <alba.rincon@automattic.com>
Co-authored-by: Alba Rincón <albarin@users.noreply.github.com>
Co-authored-by: Luigi <gigitux@gmail.com>
* Fix "On sale" badge class for shop
* Add class to sale badge
* Apply styleProps.styles to elements using them
* Product Gallery: Lock the Sale Badge and the Next/Prev Buttons
* Change default number of columns in Related Products
* Add default attributes to Product Template in Single Product template
* Revert adding attributes
* Fix block alignment with Large Image block
* Prevent error when layout is not present in the attributes object
* Add Large Image and Pager to its own group
* Fix issue when moving around the thumbnails block
* Fix e2e tests for Product Gallery block
* Change ancestor block for the Pager block
* Fix bug where is-plain-obj is not transpiled by Jest, update lock.
* Update packages.
* Mock useSelect for a handful of RichText selectors in test.
* Resolve react to single version to avoid invalid hook errors.
* Patch trim-html locally to avoid a bug in the released npm source.
* Mock out resizeObserver to avoid https://github.com/FezVrasta/react-resize-aware/issues/58
* Don't transpile config package: https://github.com/node-config/node-config/issues/628
Customer Account block icon size is based on the parent `font-size`
in order to make sure they stay harmoniously together.
However, the `box-sizing` could be set by some other actor
and mess with the size of the icon.
* Product Gallery: add support for On Sale Badge Block
* add align support
* Add E2E tests
* set margin via Block Styles
* disable experimental flag
* add next previous block
* restore support file
* fix TS error
* fix layout
* change product
The main aim of this PR was to convert the product-control component to TypeScript. However, since the component is coupled with many other parts (it is itself wrapped into 4 HOCs), many refactoring changes were needed to make the types work.
In particular:
* Add `convertProductResponseItemToSearchItem` utility function
The function allows to clean up the `ProductResponseItem` in order
to make its shape compatible with the `SearchListItem`, instead of
passing the entire object.
Because data from the object might need to be used in certain
circumstance (e.g. render functions), the data is now allowed to be
scoped within a `details` key.
This commit also converts `utils/products` to TypeScript.
* Fix `ProductResponseItem` type missing `slug`
The `slug` is returned by the API but didn't appear in the type def.
* Improve certain HOCs types
The `withSearchedProducts` and `withTransformSingleSelectToMultipleSelect`
HOCs are now typed in such a way that it is clear what incoming props
they expect and what they inject.
* Refactor `ProductAttrributeTermControl` for further type safety
Make sure that `count` is always a `number` as required by the
component types.
* Refactor `search-list-control.tsx` and `item.tsx`
The new `SearchItem` allows for the `details` key to be passed.
All the components are now aware of it.
* Add Product Gallery Next Previous block
* update description
* update registration
* improve style
* use context instead of attributes
* add eslint and ts lint exception
* improve CSS
* E2E Next Previous block (https://github.com/woocommerce/woocommerce-blocks/pull/10329)
* Add E2E tests
* fix e2e tests path after rebase
* add screenshots
* improve E2E test
* improve E2E test
* improve E2E test
---------
Co-authored-by: Manish Menaria <the.manish.menaria@gmail.com>
* fix webpack conf
* Next Previous Button block - Add layout support (https://github.com/woocommerce/woocommerce-blocks/pull/10668)
* Add layout support
* Product Gallery Next Previous: Fix block crashing in the editor when vertical alignment has not been customized yet
* Product Gallery Next Previous: Position fixes for the Next/Previous button both in the editor and frontend
* add E2E test
* fix import
---------
Co-authored-by: Daniel Dudzic <daniel.dudzic@automattic.com>
* Next Previous Buttons: hide buttons when the product has only one image (https://github.com/woocommerce/woocommerce-blocks/pull/10743)
* Next Previous Buttons: hide buttons when the product has only one image
* update URL
* fix import
* set default value
* fix E2E test
---------
Co-authored-by: Manish Menaria <the.manish.menaria@gmail.com>
Co-authored-by: Daniel Dudzic <daniel.dudzic@automattic.com>
* Add support to Interactivity API
* Fix php cs errors
* Rename numberOfThumbnailImages to numberOfThumbnails
* Use frontend.tsx with InteractivityAPI
* Replace viewScript in block.json
* Fix UI misalignment of Filter by Price in TT1 theme
* Fix frontend Firefox styles
* Simplify the styles and fix them in Editor (Firefox/Safari)
* Align the background color and sizing in Firefox
* Enable Product Collection as a core feature
* Fix: disable product query title and summary variations from inserter in favour of Product Collection ones (https://github.com/woocommerce/woocommerce-blocks/pull/10548)
* Limit the scope of Product Query's Product Title and Product Summary
* Add missing piece after refactoring
* Enable manual migration of Products to Product Collection (https://github.com/woocommerce/woocommerce-blocks/pull/10655)
* Refactor block variation registration in product-collection (https://github.com/woocommerce/woocommerce-blocks/pull/10701)
This commit refactors the product-collection block's variation registration.
Changes:
- The `product-summary` and `product-title` variations have been encapsulated within their own respective functions: `registerProductSummaryVariation` and `registerProductTitleVariation`.
- Imported and invoked these new functions in the main `index.tsx` of the product-collection block, ensuring the variations are registered.
---------
Co-authored-by: Manish Menaria <the.manish.menaria@gmail.com>
* Add block foundation
* Add block styles
* Add Dots Pager
* Move icons to the block folder
* Add block settings
* Add Pager to Product Gallery template
* Add setting to change Pager display mode
* Change the block description
* Fix the block icon color when selected
* Fix php cs errors
* Fix php cs errors
* Fix css lint errors
* Fix eslint error
* Move enum to its own file
* Remove unnused call to request context
* Add block template
* Fix php cs errors
* fix php cs errors
* improve docs
* Remove duplicate HTML element and added classnames for single product block (https://github.com/woocommerce/woocommerce-blocks/pull/10374)
* Show only products with rating (https://github.com/woocommerce/woocommerce-blocks/pull/10434)
* Add Product Gallery Thumbnails block (https://github.com/woocommerce/woocommerce-blocks/pull/10442)
* WIP Product Gallery: Add the Thumbnails block
* Product Gallery Thumbnails: Add block settings
* Add template for the Product Gallery block
* Add template for the Product Gallery block. Add the rest of the files.
* Product Gallery Thumbnails: Add context settings sharing between the Product Gallery and Thumbnails block.
* Product Gallery Thumbnails: Add UI functionality and frontend functionality. Add settings for the Thumbnails in both places - Product Gallery and the Thumbnails block.
* Product Gallery Thumbnails: Move the static template ouside of the component
* Make sure the context is set before accesing the array values
* Product Gallery Thumbnails: Move the setGroupAttributes() function outside of the component
* Product Gallery Thumbnails: Fix TS errors
* Product Gallery Thumbnails: Update the Features Flags and Experimental Interfaces doc
* Product Gallery Thumbnails: Fix TS error
* Product Gallery Thumbnails: Remove unused stylesheet
* Product Gallery Thumbnails: Fix TS errors
* Product Gallery Thumbnails: Remove unused context and fix the thumbnails bottom position styling on the frontend.
* Product Gallery Thumbnails: Allow the user to move the horizontal thumbnails above the large image and don't overwrite that automatically
* Product Gallery Thumbnails: Add code comments and remove the incorrect conditional check when moving thumbnails up and down
* Product Gallery Thumbnails: Fix the eslint dependency error
* Product Gallery Thumbnails: Refactor Product Gallery edit code and move the logic to a utils file
* Product Gallery Thumbnails: Update the utils file
* Product Gallery Thumbnails: Update the utils file. Fix comment indentation
* Product Gallery Thumbnails: Fix undefined variable html when only 1 product image is set
* Product Gallery: Rename clientId to productGalleryClientId
* Product Gallery Thumbnails: Combine the useEffect code having the same dependencies
* Product Gallery Thumbnails: Combine all useEffect code together
* Product Gallery Thumbnails: Add a ThumbnailsPosition enum
* Product Gallery Thumbnails: Update the thumbnailsPosition to an enum
* Product Gallery Thumbnails: Fix TS errors
* Product Gallery Thumbnails: Fix TS errors
* Product Gallery Thumbnails: Add missing dependency
* Product Gallery Thumbnails: Uppercase the enum and fix the thumbnails position bug when initially adding the Product Gallery block
* Product Gallery: Add crop, zoom and full-screen settings
* Product Gallery Thumbnails: Replace ts-ignore with ts-expect-error
* Product Gallery Thumbnails: Replace ts-ignore with ts-expect-error
* Product Gallery Thumbnails: Revert back to ts-ignore
* Revert "Product Gallery: Add crop, zoom and full-screen settings"
This reverts commit 840654197619e2611029b81990493387ae0b543d.
* Remove propTypes (https://github.com/woocommerce/woocommerce-blocks/pull/10432)
* Fix badge wrong spacing on the newest arrivals pattern (https://github.com/woocommerce/woocommerce-blocks/pull/10446)
* Product Gallery: Add Crop, Zoom and Full-screen settings (https://github.com/woocommerce/woocommerce-blocks/pull/10445)
* WIP Product Gallery: Add the Thumbnails block
* Product Gallery Thumbnails: Add block settings
* Add template for the Product Gallery block
* Add template for the Product Gallery block. Add the rest of the files.
* Product Gallery Thumbnails: Add context settings sharing between the Product Gallery and Thumbnails block.
* Product Gallery Thumbnails: Add UI functionality and frontend functionality. Add settings for the Thumbnails in both places - Product Gallery and the Thumbnails block.
* Product Gallery Thumbnails: Move the static template ouside of the component
* Make sure the context is set before accesing the array values
* Product Gallery Thumbnails: Move the setGroupAttributes() function outside of the component
* Product Gallery Thumbnails: Fix TS errors
* Product Gallery Thumbnails: Update the Features Flags and Experimental Interfaces doc
* Product Gallery Thumbnails: Fix TS error
* Product Gallery Thumbnails: Remove unused stylesheet
* Product Gallery Thumbnails: Fix TS errors
* Product Gallery Thumbnails: Remove unused context and fix the thumbnails bottom position styling on the frontend.
* Product Gallery Thumbnails: Allow the user to move the horizontal thumbnails above the large image and don't overwrite that automatically
* Product Gallery Thumbnails: Add code comments and remove the incorrect conditional check when moving thumbnails up and down
* Product Gallery Thumbnails: Fix the eslint dependency error
* Product Gallery Thumbnails: Refactor Product Gallery edit code and move the logic to a utils file
* Product Gallery Thumbnails: Update the utils file
* Product Gallery Thumbnails: Update the utils file. Fix comment indentation
* Product Gallery Thumbnails: Fix undefined variable html when only 1 product image is set
* Product Gallery: Rename clientId to productGalleryClientId
* Product Gallery Thumbnails: Combine the useEffect code having the same dependencies
* Product Gallery Thumbnails: Combine all useEffect code together
* Product Gallery Thumbnails: Add a ThumbnailsPosition enum
* Product Gallery Thumbnails: Update the thumbnailsPosition to an enum
* Product Gallery Thumbnails: Fix TS errors
* Product Gallery Thumbnails: Fix TS errors
* Product Gallery Thumbnails: Add missing dependency
* Product Gallery Thumbnails: Uppercase the enum and fix the thumbnails position bug when initially adding the Product Gallery block
* Product Gallery: Add crop, zoom and full-screen settings
* Product Gallery Thumbnails: Replace ts-ignore with ts-expect-error
* Product Gallery Thumbnails: Replace ts-ignore with ts-expect-error
* Product Gallery Thumbnails: Revert back to ts-ignore
* Revert "Product Gallery: Add crop, zoom and full-screen settings"
This reverts commit 840654197619e2611029b81990493387ae0b543d.
* Product Gallery: Add crop, zoom and full-screen settings
* Product Gallery: Remove the redundant React Fragment
* Remove nested filled and empty cart blocks in cart template (https://github.com/woocommerce/woocommerce-blocks/pull/10447)
* improve migration to blockified templates (https://github.com/woocommerce/woocommerce-blocks/pull/10415)
* fix compatibility with WP 6.2 (https://github.com/woocommerce/woocommerce-blocks/pull/10449)
* Add Product Gallery Pager to template
* Add Pager settings to Product Gallery block
* Remove save function and rename icon
* Use nullish coalescing operator for the block context
---------
Co-authored-by: Roy Ho <roykho77@gmail.com>
Co-authored-by: Alba Rincón <albarin@users.noreply.github.com>
Co-authored-by: Daniel Dudzic <daniel.dudzic@automattic.com>
Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>
Co-authored-by: Luigi Teschio <gigitux@gmail.com>
* WIP of Upgrade Notice state
* Extend the state options with seeing option
* Move the logic to the dedicated folder
* Subscribe only if not reverted
* Refactor the way UpgradeNotice is rendered
* Simplify the logic of keeping the Upgrade Notice state in local storage
* Improve types organisation
* Lift the functions interacting with local storage to the Inspector Controls of Product Colelction
* Simplify logic of showing Upgrade Notice
* Disable auto migration
* Refactoring
* Use useLocalStorageState hook
* Fix incorrect merge
* Final improvements
* Allow to display Upgrade Notice after revert and manual upgrade
* Fix incorrect merge
* Improve the unsubscribe process
* Trigger auto-update from Product Collection only
* Remove weird console.log
* Abstract manual update from Product Query
* Fix the taxQuery migration from Product Collection to Products
* Product Collection - logic to hide upgrade notice (https://github.com/woocommerce/woocommerce-blocks/pull/10494)
* Add timestamp to each upgrade notice status change
* Revert back only Product Collections converted from Products block
* Make the time threshold configurable
* Add logic that hides the Upgrade Notice after some amount of displays
* Fix the taxQuery migration from Product Collection to Products
* Change the way to count Product Collection entries
* Fix the problem of multiple display counter increments with Product Collection
* Update Upgrade Notice visibility conditions
* Add contiions to unmark Product Collection as converted from Products
* Change variable name
* Change variable t to time name for better readibility. Improve types
* Replace useState with useRef
* Remove unecessary props passed to UpgradeNotice
* Fix express button display in the Cart block
When multiple buttons are displayed they don't appear stacked. This PR fixes a regression;
* Fix editor experience
* Fix incorrect icon color when Product Gallery is selected
* Fix incorrect icon color when block is selected
* Remove unnecessary style
* Fix icon alignment
* Fix alignment for the icon
* Fix icon alignment
* Update Interactivity API JS files
* Disable TS checks in the Interactivity API for now
* Add new SSR files
* Replace wp_ prefixes with wc_ ones
* Replace wp- prefix with wc-
* Replace guternberg_ prefix with woocommerce_
* Remove file comments from Gutenberg
* Rename files with `wp` prefix
* Fix code to load Interactivity API php files
* Remove TODO comments
* Replace @wordpress with @woocommerce
* Update Webpack configuration
* Fix directive prefix
* Remove interactivity folder from tsconfig exclude
* Add client-side navigation meta tag code
* Remove unneeded blocks.php file
* Fix store tag id
* Register Interactivity API runtime script
* Fix Interactivity API runtime registering
* Remove all files related to directive processing in PHP
* Move json_encode to Store's render method
* WIP
* WIP
* WIP
* WIP
* Preserve previous context
* Ignore Minicart block on client-side navigation
* Refresh page on store updatRefresh page on store updatee
* Refactor logic
* Add console error when a path is missing
* fix PHP lint error
* WIP store
* use store approach
* update jest configuration
* restore Mini Cart changes
* move cart store subscription to interactivity package
* move interactivity flag
* format HTML
* move addToCartText to the context
* Load product-query stylesheet when rendering the Products block
* update sideEffects array
* fix catch
* rename moreThanOneItem to isThereMoreThanOneItem
* improve how scripts are enqueued
* update default value for the filter woocommerce_blocks_enable_interactivity_api
* Update assets/js/atomic/blocks/product-elements/button/block.json
Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com>
* Update assets/js/interactivity/cart/cart-store.ts
Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com>
* fix block.json
* remove updateStore function
* restore interactivity api changes
* import cart store
* show notice when there is an error
* add logic to dequeue script on classic themes and block themes
* imrpove logic about notice
* Interactivity API: add `afterLoad` callbacks to `store()` function (https://github.com/woocommerce/woocommerce-blocks/pull/10338)
* show notice when there is an error
* Add initial implementation for store callbacks
* Run `afterLoad` callbacks after `init`
* Move cart state subscription to Product button
* Remove cart-store from Interactivity API internals
* Change callbacks with options and save only afterLoad callbacks
* ProductButton: Add animation (https://github.com/woocommerce/woocommerce-blocks/pull/10351)
* implement animation
* improve logic
* refactor logic
* refactor code
* address feedback about code style
* add support for woocommerce_add_to_cart_quantity
* Fix animation flickering
* Introduce wp-effect, reduce the amount of numberOfItem variables to 2 and consolidate animation status
* add support for added class
* Remove unnecessary selector
* Don't fetch cart if it was already fetched
* remove added class
---------
Co-authored-by: Luis Herranz <luisherranz@gmail.com>
---------
Co-authored-by: Luigi <gigitux@gmail.com>
Co-authored-by: Luis Herranz <luisherranz@gmail.com>
* update deepsignal
* remove added class
* update deepsignal
* Interactivity API and Product Button: Add E2E tests (https://github.com/woocommerce/woocommerce-blocks/pull/10036)
* Add FrontendUtils class
* fix conflicts
* use locator
* restore click usage
* Product Button: Add E2E test
* fix util
* fix E2E tests
* remove comment
* Add E2E test to ensure that woocommerce_product_add_to_cart_text works
* update sideEffects array
* add zip and unzip as package
* fix wp-env configuration
* fix E2E test
* add report
* try now
* try now
* try now
* fix E2E test
* E2E: Add documentation for testing actions and filters. Fixeswoocommerce/woocommerce-blocks#10135 (https://github.com/woocommerce/woocommerce-blocks/pull/10206)
* update description
* fix label
* rename files
* make requestUtils private
* remove page.goto
* use toHaveCount
* use productsToDisplay variable
* fix E2E tests
* rename class utils
---------
Co-authored-by: Daniel Dudzic <daniel.dudzic@automattic.com>
---------
Co-authored-by: David Arenas <david.arenas@automattic.com>
Co-authored-by: Luis Herranz <luisherranz@gmail.com>
Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com>
Co-authored-by: Daniel Dudzic <daniel.dudzic@automattic.com>
* Add local state to address-form
* Update test with valid postcode and required fields
* Push changes refactoring
* Avoid loops due to retrying same data
* Callbacks to prevent rerenders
* Move validation functions
* Filter incoming values to only those included as fields to prevent errors
* Keep track of country changes to prevent excessive updates of addressFormFields.
* Use helpers in test
* Fill company
* Revert local state in address form
* Update address form to remove validation handling for postcode (country clears the field).
* Revert "Update test with valid postcode and required fields"
This reverts commit 718a6006df24f6e957297ad4d1ef9d6f690793bd.
* Clear postcode when country changes if invalid
* Revalidate fields when country changes
* Comment for pick
* Revert unneccessary test change
* Revery moving of functions to reduce diff size
* Increase push timeout in tests
* Revert test changes
* Update router to hydrate only interactive regions
* Rename link directive to navigation-link
* Add navigation directives to Query and Pagination blocks
* Enable the Interactivity API by default
* Remove client-side navigation meta tag
* Cache initial regions
* Move data-wc-interactive from query to query-pagination
* Add woo prefix to navigation id
* Add keys and move wc-interactive back to the query block
* Reuse root fragments for each interactive region
* Fix navigation-id retrieval
* WIP Product Gallery: Add the Thumbnails block
* Product Gallery Thumbnails: Add block settings
* Add template for the Product Gallery block
* Add template for the Product Gallery block. Add the rest of the files.
* Product Gallery Thumbnails: Add context settings sharing between the Product Gallery and Thumbnails block.
* Product Gallery Thumbnails: Add UI functionality and frontend functionality. Add settings for the Thumbnails in both places - Product Gallery and the Thumbnails block.
* Product Gallery Thumbnails: Move the static template ouside of the component
* Make sure the context is set before accesing the array values
* Product Gallery Thumbnails: Move the setGroupAttributes() function outside of the component
* Product Gallery Thumbnails: Fix TS errors
* Product Gallery Thumbnails: Update the Features Flags and Experimental Interfaces doc
* Product Gallery Thumbnails: Fix TS error
* Product Gallery Thumbnails: Remove unused stylesheet
* Product Gallery Thumbnails: Fix TS errors
* Product Gallery Thumbnails: Remove unused context and fix the thumbnails bottom position styling on the frontend.
* Product Gallery Thumbnails: Allow the user to move the horizontal thumbnails above the large image and don't overwrite that automatically
* Product Gallery Thumbnails: Add code comments and remove the incorrect conditional check when moving thumbnails up and down
* Product Gallery Thumbnails: Fix the eslint dependency error
* Product Gallery Thumbnails: Refactor Product Gallery edit code and move the logic to a utils file
* Product Gallery Thumbnails: Update the utils file
* Product Gallery Thumbnails: Update the utils file. Fix comment indentation
* Product Gallery Thumbnails: Fix undefined variable html when only 1 product image is set
* Product Gallery: Rename clientId to productGalleryClientId
* Product Gallery Thumbnails: Combine the useEffect code having the same dependencies
* Product Gallery Thumbnails: Combine all useEffect code together
* Product Gallery Thumbnails: Add a ThumbnailsPosition enum
* Product Gallery Thumbnails: Update the thumbnailsPosition to an enum
* Product Gallery Thumbnails: Fix TS errors
* Product Gallery Thumbnails: Fix TS errors
* Product Gallery Thumbnails: Add missing dependency
* Product Gallery Thumbnails: Uppercase the enum and fix the thumbnails position bug when initially adding the Product Gallery block
* Product Gallery: Add crop, zoom and full-screen settings
* Product Gallery Thumbnails: Replace ts-ignore with ts-expect-error
* Product Gallery Thumbnails: Replace ts-ignore with ts-expect-error
* Product Gallery Thumbnails: Revert back to ts-ignore
* Revert "Product Gallery: Add crop, zoom and full-screen settings"
This reverts commit 840654197619e2611029b81990493387ae0b543d.
* Product Gallery: Add crop, zoom and full-screen settings
* Product Gallery: Remove the redundant React Fragment
* WIP Product Gallery: Add the Thumbnails block
* Product Gallery Thumbnails: Add block settings
* Add template for the Product Gallery block
* Add template for the Product Gallery block. Add the rest of the files.
* Product Gallery Thumbnails: Add context settings sharing between the Product Gallery and Thumbnails block.
* Product Gallery Thumbnails: Add UI functionality and frontend functionality. Add settings for the Thumbnails in both places - Product Gallery and the Thumbnails block.
* Product Gallery Thumbnails: Move the static template ouside of the component
* Make sure the context is set before accesing the array values
* Product Gallery Thumbnails: Move the setGroupAttributes() function outside of the component
* Product Gallery Thumbnails: Fix TS errors
* Product Gallery Thumbnails: Update the Features Flags and Experimental Interfaces doc
* Product Gallery Thumbnails: Fix TS error
* Product Gallery Thumbnails: Remove unused stylesheet
* Product Gallery Thumbnails: Fix TS errors
* Product Gallery Thumbnails: Remove unused context and fix the thumbnails bottom position styling on the frontend.
* Product Gallery Thumbnails: Allow the user to move the horizontal thumbnails above the large image and don't overwrite that automatically
* Product Gallery Thumbnails: Add code comments and remove the incorrect conditional check when moving thumbnails up and down
* Product Gallery Thumbnails: Fix the eslint dependency error
* Product Gallery Thumbnails: Refactor Product Gallery edit code and move the logic to a utils file
* Product Gallery Thumbnails: Update the utils file
* Product Gallery Thumbnails: Update the utils file. Fix comment indentation
* Product Gallery Thumbnails: Fix undefined variable html when only 1 product image is set
* Product Gallery: Rename clientId to productGalleryClientId
* Product Gallery Thumbnails: Combine the useEffect code having the same dependencies
* Product Gallery Thumbnails: Combine all useEffect code together
* Product Gallery Thumbnails: Add a ThumbnailsPosition enum
* Product Gallery Thumbnails: Update the thumbnailsPosition to an enum
* Product Gallery Thumbnails: Fix TS errors
* Product Gallery Thumbnails: Fix TS errors
* Product Gallery Thumbnails: Add missing dependency
* Product Gallery Thumbnails: Uppercase the enum and fix the thumbnails position bug when initially adding the Product Gallery block
* Product Gallery: Add crop, zoom and full-screen settings
* Product Gallery Thumbnails: Replace ts-ignore with ts-expect-error
* Product Gallery Thumbnails: Replace ts-ignore with ts-expect-error
* Product Gallery Thumbnails: Revert back to ts-ignore
* Revert "Product Gallery: Add crop, zoom and full-screen settings"
This reverts commit 840654197619e2611029b81990493387ae0b543d.
* WIP Product Gallery: Add the Thumbnails block
* Product Gallery Thumbnails: Add block settings
* Add template for the Product Gallery block
* Add template for the Product Gallery block. Add the rest of the files.
* Product Gallery Thumbnails: Add context settings sharing between the Product Gallery and Thumbnails block.
* Product Gallery Thumbnails: Add UI functionality and frontend functionality. Add settings for the Thumbnails in both places - Product Gallery and the Thumbnails block.
* Product Gallery Thumbnails: Move the static template ouside of the component
* Make sure the context is set before accesing the array values
* Product Gallery Thumbnails: Move the setGroupAttributes() function outside of the component
* Product Gallery Thumbnails: Fix TS errors
* Product Gallery Thumbnails: Update the Features Flags and Experimental Interfaces doc
* Product Gallery Thumbnails: Fix TS error
* Product Gallery Thumbnails: Remove unused stylesheet
* Product Gallery Thumbnails: Fix TS errors
* Product Gallery Thumbnails: Remove unused context and fix the thumbnails bottom position styling on the frontend.
* Product Gallery Thumbnails: Allow the user to move the horizontal thumbnails above the large image and don't overwrite that automatically
* Product Gallery Thumbnails: Add code comments and remove the incorrect conditional check when moving thumbnails up and down
* Product Gallery Thumbnails: Fix the eslint dependency error
* Product Gallery Thumbnails: Refactor Product Gallery edit code and move the logic to a utils file
* Product Gallery Thumbnails: Update the utils file
* Product Gallery Thumbnails: Update the utils file. Fix comment indentation
* Product Gallery Thumbnails: Fix undefined variable html when only 1 product image is set
* Product Gallery: Rename clientId to productGalleryClientId
* Product Gallery Thumbnails: Combine the useEffect code having the same dependencies
* Product Gallery Thumbnails: Combine all useEffect code together
* Product Gallery Thumbnails: Add a ThumbnailsPosition enum
* Product Gallery Thumbnails: Update the thumbnailsPosition to an enum
* Product Gallery Thumbnails: Fix TS errors
* Product Gallery Thumbnails: Fix TS errors
* Product Gallery Thumbnails: Add missing dependency
* Product Gallery Thumbnails: Uppercase the enum and fix the thumbnails position bug when initially adding the Product Gallery block
* Product Gallery: Add crop, zoom and full-screen settings
* Product Gallery Thumbnails: Replace ts-ignore with ts-expect-error
* Product Gallery Thumbnails: Replace ts-ignore with ts-expect-error
* Product Gallery Thumbnails: Revert back to ts-ignore
* Make sure the revert button is registered and enqueued for usage exclusively in the site editor.
* Register and enqueue the styles for the revert button.
* Rename the files.
* Revert "Rename the file renames."
This reverts commit c0330ce70fec20bea1f957eddcf458881e16242c.
* Add plugin-proposal-optional-chaining to the WebPack plugins config.
* Rename the files.
* Remove unnecessary dependencies as those are already provided via : more specifically, get_script_data.
* Address CR.
* Change icon, title and description of the Express Checkout Block
* Fix icon style
* Update icon and add styles
* change icon for express payments in cart
* Show alignment toolbar also when the block is in the single product block
* Start using `Single Product` for the `Product Details Product Listing` pattern
* Use counter and stars blocks in the pattern
* Undo button change
* Make the new rating blocks not experimental
* Add Beta to the average rating block
* Add blocks to block types controller
* Add option to manually update Products block to Product Collection
* Disable manual upgrade of Products yet
* Manual update flag doesn't have to be dependant on auto update
* Removed commented out console info logs
* Disable option to upgrade Products block
* Change the way to bold text in Upgrade Notices so it's translatable
* Change the way UpgradeNotice is rendered conditionally
* Add new Product Average Rating block
* Add new blocks to the feature flag docs
* Translate 'No ratings'
* Fix condition
* Small improvements after review
* Avoid duplication of styles
* Update supports in php class
This commit adds a new `__experimentalExpandOnFocus` attribute to the component within the `HandPickedProductsControl`. The value is set to `true`, enabling automatic expansion of the list when the user focuses on the product selection field.
This change aims to improve the user experience by making it easier for the user to see all available options when they focus on the selection list.
* Create Mini-Cart template part area
* Update Mini-Cart template part name to exclude it
* Update src/BlockTemplatesController.php
Co-authored-by: Daniel Dudzic <daniel.dudzic@automattic.com>
* Update src/BlockTemplatesController.php
Co-authored-by: Daniel Dudzic <daniel.dudzic@automattic.com>
* Keep both variations of the template part name when excluding them
* Revert "Keep both variations of the template part name when excluding them"
This reverts commit c3f293511536d1ebbac0f50caaf74cded28d0025.
---------
Co-authored-by: Daniel Dudzic <daniel.dudzic@automattic.com>
* Remove queries that fetch all products for manipulating the results returned by the Store API for certain use-cases.
* Remove the code that's supposed to read product ids for filter context and logic around that in useCollectionData
* Fix incorrect merge
---------
Co-authored-by: Patricia Hillebrandt <patriciahillebrandt@gmail.com>
* Rating start block improvements
Fix classes, register in single product, remove unused code
* Allow to use block on product & product collection
* Fix star missalignment
* Restrict the block to be insertable only in single product
Key updates:
1. Additional CSS class to Inherit Query Control: A CSS class named `wc-block-product-collection__inherit-query-control` has been added to the ToggleControl component. This provides a precise target for E2E tests and potential custom styles.
2. E2E tests for 'Inherit query from template' control: Numerous scenarios have been covered to ensure the control's correct behavior. These scenarios include verifying visibility under different circumstances and checking its functionality in a Product Catalog template.
3. E2E test code enhancements: The E2E test code now exports the `SELECTORS` object to assist in locating different elements during the tests. This includes the new 'Inherit query from template' control. The `setShowOnlyProductsOnSale()` function has been refactored to improve readability and provide more granular control over its operations.
4. Test scenario for 'Show only products on sale': The existing E2E test for this functionality has been extended to check that it retains its state when the 'Inherit query from template' control is toggled.
These changes increase the robustness of our E2E tests, providing better coverage for the 'Inherit query from template' control in the Product Collection block.
* Foundation of the Products block replacement with Product Collection
* Provide logic to replace Products with Product Collection
* Make sure the blocks can be replaced
* Add types and refactor replacement a bit
* Fix the query attributes transform
* Add upgrade Notice to the Product Collection block
* Force upgrade notice to be displayed at the top of the Inspector Controls
* Externalise migration code so it can be reused in both ways
* Add util to get block IDs byt its name
* Add a way to revert the Product Collection blocks to Products
* Move the subscription to another place where it's triggered only once
* Add default values
* Remove attributes from Products block if they're not used to avoid incorrect query
* WIP logic of unseen/seen/reverted notice
* Change the state reading
* Revert changes regarding notice displaying logic
* Change the logc of firing replacement and bail early if there's no core/query blocks
* Add todos
* Implement inner blocks migration
* Implement the revert transformation of inner blocks
* Refactor types
* Add layout transformation from Products to Product Collection
* Add layout migration from Product Collection to Products
* Disable migration by default
* Simplify some parts of code
* Remove additional keyword from Product Collection to move it to another PR
* Adjust the logic to introduce the first step: conversion from Products to Product Collection
* Disable automatic migration
* Refactor Columns Control inspector controls in Product Collection
* Refactor Order By inspector controls in Product Collection
* Reorder imports in Product Collection Inspector Controls
* Refactor On Sale inspector controls in Product Collection
* Refactor Stock Status inspector controls in Product Collection
* Refactor Keyword inspector controls in Product Collection
* Unify interface of query controlling Inspector Controls
* Unify interfaces of Inspector Controls that modify Query in Product Collection
* Unify other Query modifying Controls
* Simplify types
* Add Display Layout controls to Product Collection
* Adjust the layout type name
* Add explicit display layout types
* Change the function name to setDisplayLayout so it's more explicit
* Pass only the necessary props to nested inspector controls
---------
Co-authored-by: Manish Menaria <the.manish.menaria@gmail.com>
* Add support for filter blocks
This commit updates the `ProductCollection` block implementation to add support for filter blocks, including the Price filter, Attributes filter, Rating filter, and In stock filter.
The changes include:
1. Adding a new property `$attributes_filter_query_args` to store the query arguments related to the filter by attributes block.
2. Adding a new method `add_support_for_filter_blocks()` to enable support for filter blocks. This method sets the necessary asset data to enable filtering and refreshes the page when a filter is applied.
3. Adding new methods to handle specific filter queries, including `get_filter_by_price_query()`, `get_filter_by_attributes_query()`, `get_filter_by_stock_status_query()`, and `get_filter_by_rating_query()`. These methods generate the respective queries based on the applied filters.
4. Refactoring the `get_final_query_args()` method to include the newly added filter queries using the `get_queries_by_applied_filters()` method.
These changes enhance the functionality of the `ProductCollection` block by allowing users to filter products based on price, attributes, rating, and stock status.
* Go to first page when filters are updated
* Enhance ProductCollection block to support filter blocks
This commit enhances the ProductCollection block to support various filter blocks such as Price filter block, Attributes filter block, Rating filter block, and In stock filter block.
The `build_query` method has been refactored into two separate methods: `build_frontend_query` and `get_final_frontend_query` to make the code more modular and readable. The `add_support_for_filter_blocks` method has been modified to support the generation of product IDs for filter blocks.
The method `update_rest_query` has been renamed to `update_rest_query_in_editor` for better clarity and understanding of its function. Similarly, `get_final_query_args` has been refactored to include the `$is_exclude_applied_filters` parameter which helps in generating product IDs for the filter blocks.
Moreover, the filter hook `pre_render_block` has been added to support the filtering of blocks before they are rendered.
This update will enhance the user experience by providing more filtering options in the ProductCollection block.
* Remove changes related to redirect to 1st page
* Go to first page when filters are updated
This commit refactors the changeUrl function in the `filters.ts` file. The purpose of this refactor is to remove the page number from the URL whenever filters are changed. This ensures that the user is always taken to the first page of results.
The commit includes the following changes:
- Added comments explaining the different page number formats in the URL.
- Updated the `newUrl` parameter by removing the page number using regular expressions.
- The page is then reloaded with the updated URL using `window.location.href`.
These changes improve the URL handling in the `changeUrl` function and enhance the user experience when interacting with filters.
* Optimize URL updates to prevent unnecessary page reloads
This commit optimizes the `changeUrl` utility function to prevent unnecessary page reloads.
Changes:
1. It checks if there are no query parameters in the URL and the URL ends with a '?'.
2. If these conditions are met, it removes the trailing '?' from the URL.
The reason for this change is that a '?' in the URL typically indicates that query parameters will follow. If there are no query parameters, the '?' is unnecessary and can cause the page to reload, which can negatively affect performance. Therefore, by removing the '?', we prevent this unnecessary page reload.
* Simplify trailing '?' removal in URL handling
This commit simplifies the removal of trailing '?' characters from URLs.
The previous implementation checked if there were any query parameters
before removing a trailing '?'.
However, upon review, it was determined that this check was unnecessary,
as a trailing '?' could be removed safely even if query parameters were
present, without any negative impact.
This change simplifies the code and prevents unnecessary computation
checking for the existence of query parameters.
* Product Gallery: Add an new block base code
* Product Gallery: Add experimental flag
* Product Gallery: Add Large Image block code
* Product Gallery Large Image: Remove unsed types
* Product Gallery: Move the block from registerBlockType to registerBlockSingleProductTemplate
* Product Gallery: Update icon
* Product Gallery: Add missing icon import
* Product Gallery Large Image: Add experimental mode check
* Product Gallery Large Image: Deregister unnecessary block settings
* Product Gallery Large Image: Add experimental flag to the Product Gallery Large Image and remove the icon override
* Product Gallery Large Image: Add zoom and correct styling
* Product Gallery Large Image: Remove commented out unnecessary code
* Product Gallery Large Image: Re-add the removed action after capturing the large image html
* Product Gallery Large Image: Update Large Image icon and description. Move metadata to the block.json file.
* Product Gallery: Add an new block base code
* Product Gallery: Add experimental flag
* Product Gallery: Move the block from registerBlockType to registerBlockSingleProductTemplate
* Product Gallery: Update icon
* Add height & width setting to the image sidebar settings
* Extract settings and add scale options
* Add width settings
* Apply settings on the frontend
* Style placeholder image
* Replace post featured image with product image
* Allow the width to be wider than container
* Fix image on top of other elements
* Hide "collection from" text when a location has an incomplete address.
* Fix display on confirmation page
* has_valid_pickup_location helper
* Missing isset
* Update test
* Fix pickup text assertion
---------
Co-authored-by: Niels Lange <info@nielslange.de>
* Fix Product Image Gallery block overflow when multiple images are used
* Increase css specificity for the Product Image Gallery images
* Fix whitespace
* Fix style issue when using smaller images in the product image gallery
* WIP: dirty attempt to dry run Cart & Checkout templates
* Added Cart and Checkout to the template hierarchies
* Merge branch 'trunk' into poc/cart_and_checkout_fse_templates
* Updated cart & Checkout templates
* Order Received FSE template (https://github.com/woocommerce/woocommerce-blocks/pull/8937)
* Order Received template bootstrap
* typo
* WIP: new block
* add logic here
* Order received classic template
* reverted constants.ts
* Added the post title (buggy)
* Corrected page title
* Updated constants.ts
* Fixed template typo
* removed placeholder for order received block
* add order-received template description
* updated placeholder description
* Formatting fixes
* Template description.
* replaced hardcoded string with OrderReceivedTemplate::SLUG
---------
Co-authored-by: Luigi <gigitux@gmail.com>
* Code formatting (https://github.com/woocommerce/woocommerce-blocks/pull/8350)
* Code formatting
* page_template_hierarchy priority to 1 (https://github.com/woocommerce/woocommerce-blocks/pull/9323)
Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com>
* Migrate Cart and Checkout Pages to the Template Editor when using a FSE theme (https://github.com/woocommerce/woocommerce-blocks/pull/9339)
* Introduce woocommerce_blocks_template_content hook
* Migrate cart and checkout page content to the template editor
* Add redirection from edit page to edit template
---------
Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com>
* Removed header and footer from checkout template. (https://github.com/woocommerce/woocommerce-blocks/pull/9378)
* Removed header and footer from checkout template.
* Removed header and footer from checkout template migration
* Permalink solution for the checkout endpoint/template (https://github.com/woocommerce/woocommerce-blocks/pull/9406)
* Checkout endpoint work
* Move setting field to util
* Include link to edit the template
* Remove todo
* Refactor checkout templates to share logic (https://github.com/woocommerce/woocommerce-blocks/pull/9411)
* Sync endpoints with pages (https://github.com/woocommerce/woocommerce-blocks/pull/9426)
* Switch to page syncing
* Update settings descriptions
---------
Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com>
* Migrate pages to templates once (https://github.com/woocommerce/woocommerce-blocks/pull/9488)
* Migrate content on init, once
* Skip migration if page does not exist
* Put back HTML for header and footer parts
* Fix page redirect due to wrong ID
* fix loading template part
* Removed unnecessary var
* update cart and checkout html templates
---------
Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com>
* Include a notice to redirect user to template editor (https://github.com/woocommerce/woocommerce-blocks/pull/9508)
* Template Placeholder Design for the Order Received Template (https://github.com/woocommerce/woocommerce-blocks/pull/9602)
* Load frontend styles in editor iframe
* Update placeholder to include skeleton and updated icons
* Update classic template configs
* 1px border for .wp-block-woocommerce-classic-template__placeholder-copy
* Show copy on focus
* Sample data
---------
Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com>
* Add simplified header on checkout template (https://github.com/woocommerce/woocommerce-blocks/pull/9607)
* Added simplified header on checkout template
* Moved simplified header to template part
* updated constants.ts
* added template part to checkout.html
* Add missing translation
* frontpage_template_hierarchy no longer needed
* Allow plugin based template parts (https://github.com/woocommerce/woocommerce-blocks/pull/9667)
* Merge branch 'trunk' into add/9288_cart-checkout-order-received_fse_templates
* Synced templates on blockified folder
* Add blockified order-received.html
* removed WooCommerce prefix
* Refactor/rebrand order received template to order confirmation (https://github.com/woocommerce/woocommerce-blocks/pull/9734)
* rebrand order received to order confirmation
* updated descriptions for templates
* updated descriptions for order confirmation placeholder
* Resolve merge conflict
* Resolve merge conflicts
* Resolve more merge conflicts after rebase
* Fix formatting
* Use patterns for localisation (https://github.com/woocommerce/woocommerce-blocks/pull/9883)
* e2e tests for cart and checkout templates (https://github.com/woocommerce/woocommerce-blocks/pull/9939)
* Merge branch 'trunk' into poc/cart_and_checkout_fse_templates
* Merge branch 'trunk' into add/9288_cart-checkout-order-received_fse_templates
* Resolve merge conflicts
* Add e2e for permalink settings
* Test that templates exist
* Add test to check that templates can be edited
* Add tests to confirm templates can be edited
* Ensure cart has contents before running tests on frontend views
* Commend out problem test
* Make sure search has multiple results
* Remove useThrottle - bad rebase
* Revert changes to docs after rebase
* Revert function call for noReviewsPlaceholder
* Bad rebase
* Reverts
* Remove revertTemplate
* Spacing
* Wait for networkidle after navigation
* Always wait for network
* Use button roles in site editor
* More specific button locator
* Update option comparison
* Fix template content
* Disable failing tests
* Disable failing classic template tests
* Use enterEditMode
* More enterEditMode usage
* enterEditMode
* Use test.skip
* More robust selectors
* Alt iframe selector
---------
Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com>
* Skip flakey test
---------
Co-authored-by: Luigi <gigitux@gmail.com>
Co-authored-by: Mike Jolley <mike.jolley@me.com>
* Change type of payment requirements to string[]
* Add CanMakePaymentArgumentCart type and update CanMakePaymentArgument
* Add getCanMakePaymentArg function to get the arg, allows reusability
* Check saved methods gateway's to see if they can make payment
* Make canMakePaymentArg a dependency of the useMemo
* Remove await from sync function call
* Update variable names to better reflect what they store
* Add tests to ensure saved payment methods don't show if canPay is false
* Rename save-payment-method-options to tsx
* Update saved payment method options to TS
* Fix TS error in saved-payment-method-options test
* Update Interactivity API JS files
* Disable TS checks in the Interactivity API for now
* Add new SSR files
* Replace wp_ prefixes with wc_ ones
* Replace wp- prefix with wc-
* Replace guternberg_ prefix with woocommerce_
* Remove file comments from Gutenberg
* Rename files with `wp` prefix
* Fix code to load Interactivity API php files
* Remove TODO comments
* Replace @wordpress with @woocommerce
* Update Webpack configuration
* Fix directive prefix
* Remove interactivity folder from tsconfig exclude
* Add client-side navigation meta tag code
* Remove unneeded blocks.php file
* Fix store tag id
* Register Interactivity API runtime script
* Fix Interactivity API runtime registering
* Remove all files related to directive processing in PHP
* Move json_encode to Store's render method
* Default show product counts to false for filter by attributes block
* Default show product counts to false for filter by stock block
* Default show product counts to false for filter by rating block
* Refactor deprecation
* Refactor deprecation
* Refactor deprecation
* Allow customer account block to center align
* Convert to using Flexbox
* Use mixins to DRY
---------
Co-authored-by: Manish Menaria <the.manish.menaria@gmail.com>
* Add E2E tests for Product Collection Block
This commit does the following changes:
1. Adjusts the .gitignore file to ignore the test-results and artifacts directories under all subdirectories named 'e2e-pw'.
2. Adds new E2E tests for the Product Collection block, specifically testing:
- If the block renders correctly, including validating the number of product images, titles, prices, and 'Add to Cart' buttons.
- If the sidebar settings correctly control the number of displayed columns.
3. Implements the 'ProductCollectionPage' class, providing methods to perform actions such as creating a new post, inserting a block, publishing a post, and locating various elements on the page.
4. Adjusts the directory structure for the E2E tests to improve organization and readability.
* Minor improvements
* Update E2E tests for Product Collection block sidebar settings
This commit updates the E2E tests for the sidebar settings of the Product Collection block. The changes include:
1. Refactoring the test assertions to use property accessors instead of method calls for the `ProductCollectionPage` class. This improves readability and consistency.
2. Updating the `ProductCollectionPage` class to initialize locators for editor and frontend elements separately. This allows easier differentiation between editor and frontend locators.
The test file `sidebar-settings.block_theme.spec.ts` has been deleted, as its functionality is now covered by the updated tests in `product-collection.block_theme.spec.ts`.
* Don't update package.json files
* Don't update gitignore file
* Add E2E test for order by control
This commit updates the E2E tests for the sidebar settings and order by control of the Product Collection block. The changes include:
1. Refactoring the test assertions and descriptions for improved readability and clarity.
2. Adding a new test case to verify the correct sorting of products by title in descending order.
3. Updating the `ProductCollectionPage` class to include a new method `setOrderBy()` to set the order by value in the order by control.
4. Adding a new method `waitForProductsToLoad()` in the `ProductCollectionPage` class to wait for the products to load in the block.
These changes ensure that the sidebar settings and order by control are functioning correctly in the Product Collection block.
* Minor improvements
* Add tests for "on sale" filter
* Add tests for Hand picked products filter
This commit updates the E2E tests for the handpicked products filter in the Product Collection block. The changes include:
1. Adding a new test case to verify that products can be filtered based on the selection in the handpicked products option.
2. Adding a new method `addFilter()` to the `ProductCollectionPage` class to select a filter option from the dropdown.
3. Adding a new method `setHandpickedProducts()` to the `ProductCollectionPage` class to set the handpicked products in the block settings.
These changes ensure that the handpicked products filter is functioning correctly in the Product Collection block.
* Verify that on sale filter works on frontend
Adding assertions to verify the count and presence of on-sale products in the frontend after publishing.
* Add tests for Keyword filter
This commit updates the E2E tests for the keyword filter in the Product Collection block. The changes include:
1. Adding assertions to verify that the products are correctly filtered based on the keyword entered.
2. Adding assertions to verify the filtered products in the frontend after publishing.
These changes ensure that the keyword filter in the Product Collection block is functioning correctly.
* Use fixture to setup product collection page
This commit refactors the E2E tests for the Product Collection block to improve test structure and readability. The changes include:
1. Refactoring the test structure using the `test.extend` function to define shared setup and teardown logic.
2. Moving the creation of the `ProductCollectionPage` instance to the shared setup logic.
3. Using the `pageObject` fixture in each test to access the `ProductCollectionPage` instance.
4. Removing duplicate code for creating the `ProductCollectionPage` instance.
These changes enhance the maintainability and readability of the E2E tests for the Product Collection block.
* Add CartEventsContext with onProceedToCheckout event
* Wrap Cart in CartEventsProvider
* Dispatch onProceedToCheckout event when button is pressed
* Update type of children on CartEventsProvider
* Add test for ProceedToCheckout block
* Add tests for CartEventProvider
* Remove superfluous div
* Fix incorrect nesting after rebase
* Wrap mini cart in CartEventsProvider
* Dispatch onProceedToCheckout event when clicking button in mini cart
* Add tests for mini cart onProceedToCheckout emitter
* Make observer fail so navigation isn't attempted
* Prevent console error on navigation
* Try preventing navigation in unit tests
* Try preventing navigation in unit tests
* Try preventing navigation in unit tests
* Try preventing navigation in unit tests
* Try preventing navigation in unit tests
* Try preventing navigation in unit tests
* Try preventing navigation in unit tests
* Mini Cart Block: show the total price, including tax, according to the option
* Fix tests in PR 9878 (https://github.com/woocommerce/woocommerce-blocks/pull/9880)
* add unit test
---------
Co-authored-by: Karol Manijak <karol.manijak@automattic.com>
* Mini Cart: Update color settings to include Price, Icon and Product Count.
* Fix color settings in the editor.
* Mini Cart: Add color settings for the Price, Icon and Product Count.
* Mini Cart: Remove unnecessary color settings.
* Remove unnecessary code comments.
* Update color settings labels.
* Add price color to the tax label.
* Add missing docs comment
* Fix TS errors
* Fix TS error
* Adjust type declaration
* Add TS error comments
* Change @ts-to-do to @ts-expect-error
---------
Co-authored-by: tjcafferkey <tjcafferkey@gmail.com>
This commit introduces the 'Display Settings' toolbar for the 'Product Collection' block in the Gutenberg editor.
- A new component 'DisplaySettingsToolbar' is added in 'display-settings-toolbar.tsx'. It includes controls for changing the number of items per page, the offset, and the maximum number of pages to show in the block. The toolbar only shows up when the 'inherit' query attribute is set to false.
- The 'DisplaySettingsToolbar' component is then integrated into the main 'edit.tsx' file through 'ToolbarControls'.
- Styles have also been added to 'editor.scss' to ensure the popover content of the display settings toolbar has an appropriate minimum width.
* Mini Cart: Add an icon setting with 3 alternative icon options. Closeswoocommerce/woocommerce-blocks#8556.
* Mini Cart: Fix Mini-cart icons in the toggle setting.
* Minor type fixes.
* Clean up type definitions.
* Move alt icon logic to a separate function.
* Fix cart icons sizes
* Add a negative margin to the mini cart icon
* 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
* 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.
* 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
* 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>
* 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
* 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>
* 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
* 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>