Merge remote-tracking branch 'origin/trunk' into tweak/loading-indicator-tax-task-store-location
This commit is contained in:
commit
dc2c4e7c48
|
@ -1,50 +0,0 @@
|
||||||
name: Build release asset
|
|
||||||
on:
|
|
||||||
release:
|
|
||||||
types: [published]
|
|
||||||
|
|
||||||
permissions: {}
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
name: Build release asset
|
|
||||||
runs-on: ubuntu-20.04
|
|
||||||
permissions:
|
|
||||||
contents: write
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Setup WooCommerce Monorepo
|
|
||||||
uses: ./.github/actions/setup-woocommerce-monorepo
|
|
||||||
with:
|
|
||||||
build: false
|
|
||||||
|
|
||||||
- name: Build zip
|
|
||||||
working-directory: plugins/woocommerce
|
|
||||||
run: bash bin/build-zip.sh
|
|
||||||
|
|
||||||
- name: Upload release asset
|
|
||||||
uses: actions/upload-release-asset@v1
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
with:
|
|
||||||
upload_url: ${{ github.event.release.upload_url }}
|
|
||||||
asset_path: plugins/woocommerce/woocommerce.zip
|
|
||||||
asset_name: woocommerce.zip
|
|
||||||
asset_content_type: application/zip
|
|
||||||
|
|
||||||
|
|
||||||
update-code-reference:
|
|
||||||
if: github.event.release.prerelease == false && github.event.release.draft == false && github.repository_owner == 'woocommerce'
|
|
||||||
name: Update Code Reference
|
|
||||||
needs: build
|
|
||||||
runs-on: ubuntu-20.04
|
|
||||||
steps:
|
|
||||||
- name: Invoke Code Reference build and deploy workflow
|
|
||||||
uses: aurelien-baudet/workflow-dispatch@v2
|
|
||||||
with:
|
|
||||||
workflow: GitHub Pages deploy
|
|
||||||
repo: woocommerce/code-reference
|
|
||||||
token: ${{ secrets.CUSTOM_GH_TOKEN }}
|
|
||||||
ref: refs/heads/trunk
|
|
||||||
inputs: '{ "version": "${{ github.event.release.tag_name }}" }'
|
|
|
@ -9,8 +9,6 @@ defaults:
|
||||||
concurrency:
|
concurrency:
|
||||||
group: ${{ github.workflow }}-${{ github.ref }}
|
group: ${{ github.workflow }}-${{ github.ref }}
|
||||||
cancel-in-progress: true
|
cancel-in-progress: true
|
||||||
env:
|
|
||||||
PHPCS: ./plugins/woocommerce/vendor/bin/phpcs # Run WooCommerce phpcs setup in phpcs-changed instead of default
|
|
||||||
|
|
||||||
permissions: {}
|
permissions: {}
|
||||||
|
|
||||||
|
@ -30,6 +28,7 @@ jobs:
|
||||||
id: changed-files
|
id: changed-files
|
||||||
uses: tj-actions/changed-files@v32
|
uses: tj-actions/changed-files@v32
|
||||||
with:
|
with:
|
||||||
|
path: plugins/woocommerce
|
||||||
files: |
|
files: |
|
||||||
**/*.php
|
**/*.php
|
||||||
|
|
||||||
|
@ -41,6 +40,7 @@ jobs:
|
||||||
|
|
||||||
- name: Tool versions
|
- name: Tool versions
|
||||||
if: steps.changed-files.outputs.any_changed == 'true'
|
if: steps.changed-files.outputs.any_changed == 'true'
|
||||||
|
working-directory: plugins/woocommerce
|
||||||
run: |
|
run: |
|
||||||
php --version
|
php --version
|
||||||
composer --version
|
composer --version
|
||||||
|
@ -48,6 +48,7 @@ jobs:
|
||||||
|
|
||||||
- name: Run PHPCS
|
- name: Run PHPCS
|
||||||
if: steps.changed-files.outputs.any_changed == 'true'
|
if: steps.changed-files.outputs.any_changed == 'true'
|
||||||
|
working-directory: plugins/woocommerce
|
||||||
run: |
|
run: |
|
||||||
HEAD_REF=$(git rev-parse HEAD)
|
HEAD_REF=$(git rev-parse HEAD)
|
||||||
git checkout $HEAD_REF
|
git checkout $HEAD_REF
|
||||||
|
|
|
@ -20,6 +20,10 @@ jobs:
|
||||||
- name: Setup WooCommerce Monorepo
|
- name: Setup WooCommerce Monorepo
|
||||||
uses: ./.github/actions/setup-woocommerce-monorepo
|
uses: ./.github/actions/setup-woocommerce-monorepo
|
||||||
|
|
||||||
|
- name: Lint
|
||||||
|
working-directory: plugins/woocommerce-beta-tester
|
||||||
|
run: composer run phpcs
|
||||||
|
|
||||||
- name: Build WooCommerce Beta Tester Zip
|
- name: Build WooCommerce Beta Tester Zip
|
||||||
working-directory: plugins/woocommerce-beta-tester
|
working-directory: plugins/woocommerce-beta-tester
|
||||||
run: pnpm build:zip
|
run: pnpm build:zip
|
||||||
|
|
|
@ -1,5 +1,97 @@
|
||||||
== Changelog ==
|
== Changelog ==
|
||||||
|
|
||||||
|
= 8.0.1 2023-08-09 =
|
||||||
|
|
||||||
|
* Fix - bump WooCommerce blocks version to 10.6.5 [#39642](https://github.com/woocommerce/woocommerce/pull/39642)
|
||||||
|
|
||||||
|
|
||||||
|
= 8.0.0 2023-08-08 =
|
||||||
|
|
||||||
|
**WooCommerce**
|
||||||
|
|
||||||
|
* Fix - Set the order table exist options value when its not present for smooth upgradation from lower WC versions. [#39616](https://github.com/woocommerce/woocommerce/pull/39616)
|
||||||
|
* Fix - Add derivative features to legacy list so that warning is not generated for them. [#39537](https://github.com/woocommerce/woocommerce/pull/39537)
|
||||||
|
* Fix - Dequeue blocktheme styles on WooCommerce Admin pages when product block editor is enabled. [#39478](https://github.com/woocommerce/woocommerce/pull/39478)
|
||||||
|
* Fix - Do not disable "Used for variations" checkbox on attribute. [#39502](https://github.com/woocommerce/woocommerce/pull/39502)
|
||||||
|
* Fix - Adds a grace period during which email verification will not be needed before the order confirmation (or payment) page is rendered. [#39191](https://github.com/woocommerce/woocommerce/pull/39191)
|
||||||
|
* Fix - Fix turn off the new block experience when tracking is turned off [#39317](https://github.com/woocommerce/woocommerce/pull/39317)
|
||||||
|
* Fix - Restore woocommerce_variations_added jQuery trigger. [#39301](https://github.com/woocommerce/woocommerce/pull/39301)
|
||||||
|
* Fix - Add wrapper to the content generated by wc_empty_cart_message [[#38738]](https://github.com/woocommerce/woocommerce/pull/38738)
|
||||||
|
* Fix - Allow to add custom metabox to custom order edit page by setting the correct screen id. [[#38938]](https://github.com/woocommerce/woocommerce/pull/38938)
|
||||||
|
* Fix - Bootstrap server side block definitions [[#39027]](https://github.com/woocommerce/woocommerce/pull/39027)
|
||||||
|
* Fix - Comment: Fix "Used for variations" checkbox being disabled on Variable products [[#39106]](https://github.com/woocommerce/woocommerce/pull/39106)
|
||||||
|
* Fix - Convert DatabaseUtil::get_index_columns() to use SHOW INDEX FROM instead of INFORMATION_SCHEMA query [[#36427]](https://github.com/woocommerce/woocommerce/pull/36427)
|
||||||
|
* Fix - Decrease product total sales when an order is reversed [[#37842]](https://github.com/woocommerce/woocommerce/pull/37842)
|
||||||
|
* Fix - Do not show "Adding new attribute failed" error message when loading of product screens is interrupted by page unload. [[#38815]](https://github.com/woocommerce/woocommerce/pull/38815)
|
||||||
|
* Fix - do not use image size cache while in customizer [[#38875]](https://github.com/woocommerce/woocommerce/pull/38875)
|
||||||
|
* Fix - Fix attribute taxonomy templates when a templates for specific product attribute exists. [[#37552]](https://github.com/woocommerce/woocommerce/pull/37552)
|
||||||
|
* Fix - Fixed failing shipping zones tests and cleaned up locators [[#38949]](https://github.com/woocommerce/woocommerce/pull/38949)
|
||||||
|
* Fix - Fix grey background when menu is collapsed #38887 [[#38941]](https://github.com/woocommerce/woocommerce/pull/38941)
|
||||||
|
* Fix - Fix links under "Help" panel on Home screen [[#38817]](https://github.com/woocommerce/woocommerce/pull/38817)
|
||||||
|
* Fix - Fix Minimum Requirements in readme.txt file [[#39078]](https://github.com/woocommerce/woocommerce/pull/39078)
|
||||||
|
* Fix - Fix the issue of stores sending frequent Helper API requests when the store databases disk is full. [[#37378]](https://github.com/woocommerce/woocommerce/pull/37378)
|
||||||
|
* Fix - Fix the layout of View Cart link on the posts/pages [[#38950]](https://github.com/woocommerce/woocommerce/pull/38950)
|
||||||
|
* Fix - Fix undismissable store alert when using language localization [[#38967]](https://github.com/woocommerce/woocommerce/pull/38967)
|
||||||
|
* Fix - Fix unexpected gap on ipad and ipad mini [[#39108]](https://github.com/woocommerce/woocommerce/pull/39108)
|
||||||
|
* Fix - Linting fix to webpack config. [[#38920]](https://github.com/woocommerce/woocommerce/pull/38920)
|
||||||
|
* Fix - Make `WC_Order::get_item_subtotal()` always return a float. [[#36760]](https://github.com/woocommerce/woocommerce/pull/36760)
|
||||||
|
* Fix - OrdersTableDataStore: capture and log errors when populating order properties [[#38840]](https://github.com/woocommerce/woocommerce/pull/38840)
|
||||||
|
* Fix - Revert "Always show pricing group fields, disable if not available for a product type" [[#38964]](https://github.com/woocommerce/woocommerce/pull/38964)
|
||||||
|
* Fix - Support dynamic prop setting to use in refunds for setting correct props. [[#39219]](https://github.com/woocommerce/woocommerce/pull/39219)
|
||||||
|
* Fix - Trigger "woocommerce_newly_installed" hook for new installations [[#38694]](https://github.com/woocommerce/woocommerce/pull/38694)
|
||||||
|
* Fix - When dormant customer accounts are removed, their content should be preserved. [[#38837]](https://github.com/woocommerce/woocommerce/pull/38837)
|
||||||
|
* Fix - [HPOS] Backfill to post table only after order has persisted in orders table. [[#39196]](https://github.com/woocommerce/woocommerce/pull/39196)
|
||||||
|
* Add - Add support for BG, CZ, HR, HU, RO and SE in WCPay [[#38109]](https://github.com/woocommerce/woocommerce/pull/38109)
|
||||||
|
* Add - Add synchronization of deleted orders for HPOS [[#37050]](https://github.com/woocommerce/woocommerce/pull/37050)
|
||||||
|
* Add - Add Variations tab to Product block editor [[#38921]](https://github.com/woocommerce/woocommerce/pull/38921)
|
||||||
|
* Add - Allow registered React-powered pages to specify a parent navigation menu item to highlight when active. [[#39116]](https://github.com/woocommerce/woocommerce/pull/39116)
|
||||||
|
* Add - Introduce the add and edit view Tracks events in the new form [[#39186]](https://github.com/woocommerce/woocommerce/pull/39186)
|
||||||
|
* Add - Register woocommerce/product-variations-fields block [[#39038]](https://github.com/woocommerce/woocommerce/pull/39038)
|
||||||
|
* Add - Removed Avalara from Tax task list item [[#39238]](https://github.com/woocommerce/woocommerce/pull/39238)
|
||||||
|
* Add - Show create campaign button when there are campaign types in marketing page. [[#38825]](https://github.com/woocommerce/woocommerce/pull/38825)
|
||||||
|
* Update - Update WooCommerce Blocks to 10.6.4 [#39582](https://github.com/woocommerce/woocommerce/pull/39582)
|
||||||
|
* Update - Update WooCommerce Blocks to 10.6.3 [#39560](https://github.com/woocommerce/woocommerce/pull/39560)
|
||||||
|
* Update - Update WooCommerce Blocks to 10.6.2 [#39492](https://github.com/woocommerce/woocommerce/pull/39492)
|
||||||
|
* Update - Fix grammar in data-sharing agreement copy [#39327](https://github.com/woocommerce/woocommerce/pull/39327)
|
||||||
|
* Update - Update WooCommerce Blocks to 10.6.1 [#39299](https://github.com/woocommerce/woocommerce/pull/39299)
|
||||||
|
* Update - Add Klaviyo into onboarding marketing task list. [[#39087]](https://github.com/woocommerce/woocommerce/pull/39087)
|
||||||
|
* Update - Analytics API: A new filter_empty parameter that allows to remove from result customers with given empty fields [[#38827]](https://github.com/woocommerce/woocommerce/pull/38827)
|
||||||
|
* Update - Analytics API: Search for customers by all of the available fields instead of having to choose one [[#38628]](https://github.com/woocommerce/woocommerce/pull/38628)
|
||||||
|
* Update - Branding rollout - change WooCommerce Payments to WooPayments [[#39188]](https://github.com/woocommerce/woocommerce/pull/39188)
|
||||||
|
* Update - Change button text from "Install plugin" to "Install extension" in Marketing page. [[#39130]](https://github.com/woocommerce/woocommerce/pull/39130)
|
||||||
|
* Update - Remove Tiktok from plugin suggestion list [[#39135]](https://github.com/woocommerce/woocommerce/pull/39135)
|
||||||
|
* Update - Update the call to marketing extensions recommendations API from version 1.2 to version 1.3 with new recommendation Klaviyo. [[#38974]](https://github.com/woocommerce/woocommerce/pull/38974)
|
||||||
|
* Update - Update WooCommerce Blocks to 10.6.0 [[#39144]](https://github.com/woocommerce/woocommerce/pull/39144)
|
||||||
|
* Update - Use wp_json_encode instead of print_r in output for HPOS-related WP CLI commands. [[#38699]](https://github.com/woocommerce/woocommerce/pull/38699)
|
||||||
|
* Dev - Add more assertions to `can add custom product attributes` E2E test. [[#39139]](https://github.com/woocommerce/woocommerce/pull/39139)
|
||||||
|
* Dev - Add pnpm commands for easier PHP linting [[#38727]](https://github.com/woocommerce/woocommerce/pull/38727)
|
||||||
|
* Dev - Cleanup global state after testing `wc_load_cart()`. [[#39136]](https://github.com/woocommerce/woocommerce/pull/39136)
|
||||||
|
* Dev - Enable HPOS through the `wp option` command. [[#39095]](https://github.com/woocommerce/woocommerce/pull/39095)
|
||||||
|
* Dev - Ensure `can discard industry changes when navigating back to "Store Details"'` can run independent from previous tests [[#38715]](https://github.com/woocommerce/woocommerce/pull/38715)
|
||||||
|
* Dev - Fix skipping of core profiler in page-loads.spec.js. [[#39084]](https://github.com/woocommerce/woocommerce/pull/39084)
|
||||||
|
* Dev - Improvements to the DI related unit testing infrastructure [[#38849]](https://github.com/woocommerce/woocommerce/pull/38849)
|
||||||
|
* Dev - Replace deprecated page methods. [[#38344]](https://github.com/woocommerce/woocommerce/pull/38344)
|
||||||
|
* Dev - Skip failing e2e test preventing PRs being merged. GH fails but local works [[#38855]](https://github.com/woocommerce/woocommerce/pull/38855)
|
||||||
|
* Dev - Update locators in `order-emails` and `order-email-receiving` specs so that they pass on WP 6.3. [[#39159]](https://github.com/woocommerce/woocommerce/pull/39159)
|
||||||
|
* Dev - Update locators in `order-emails` spec, and use the latest version of WP Mail Logging. [[#39013]](https://github.com/woocommerce/woocommerce/pull/39013)
|
||||||
|
* Dev - Update pnpm monorepo-wide to 8.6.5 [[#38990]](https://github.com/woocommerce/woocommerce/pull/38990)
|
||||||
|
* Dev - Update `wp-env` to version 8.2.0. [[#39100]](https://github.com/woocommerce/woocommerce/pull/39100)
|
||||||
|
* Dev - Use grunt-contrib-uglify-es to handle legacy es6" [[#38342]](https://github.com/woocommerce/woocommerce/pull/38342)
|
||||||
|
* Tweak - Add autoFocus attribute to product-name-field block [[#39050]](https://github.com/woocommerce/woocommerce/pull/39050)
|
||||||
|
* Tweak - Corrects a minor issue (incorrect HTML markup) in the System Status Report. [[#39053]](https://github.com/woocommerce/woocommerce/pull/39053)
|
||||||
|
* Tweak - Remove letter-spacing from the core profiler headers; Use 500 for font-weight. [[#39042]](https://github.com/woocommerce/woocommerce/pull/39042)
|
||||||
|
* Tweak - Replace "Proceed" with "Continue" to be more consistent [[#38961]](https://github.com/woocommerce/woocommerce/pull/38961)
|
||||||
|
* Tweak - Restore user's plugin selection when there is an installation error [[#38922]](https://github.com/woocommerce/woocommerce/pull/38922)
|
||||||
|
* Tweak - Update CSS styles for the core profiler header [[#39059]](https://github.com/woocommerce/woocommerce/pull/39059)
|
||||||
|
* Tweak - Use existing table instead of 'DUAL' to support hosts which do not support 'DUAL'. [[#39111]](https://github.com/woocommerce/woocommerce/pull/39111)
|
||||||
|
* Tweak - When detecting which plugins are WooCommerce-aware, improve accuracy by ignoring cached plugin data. [[#38836]](https://github.com/woocommerce/woocommerce/pull/38836)
|
||||||
|
* Tweak - When displaying partial consumer keys in the REST API settings, replace ellipses with asterisks.
|
||||||
|
* Enhancement - Add action for 'order_edit_form_top' as a replacement to edit_form_top for HPOS. [[#39165]](https://github.com/woocommerce/woocommerce/pull/39165)
|
||||||
|
* Enhancement - Add filter `woocommerce_redirect_order_location` for consistency with posts and HPOS. [[#39193]](https://github.com/woocommerce/woocommerce/pull/39193)
|
||||||
|
* Enhancement - New product block editor modal text enhancements [[#39055]](https://github.com/woocommerce/woocommerce/pull/39055)
|
||||||
|
* Enhancement - Refresh UX to enable HPOS to make it user friendly. [[#38993]](https://github.com/woocommerce/woocommerce/pull/38993)
|
||||||
|
|
||||||
|
|
||||||
= 7.9.0 2023-07-17 =
|
= 7.9.0 2023-07-17 =
|
||||||
|
|
||||||
**WooCommerce**
|
**WooCommerce**
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
Significance: minor
|
||||||
|
Type: add
|
||||||
|
|
||||||
|
Add catalog_visibility property to the Product type
|
|
@ -0,0 +1,4 @@
|
||||||
|
Significance: minor
|
||||||
|
Type: add
|
||||||
|
|
||||||
|
Add default attributes property to the Product type
|
|
@ -0,0 +1,4 @@
|
||||||
|
Significance: patch
|
||||||
|
Type: update
|
||||||
|
|
||||||
|
Update ProductAttributeTerms action types and include it as part of @wordpress/data module
|
|
@ -0,0 +1,4 @@
|
||||||
|
Significance: patch
|
||||||
|
Type: update
|
||||||
|
|
||||||
|
Add new user preference to UserPreferences type.
|
|
@ -1,8 +1,16 @@
|
||||||
|
/**
|
||||||
|
* External dependencies
|
||||||
|
*/
|
||||||
|
import { SelectFromMap } from '@automattic/data-stores';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
*/
|
*/
|
||||||
import { STORE_NAME, WC_PRODUCT_ATTRIBUTE_TERMS_NAMESPACE } from './constants';
|
import { STORE_NAME, WC_PRODUCT_ATTRIBUTE_TERMS_NAMESPACE } from './constants';
|
||||||
import { createCrudDataStore } from '../crud';
|
import { createCrudDataStore } from '../crud';
|
||||||
|
import { ActionDispatchers, ProductAttributeTermsSelectors } from './types';
|
||||||
|
import { WPDataSelectors } from '../types';
|
||||||
|
import { PromiseifySelectors } from '../types/promiseify-selectors';
|
||||||
|
|
||||||
createCrudDataStore( {
|
createCrudDataStore( {
|
||||||
storeName: STORE_NAME,
|
storeName: STORE_NAME,
|
||||||
|
@ -12,3 +20,14 @@ createCrudDataStore( {
|
||||||
} );
|
} );
|
||||||
|
|
||||||
export const EXPERIMENTAL_PRODUCT_ATTRIBUTE_TERMS_STORE_NAME = STORE_NAME;
|
export const EXPERIMENTAL_PRODUCT_ATTRIBUTE_TERMS_STORE_NAME = STORE_NAME;
|
||||||
|
|
||||||
|
declare module '@wordpress/data' {
|
||||||
|
// TODO: convert action.js to TS
|
||||||
|
function dispatch( key: typeof STORE_NAME ): ActionDispatchers;
|
||||||
|
function select(
|
||||||
|
key: typeof STORE_NAME
|
||||||
|
): SelectFromMap< ProductAttributeTermsSelectors > & WPDataSelectors;
|
||||||
|
function resolveSelect(
|
||||||
|
key: typeof STORE_NAME
|
||||||
|
): PromiseifySelectors< SelectFromMap< ProductAttributeTermsSelectors > >;
|
||||||
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ type MutableProperties = Partial<
|
||||||
|
|
||||||
type ProductAttributeTermActions = CrudActions<
|
type ProductAttributeTermActions = CrudActions<
|
||||||
'ProductAttributeTerm',
|
'ProductAttributeTerm',
|
||||||
ProductAttributeTerm,
|
ProductAttributeTerm & { attribute_id: string },
|
||||||
MutableProperties,
|
MutableProperties,
|
||||||
'name'
|
'name'
|
||||||
>;
|
>;
|
||||||
|
|
|
@ -36,12 +36,36 @@ export type ProductAttribute = {
|
||||||
options: string[];
|
options: string[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Product - Default attributes properties
|
||||||
|
*/
|
||||||
|
export type ProductDefaultAttribute = {
|
||||||
|
/**
|
||||||
|
* Attribute ID.
|
||||||
|
*/
|
||||||
|
id: number;
|
||||||
|
/**
|
||||||
|
* Attribute name.
|
||||||
|
*/
|
||||||
|
name: string;
|
||||||
|
/**
|
||||||
|
* Selected attribute term name.
|
||||||
|
*/
|
||||||
|
option: string;
|
||||||
|
};
|
||||||
|
|
||||||
export type ProductDimensions = {
|
export type ProductDimensions = {
|
||||||
width: string;
|
width: string;
|
||||||
height: string;
|
height: string;
|
||||||
length: string;
|
length: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type ProductCatalogVisibility =
|
||||||
|
| 'visible'
|
||||||
|
| 'catalog'
|
||||||
|
| 'search'
|
||||||
|
| 'hidden';
|
||||||
|
|
||||||
export type Product< Status = ProductStatus, Type = ProductType > = Omit<
|
export type Product< Status = ProductStatus, Type = ProductType > = Omit<
|
||||||
Schema.Post,
|
Schema.Post,
|
||||||
'status' | 'categories'
|
'status' | 'categories'
|
||||||
|
@ -53,12 +77,14 @@ export type Product< Status = ProductStatus, Type = ProductType > = Omit<
|
||||||
backorders_allowed: boolean;
|
backorders_allowed: boolean;
|
||||||
button_text: string;
|
button_text: string;
|
||||||
categories: Pick< ProductCategory, 'id' | 'name' | 'slug' >[];
|
categories: Pick< ProductCategory, 'id' | 'name' | 'slug' >[];
|
||||||
|
catalog_visibility: ProductCatalogVisibility;
|
||||||
date_created: string;
|
date_created: string;
|
||||||
date_created_gmt: string;
|
date_created_gmt: string;
|
||||||
date_modified: string;
|
date_modified: string;
|
||||||
date_modified_gmt: string;
|
date_modified_gmt: string;
|
||||||
date_on_sale_from_gmt: string | null;
|
date_on_sale_from_gmt: string | null;
|
||||||
date_on_sale_to_gmt: string | null;
|
date_on_sale_to_gmt: string | null;
|
||||||
|
default_attributes: ProductDefaultAttribute[];
|
||||||
description: string;
|
description: string;
|
||||||
dimensions: ProductDimensions;
|
dimensions: ProductDimensions;
|
||||||
download_expiry: number;
|
download_expiry: number;
|
||||||
|
|
|
@ -26,6 +26,7 @@ export type UserPreferences = {
|
||||||
};
|
};
|
||||||
taxes_report_columns?: string;
|
taxes_report_columns?: string;
|
||||||
variable_product_tour_shown?: string;
|
variable_product_tour_shown?: string;
|
||||||
|
variable_product_block_tour_shown?: string;
|
||||||
variations_report_columns?: string;
|
variations_report_columns?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
Significance: minor
|
||||||
|
Type: add
|
||||||
|
|
||||||
|
Add support to attribute input field for creating global attributes by default and enable this for variation blocks.
|
|
@ -0,0 +1,4 @@
|
||||||
|
Significance: minor
|
||||||
|
Type: add
|
||||||
|
|
||||||
|
Create product search and catalog visibility blocks
|
|
@ -0,0 +1,4 @@
|
||||||
|
Significance: minor
|
||||||
|
Type: add
|
||||||
|
|
||||||
|
Focus the first attribute field when opening the modal
|
|
@ -0,0 +1,4 @@
|
||||||
|
Significance: minor
|
||||||
|
Type: add
|
||||||
|
|
||||||
|
Add set default value checkbox to the edit attribute options modal
|
|
@ -0,0 +1,4 @@
|
||||||
|
Significance: minor
|
||||||
|
Type: add
|
||||||
|
|
||||||
|
Add product variation items block
|
|
@ -0,0 +1,4 @@
|
||||||
|
Significance: minor
|
||||||
|
Type: dev
|
||||||
|
|
||||||
|
[Product Block Editor] Remove additional create attribute term modal
|
|
@ -0,0 +1,4 @@
|
||||||
|
Significance: patch
|
||||||
|
Type: tweak
|
||||||
|
Comment: Small change to fix bug in previous PR.
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
Significance: minor
|
||||||
|
Type: add
|
||||||
|
|
||||||
|
Add isInSelectedTab context to tab blocks for use in nested blocks.
|
|
@ -0,0 +1,4 @@
|
||||||
|
Significance: minor
|
||||||
|
Type: update
|
||||||
|
|
||||||
|
Update variation options block to auto create variations upon options update.
|
|
@ -0,0 +1,31 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||||
|
"apiVersion": 2,
|
||||||
|
"name": "woocommerce/product-catalog-visibility-field",
|
||||||
|
"description": "A checkbox to manage the catalog visibility of the product.",
|
||||||
|
"title": "Product catalog visibility",
|
||||||
|
"category": "widgets",
|
||||||
|
"keywords": [ "products", "catalog" ],
|
||||||
|
"textdomain": "default",
|
||||||
|
"attributes": {
|
||||||
|
"label": {
|
||||||
|
"type": "string",
|
||||||
|
"__experimentalRole": "content"
|
||||||
|
},
|
||||||
|
"visibilty": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": [ "visible", "catalog", "search", "hidden" ],
|
||||||
|
"default": "visible"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"supports": {
|
||||||
|
"align": false,
|
||||||
|
"html": false,
|
||||||
|
"multiple": false,
|
||||||
|
"reusable": false,
|
||||||
|
"inserter": false,
|
||||||
|
"lock": false,
|
||||||
|
"__experimentalToolbar": false
|
||||||
|
},
|
||||||
|
"editorStyle": "file:./editor.css"
|
||||||
|
}
|
|
@ -0,0 +1,63 @@
|
||||||
|
/**
|
||||||
|
* External dependencies
|
||||||
|
*/
|
||||||
|
import { useBlockProps } from '@wordpress/block-editor';
|
||||||
|
import { CheckboxControl } from '@wordpress/components';
|
||||||
|
import { useEntityProp } from '@wordpress/core-data';
|
||||||
|
import { createElement } from '@wordpress/element';
|
||||||
|
import { Product } from '@woocommerce/data';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal dependencies
|
||||||
|
*/
|
||||||
|
import { CatalogVisibilityBlockAttributes } from './types';
|
||||||
|
|
||||||
|
export function Edit( {
|
||||||
|
attributes,
|
||||||
|
}: {
|
||||||
|
attributes: CatalogVisibilityBlockAttributes;
|
||||||
|
} ) {
|
||||||
|
const { label, visibilty } = attributes;
|
||||||
|
|
||||||
|
const blockProps = useBlockProps();
|
||||||
|
|
||||||
|
const [ catalogVisibility, setCatalogVisibility ] = useEntityProp<
|
||||||
|
Product[ 'catalog_visibility' ]
|
||||||
|
>( 'postType', 'product', 'catalog_visibility' );
|
||||||
|
|
||||||
|
const checked =
|
||||||
|
catalogVisibility === visibilty || catalogVisibility === 'hidden';
|
||||||
|
|
||||||
|
function handleChange( selected: boolean ) {
|
||||||
|
if ( selected ) {
|
||||||
|
if ( catalogVisibility === 'visible' ) {
|
||||||
|
setCatalogVisibility( visibilty );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setCatalogVisibility( 'hidden' );
|
||||||
|
} else {
|
||||||
|
if ( catalogVisibility === 'hidden' ) {
|
||||||
|
if ( visibilty === 'catalog' ) {
|
||||||
|
setCatalogVisibility( 'search' );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ( visibilty === 'search' ) {
|
||||||
|
setCatalogVisibility( 'catalog' );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setCatalogVisibility( 'visible' );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div { ...blockProps }>
|
||||||
|
<CheckboxControl
|
||||||
|
label={ label }
|
||||||
|
checked={ checked }
|
||||||
|
onChange={ handleChange }
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
/**
|
||||||
|
* External dependencies
|
||||||
|
*/
|
||||||
|
import { BlockConfiguration } from '@wordpress/blocks';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal dependencies
|
||||||
|
*/
|
||||||
|
import { initBlock } from '../../utils/init-block';
|
||||||
|
import blockConfiguration from './block.json';
|
||||||
|
import { Edit } from './edit';
|
||||||
|
import { CatalogVisibilityBlockAttributes } from './types';
|
||||||
|
|
||||||
|
const { name, ...metadata } =
|
||||||
|
blockConfiguration as BlockConfiguration< CatalogVisibilityBlockAttributes >;
|
||||||
|
|
||||||
|
export { metadata, name };
|
||||||
|
|
||||||
|
export const settings: Partial<
|
||||||
|
BlockConfiguration< CatalogVisibilityBlockAttributes >
|
||||||
|
> = {
|
||||||
|
example: {},
|
||||||
|
edit: Edit,
|
||||||
|
};
|
||||||
|
|
||||||
|
export function init() {
|
||||||
|
return initBlock( { name, metadata, settings } );
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
/**
|
||||||
|
* External dependencies
|
||||||
|
*/
|
||||||
|
import { Product } from '@woocommerce/data';
|
||||||
|
import { BlockAttributes } from '@wordpress/blocks';
|
||||||
|
|
||||||
|
export interface CatalogVisibilityBlockAttributes extends BlockAttributes {
|
||||||
|
label: string;
|
||||||
|
visibilty: Product[ 'catalog_visibility' ];
|
||||||
|
}
|
|
@ -1,11 +1,16 @@
|
||||||
|
/**
|
||||||
|
* External dependencies
|
||||||
|
*/
|
||||||
|
import { BlockConfiguration } from '@wordpress/blocks';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
*/
|
*/
|
||||||
import initBlock from '../../utils/init-block';
|
import { initBlock } from '../../utils/init-block';
|
||||||
import metadata from './block.json';
|
import blockConfiguration from './block.json';
|
||||||
import { Edit } from './edit';
|
import { Edit } from './edit';
|
||||||
|
|
||||||
const { name } = metadata;
|
const { name, ...metadata } = blockConfiguration as BlockConfiguration;
|
||||||
|
|
||||||
export { metadata, name };
|
export { metadata, name };
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,16 @@
|
||||||
|
/**
|
||||||
|
* External dependencies
|
||||||
|
*/
|
||||||
|
import { BlockConfiguration } from '@wordpress/blocks';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
*/
|
*/
|
||||||
import initBlock from '../../utils/init-block';
|
import { initBlock } from '../../utils/init-block';
|
||||||
import metadata from './block.json';
|
import blockConfiguration from './block.json';
|
||||||
import { Edit } from './edit';
|
import { Edit } from './edit';
|
||||||
|
|
||||||
const { name } = metadata;
|
const { name, ...metadata } = blockConfiguration as BlockConfiguration;
|
||||||
|
|
||||||
export { metadata, name };
|
export { metadata, name };
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
export { init as initCatalogVisibility } from './catalog-visibility';
|
||||||
export { init as initCategory } from './category';
|
export { init as initCategory } from './category';
|
||||||
export { init as initCheckbox } from './checkbox';
|
export { init as initCheckbox } from './checkbox';
|
||||||
export { init as initCollapsible } from './collapsible';
|
export { init as initCollapsible } from './collapsible';
|
||||||
|
@ -22,4 +23,5 @@ export { init as initToggle } from './toggle';
|
||||||
export { init as attributesInit } from './attributes';
|
export { init as attributesInit } from './attributes';
|
||||||
export { init as initVariations } from './variations';
|
export { init as initVariations } from './variations';
|
||||||
export { init as initRequirePassword } from './password';
|
export { init as initRequirePassword } from './password';
|
||||||
|
export { init as initVariationItems } from './variation-items';
|
||||||
export { init as initVariationOptions } from './variation-options';
|
export { init as initVariationOptions } from './variation-options';
|
||||||
|
|
|
@ -7,7 +7,7 @@ import { BlockConfiguration } from '@wordpress/blocks';
|
||||||
/**
|
/**
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
*/
|
*/
|
||||||
import { initBlock } from '../../utils/init-blocks';
|
import { initBlock } from '../../utils/init-block';
|
||||||
import blockConfiguration from './block.json';
|
import blockConfiguration from './block.json';
|
||||||
import { Edit } from './edit';
|
import { Edit } from './edit';
|
||||||
import { InventoryEmailBlockAttributes } from './types';
|
import { InventoryEmailBlockAttributes } from './types';
|
||||||
|
|
|
@ -7,7 +7,7 @@ import { BlockConfiguration } from '@wordpress/blocks';
|
||||||
/**
|
/**
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
*/
|
*/
|
||||||
import { initBlock } from '../../utils/init-blocks';
|
import { initBlock } from '../../utils/init-block';
|
||||||
import blockConfiguration from './block.json';
|
import blockConfiguration from './block.json';
|
||||||
import { Edit } from './edit';
|
import { Edit } from './edit';
|
||||||
import { TrackInventoryBlockAttributes } from './types';
|
import { TrackInventoryBlockAttributes } from './types';
|
||||||
|
|
|
@ -1,11 +1,16 @@
|
||||||
|
/**
|
||||||
|
* External dependencies
|
||||||
|
*/
|
||||||
|
import { BlockConfiguration } from '@wordpress/blocks';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
*/
|
*/
|
||||||
import initBlock from '../../utils/init-block';
|
import { initBlock } from '../../utils/init-block';
|
||||||
import metadata from './block.json';
|
import blockConfiguration from './block.json';
|
||||||
import { Edit } from './edit';
|
import { Edit } from './edit';
|
||||||
|
|
||||||
const { name } = metadata;
|
const { name, ...metadata } = blockConfiguration as BlockConfiguration;
|
||||||
|
|
||||||
export { metadata, name };
|
export { metadata, name };
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { BlockConfiguration } from '@wordpress/blocks';
|
||||||
/**
|
/**
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
*/
|
*/
|
||||||
import { initBlock } from '../../utils/init-blocks';
|
import { initBlock } from '../../utils/init-block';
|
||||||
import blockConfiguration from './block.json';
|
import blockConfiguration from './block.json';
|
||||||
import { Edit } from './edit';
|
import { Edit } from './edit';
|
||||||
import { RequirePasswordBlockAttributes } from './types';
|
import { RequirePasswordBlockAttributes } from './types';
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { BlockConfiguration } from '@wordpress/blocks';
|
||||||
/**
|
/**
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
*/
|
*/
|
||||||
import { initBlock } from '../../utils/init-blocks';
|
import { initBlock } from '../../utils/init-block';
|
||||||
import blockConfiguration from './block.json';
|
import blockConfiguration from './block.json';
|
||||||
import { Edit } from './edit';
|
import { Edit } from './edit';
|
||||||
import { PricingBlockAttributes } from './types';
|
import { PricingBlockAttributes } from './types';
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { BlockConfiguration } from '@wordpress/blocks';
|
||||||
/**
|
/**
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
*/
|
*/
|
||||||
import { initBlock } from '../../utils/init-blocks';
|
import { initBlock } from '../../utils/init-block';
|
||||||
import blockConfiguration from './block.json';
|
import blockConfiguration from './block.json';
|
||||||
import { Edit } from './edit';
|
import { Edit } from './edit';
|
||||||
import { RadioBlockAttributes } from './types';
|
import { RadioBlockAttributes } from './types';
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { BlockConfiguration } from '@wordpress/blocks';
|
||||||
/**
|
/**
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
*/
|
*/
|
||||||
import { initBlock } from '../../utils/init-blocks';
|
import { initBlock } from '../../utils/init-block';
|
||||||
import blockConfiguration from './block.json';
|
import blockConfiguration from './block.json';
|
||||||
import { Edit } from './edit';
|
import { Edit } from './edit';
|
||||||
import { SalePriceBlockAttributes } from './types';
|
import { SalePriceBlockAttributes } from './types';
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { BlockConfiguration } from '@wordpress/blocks';
|
||||||
/**
|
/**
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
*/
|
*/
|
||||||
import { initBlock } from '../../utils/init-blocks';
|
import { initBlock } from '../../utils/init-block';
|
||||||
import blockConfiguration from './block.json';
|
import blockConfiguration from './block.json';
|
||||||
import { Edit } from './edit';
|
import { Edit } from './edit';
|
||||||
import { SalePriceBlockAttributes } from './types';
|
import { SalePriceBlockAttributes } from './types';
|
||||||
|
|
|
@ -7,7 +7,7 @@ import { BlockConfiguration } from '@wordpress/blocks';
|
||||||
/**
|
/**
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
*/
|
*/
|
||||||
import { initBlock } from '../../utils/init-blocks';
|
import { initBlock } from '../../utils/init-block';
|
||||||
import blockConfiguration from './block.json';
|
import blockConfiguration from './block.json';
|
||||||
import { Edit } from './edit';
|
import { Edit } from './edit';
|
||||||
import { ScheduleSalePricingBlockAttributes } from './types';
|
import { ScheduleSalePricingBlockAttributes } from './types';
|
||||||
|
|
|
@ -7,7 +7,7 @@ import { BlockConfiguration } from '@wordpress/blocks';
|
||||||
/**
|
/**
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
*/
|
*/
|
||||||
import { initBlock } from '../../utils/init-blocks';
|
import { initBlock } from '../../utils/init-block';
|
||||||
import blockConfiguration from './block.json';
|
import blockConfiguration from './block.json';
|
||||||
import { Edit } from './edit';
|
import { Edit } from './edit';
|
||||||
import { SectionBlockAttributes } from './types';
|
import { SectionBlockAttributes } from './types';
|
||||||
|
|
|
@ -7,7 +7,7 @@ import { BlockConfiguration } from '@wordpress/blocks';
|
||||||
/**
|
/**
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
*/
|
*/
|
||||||
import { initBlock } from '../../utils/init-blocks';
|
import { initBlock } from '../../utils/init-block';
|
||||||
import blockConfiguration from './block.json';
|
import blockConfiguration from './block.json';
|
||||||
import { Edit } from './edit';
|
import { Edit } from './edit';
|
||||||
import { ShippingClassBlockAttributes } from './types';
|
import { ShippingClassBlockAttributes } from './types';
|
||||||
|
|
|
@ -7,7 +7,7 @@ import { BlockConfiguration } from '@wordpress/blocks';
|
||||||
/**
|
/**
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
*/
|
*/
|
||||||
import { initBlock } from '../../utils/init-blocks';
|
import { initBlock } from '../../utils/init-block';
|
||||||
import blockConfiguration from './block.json';
|
import blockConfiguration from './block.json';
|
||||||
import { Edit } from './edit';
|
import { Edit } from './edit';
|
||||||
import { ShippingDimensionsBlockAttributes } from './types';
|
import { ShippingDimensionsBlockAttributes } from './types';
|
||||||
|
|
|
@ -15,4 +15,5 @@
|
||||||
@import 'tab/editor.scss';
|
@import 'tab/editor.scss';
|
||||||
@import 'variations/editor.scss';
|
@import 'variations/editor.scss';
|
||||||
@import 'password/editor.scss';
|
@import 'password/editor.scss';
|
||||||
|
@import 'variation-items/editor.scss';
|
||||||
@import 'variation-options/editor.scss';
|
@import 'variation-options/editor.scss';
|
||||||
|
|
|
@ -27,6 +27,9 @@
|
||||||
"lock": false,
|
"lock": false,
|
||||||
"__experimentalToolbar": false
|
"__experimentalToolbar": false
|
||||||
},
|
},
|
||||||
|
"providesContext": {
|
||||||
|
"isInSelectedTab": "isSelected"
|
||||||
|
},
|
||||||
"usesContext": [ "selectedTab" ],
|
"usesContext": [ "selectedTab" ],
|
||||||
"editorStyle": "file:./editor.css",
|
"editorStyle": "file:./editor.css",
|
||||||
"templateLock": "contentOnly"
|
"templateLock": "contentOnly"
|
||||||
|
|
|
@ -4,25 +4,35 @@
|
||||||
import { InnerBlocks, useBlockProps } from '@wordpress/block-editor';
|
import { InnerBlocks, useBlockProps } from '@wordpress/block-editor';
|
||||||
import classnames from 'classnames';
|
import classnames from 'classnames';
|
||||||
import { createElement } from '@wordpress/element';
|
import { createElement } from '@wordpress/element';
|
||||||
import type { BlockAttributes } from '@wordpress/blocks';
|
import type { BlockAttributes, BlockEditProps } from '@wordpress/blocks';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
*/
|
*/
|
||||||
import { TabButton } from './tab-button';
|
import { TabButton } from './tab-button';
|
||||||
|
|
||||||
|
export interface TabBlockAttributes extends BlockAttributes {
|
||||||
|
id: string;
|
||||||
|
title: string;
|
||||||
|
order: number;
|
||||||
|
isSelected?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
export function Edit( {
|
export function Edit( {
|
||||||
|
setAttributes,
|
||||||
attributes,
|
attributes,
|
||||||
context,
|
context,
|
||||||
}: {
|
}: BlockEditProps< TabBlockAttributes > & {
|
||||||
attributes: BlockAttributes;
|
|
||||||
context?: {
|
context?: {
|
||||||
selectedTab?: string | null;
|
selectedTab?: string | null;
|
||||||
};
|
};
|
||||||
} ) {
|
} ) {
|
||||||
const blockProps = useBlockProps();
|
const blockProps = useBlockProps();
|
||||||
const { id, title, order } = attributes;
|
const { id, title, order, isSelected: contextIsSelected } = attributes;
|
||||||
const isSelected = context?.selectedTab === id;
|
const isSelected = context?.selectedTab === id;
|
||||||
|
if ( isSelected !== contextIsSelected ) {
|
||||||
|
setAttributes( { isSelected } );
|
||||||
|
}
|
||||||
|
|
||||||
const classes = classnames( 'wp-block-woocommerce-product-tab__content', {
|
const classes = classnames( 'wp-block-woocommerce-product-tab__content', {
|
||||||
'is-selected': isSelected,
|
'is-selected': isSelected,
|
||||||
|
|
|
@ -1,17 +1,25 @@
|
||||||
|
/**
|
||||||
|
* External dependencies
|
||||||
|
*/
|
||||||
|
import { BlockConfiguration } from '@wordpress/blocks';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
*/
|
*/
|
||||||
import initBlock from '../../utils/init-block';
|
import { initBlock } from '../../utils/init-block';
|
||||||
import metadata from './block.json';
|
import blockConfiguration from './block.json';
|
||||||
import { Edit } from './edit';
|
import { Edit, TabBlockAttributes } from './edit';
|
||||||
|
|
||||||
const { name } = metadata;
|
const { name, ...metadata } =
|
||||||
|
blockConfiguration as BlockConfiguration< TabBlockAttributes >;
|
||||||
|
|
||||||
export { metadata, name };
|
export { metadata, name };
|
||||||
|
|
||||||
export const settings = {
|
export const settings: Partial< BlockConfiguration< TabBlockAttributes > > = {
|
||||||
example: {},
|
example: {},
|
||||||
edit: Edit,
|
edit: Edit,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const init = () => initBlock( { name, metadata, settings } );
|
export function init() {
|
||||||
|
initBlock( { name, metadata, settings } );
|
||||||
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { BlockConfiguration } from '@wordpress/blocks';
|
||||||
/**
|
/**
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
*/
|
*/
|
||||||
import { initBlock } from '../../utils/init-blocks';
|
import { initBlock } from '../../utils/init-block';
|
||||||
import blockConfiguration from './block.json';
|
import blockConfiguration from './block.json';
|
||||||
import { Edit } from './edit';
|
import { Edit } from './edit';
|
||||||
import { ToggleBlockAttributes } from './types';
|
import { ToggleBlockAttributes } from './types';
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||||
|
"apiVersion": 2,
|
||||||
|
"name": "woocommerce/product-variation-items-field",
|
||||||
|
"title": "Product variations items",
|
||||||
|
"category": "woocommerce",
|
||||||
|
"description": "The product variations items.",
|
||||||
|
"keywords": [ "products", "variations" ],
|
||||||
|
"textdomain": "default",
|
||||||
|
"attributes": {
|
||||||
|
"description": {
|
||||||
|
"type": "string",
|
||||||
|
"__experimentalRole": "content"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"supports": {
|
||||||
|
"align": false,
|
||||||
|
"html": false,
|
||||||
|
"multiple": false,
|
||||||
|
"reusable": false,
|
||||||
|
"inserter": false,
|
||||||
|
"lock": false,
|
||||||
|
"__experimentalToolbar": false
|
||||||
|
},
|
||||||
|
"usesContext": [ "isInSelectedTab" ],
|
||||||
|
"editorStyle": "file:./editor.css"
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
/**
|
||||||
|
* External dependencies
|
||||||
|
*/
|
||||||
|
import { useBlockProps } from '@wordpress/block-editor';
|
||||||
|
import { BlockEditProps } from '@wordpress/blocks';
|
||||||
|
import { createElement } from '@wordpress/element';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal dependencies
|
||||||
|
*/
|
||||||
|
import { VariationsTable } from '../../components/variations-table';
|
||||||
|
import { VariationOptionsBlockAttributes } from './types';
|
||||||
|
import { VariableProductTour } from './variable-product-tour';
|
||||||
|
|
||||||
|
export function Edit( {
|
||||||
|
context,
|
||||||
|
}: BlockEditProps< VariationOptionsBlockAttributes > & {
|
||||||
|
context?: {
|
||||||
|
isInSelectedTab?: boolean;
|
||||||
|
};
|
||||||
|
} ) {
|
||||||
|
const blockProps = useBlockProps();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div { ...blockProps }>
|
||||||
|
<VariationsTable />
|
||||||
|
{ context?.isInSelectedTab && <VariableProductTour /> }
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
.wp-block-woocommerce-product-variations-items-field {
|
||||||
|
}
|
||||||
|
|
||||||
|
.variation-items-product-tour {
|
||||||
|
.tour-kit-spotlight {
|
||||||
|
border-radius: $gap-smaller;
|
||||||
|
padding: $gap-large;
|
||||||
|
}
|
||||||
|
.tour-kit-frame__container,
|
||||||
|
.woocommerce-tour-kit-step {
|
||||||
|
border-radius: $gap-smaller;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
/**
|
||||||
|
* External dependencies
|
||||||
|
*/
|
||||||
|
import { BlockConfiguration } from '@wordpress/blocks';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal dependencies
|
||||||
|
*/
|
||||||
|
import { initBlock } from '../../utils/init-block';
|
||||||
|
import blockConfiguration from './block.json';
|
||||||
|
import { Edit } from './edit';
|
||||||
|
import { VariationOptionsBlockAttributes } from './types';
|
||||||
|
|
||||||
|
const { name, ...metadata } =
|
||||||
|
blockConfiguration as BlockConfiguration< VariationOptionsBlockAttributes >;
|
||||||
|
|
||||||
|
export { metadata, name };
|
||||||
|
|
||||||
|
export const settings: Partial<
|
||||||
|
BlockConfiguration< VariationOptionsBlockAttributes >
|
||||||
|
> = {
|
||||||
|
example: {},
|
||||||
|
edit: Edit,
|
||||||
|
};
|
||||||
|
|
||||||
|
export function init() {
|
||||||
|
return initBlock( { name, metadata, settings } );
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
/**
|
||||||
|
* External dependencies
|
||||||
|
*/
|
||||||
|
import { BlockAttributes } from '@wordpress/blocks';
|
||||||
|
|
||||||
|
export interface VariationOptionsBlockAttributes extends BlockAttributes {
|
||||||
|
description: string;
|
||||||
|
}
|
|
@ -0,0 +1,138 @@
|
||||||
|
/**
|
||||||
|
* External dependencies
|
||||||
|
*/
|
||||||
|
import { createElement, useEffect, useRef, useState } from '@wordpress/element';
|
||||||
|
import { __ } from '@wordpress/i18n';
|
||||||
|
import { TourKit, TourKitTypes } from '@woocommerce/components';
|
||||||
|
import {
|
||||||
|
EXPERIMENTAL_PRODUCT_VARIATIONS_STORE_NAME,
|
||||||
|
useUserPreferences,
|
||||||
|
} from '@woocommerce/data';
|
||||||
|
import { recordEvent } from '@woocommerce/tracks';
|
||||||
|
import { useSelect } from '@wordpress/data';
|
||||||
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
|
// @ts-ignore No types for this exist yet.
|
||||||
|
// eslint-disable-next-line @woocommerce/dependency-group
|
||||||
|
import { useEntityId } from '@wordpress/core-data';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal dependencies
|
||||||
|
*/
|
||||||
|
import { DEFAULT_PER_PAGE_OPTION } from '../../constants';
|
||||||
|
|
||||||
|
export const VariableProductTour: React.FC = () => {
|
||||||
|
const [ isTourOpen, setIsTourOpen ] = useState( false );
|
||||||
|
const productId = useEntityId( 'postType', 'product' );
|
||||||
|
const prevTotalCount = useRef< undefined | number >();
|
||||||
|
|
||||||
|
const { totalCount } = useSelect(
|
||||||
|
( select ) => {
|
||||||
|
const { getProductVariationsTotalCount } = select(
|
||||||
|
EXPERIMENTAL_PRODUCT_VARIATIONS_STORE_NAME
|
||||||
|
);
|
||||||
|
const requestParams = {
|
||||||
|
product_id: productId,
|
||||||
|
page: 1,
|
||||||
|
per_page: DEFAULT_PER_PAGE_OPTION,
|
||||||
|
order: 'asc',
|
||||||
|
orderby: 'menu_order',
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
totalCount:
|
||||||
|
getProductVariationsTotalCount< number >( requestParams ),
|
||||||
|
};
|
||||||
|
},
|
||||||
|
[ productId ]
|
||||||
|
);
|
||||||
|
|
||||||
|
const {
|
||||||
|
updateUserPreferences,
|
||||||
|
variable_product_block_tour_shown: hasShownTour,
|
||||||
|
} = useUserPreferences();
|
||||||
|
|
||||||
|
const config: TourKitTypes.WooConfig = {
|
||||||
|
placement: 'top',
|
||||||
|
steps: [
|
||||||
|
{
|
||||||
|
referenceElements: {
|
||||||
|
desktop:
|
||||||
|
'.wp-block-woocommerce-product-variation-items-field',
|
||||||
|
},
|
||||||
|
focusElement: {
|
||||||
|
desktop:
|
||||||
|
'.wp-block-woocommerce-product-variation-items-field',
|
||||||
|
},
|
||||||
|
meta: {
|
||||||
|
name: 'product-variations-2',
|
||||||
|
heading: __(
|
||||||
|
'⚡️ This product now has variations',
|
||||||
|
'woocommerce'
|
||||||
|
),
|
||||||
|
descriptions: {
|
||||||
|
desktop: __(
|
||||||
|
'From now on, you’ll manage pricing, shipping, and inventory for each variation individually—just like any other product in your store.',
|
||||||
|
'woocommerce'
|
||||||
|
),
|
||||||
|
},
|
||||||
|
primaryButton: {
|
||||||
|
text: __( 'Got it', 'woocommerce' ),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
options: {
|
||||||
|
classNames: [ 'variation-items-product-tour' ],
|
||||||
|
// WooTourKit does not handle merging of default options properly,
|
||||||
|
// so we need to duplicate the effects options here.
|
||||||
|
effects: {
|
||||||
|
arrowIndicator: true,
|
||||||
|
spotlight: {
|
||||||
|
interactivity: {
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
callbacks: {
|
||||||
|
onStepViewOnce: () => {
|
||||||
|
recordEvent( 'variable_product_block_tour_shown', {
|
||||||
|
variable_count: totalCount,
|
||||||
|
} );
|
||||||
|
},
|
||||||
|
},
|
||||||
|
popperModifiers: [
|
||||||
|
{
|
||||||
|
name: 'offset',
|
||||||
|
options: {
|
||||||
|
// 24px for additional padding and 8px for arrow.
|
||||||
|
offset: [ 0, 32 ],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
closeHandler: () => {
|
||||||
|
updateUserPreferences( {
|
||||||
|
variable_product_block_tour_shown: 'yes',
|
||||||
|
} );
|
||||||
|
setIsTourOpen( false );
|
||||||
|
|
||||||
|
recordEvent( 'variable_product_block_tour_dismissed' );
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect( () => {
|
||||||
|
const isFirstVariation =
|
||||||
|
prevTotalCount.current !== totalCount &&
|
||||||
|
totalCount > 0 &&
|
||||||
|
prevTotalCount.current === 0;
|
||||||
|
prevTotalCount.current = totalCount;
|
||||||
|
if ( isFirstVariation && ! isTourOpen ) {
|
||||||
|
setIsTourOpen( true );
|
||||||
|
}
|
||||||
|
}, [ totalCount ] );
|
||||||
|
|
||||||
|
if ( hasShownTour === 'yes' || ! isTourOpen ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return <TourKit config={ config } />;
|
||||||
|
};
|
|
@ -3,8 +3,12 @@
|
||||||
*/
|
*/
|
||||||
import { __ } from '@wordpress/i18n';
|
import { __ } from '@wordpress/i18n';
|
||||||
import { useBlockProps } from '@wordpress/block-editor';
|
import { useBlockProps } from '@wordpress/block-editor';
|
||||||
import { createElement, createInterpolateElement } from '@wordpress/element';
|
import {
|
||||||
import { ProductAttribute } from '@woocommerce/data';
|
createElement,
|
||||||
|
createInterpolateElement,
|
||||||
|
useMemo,
|
||||||
|
} from '@wordpress/element';
|
||||||
|
import { Product, ProductAttribute } from '@woocommerce/data';
|
||||||
import { Link } from '@woocommerce/components';
|
import { Link } from '@woocommerce/components';
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
// @ts-ignore No types for this exist yet.
|
// @ts-ignore No types for this exist yet.
|
||||||
|
@ -14,28 +18,78 @@ import { useEntityProp, useEntityId } from '@wordpress/core-data';
|
||||||
/**
|
/**
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
*/
|
*/
|
||||||
import { useProductAttributes } from '../../hooks/use-product-attributes';
|
import {
|
||||||
|
EnhancedProductAttribute,
|
||||||
|
useProductAttributes,
|
||||||
|
} from '../../hooks/use-product-attributes';
|
||||||
import { AttributeControl } from '../../components/attribute-control';
|
import { AttributeControl } from '../../components/attribute-control';
|
||||||
|
import { useProductVariationsHelper } from '../../hooks/use-product-variations-helper';
|
||||||
|
|
||||||
|
function manageDefaultAttributes( values: EnhancedProductAttribute[] ) {
|
||||||
|
return values.reduce< Product[ 'default_attributes' ] >(
|
||||||
|
( prevDefaultAttributes, currentAttribute ) => {
|
||||||
|
if ( currentAttribute.isDefault ) {
|
||||||
|
return [
|
||||||
|
...prevDefaultAttributes,
|
||||||
|
{
|
||||||
|
id: currentAttribute.id,
|
||||||
|
name: currentAttribute.name,
|
||||||
|
option: currentAttribute.options[ 0 ],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
return prevDefaultAttributes;
|
||||||
|
},
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export function Edit() {
|
export function Edit() {
|
||||||
const blockProps = useBlockProps();
|
const blockProps = useBlockProps();
|
||||||
|
const { generateProductVariations } = useProductVariationsHelper();
|
||||||
|
|
||||||
const [ entityAttributes, setEntityAttributes ] = useEntityProp<
|
const [ entityAttributes, setEntityAttributes ] = useEntityProp<
|
||||||
ProductAttribute[]
|
ProductAttribute[]
|
||||||
>( 'postType', 'product', 'attributes' );
|
>( 'postType', 'product', 'attributes' );
|
||||||
|
|
||||||
|
const [ entityDefaultAttributes, setEntityDefaultAttributes ] =
|
||||||
|
useEntityProp< Product[ 'default_attributes' ] >(
|
||||||
|
'postType',
|
||||||
|
'product',
|
||||||
|
'default_attributes'
|
||||||
|
);
|
||||||
|
|
||||||
const { attributes, handleChange } = useProductAttributes( {
|
const { attributes, handleChange } = useProductAttributes( {
|
||||||
allAttributes: entityAttributes,
|
allAttributes: entityAttributes,
|
||||||
onChange: setEntityAttributes,
|
|
||||||
isVariationAttributes: true,
|
isVariationAttributes: true,
|
||||||
productId: useEntityId( 'postType', 'product' ),
|
productId: useEntityId( 'postType', 'product' ),
|
||||||
|
onChange( values ) {
|
||||||
|
setEntityAttributes( values );
|
||||||
|
setEntityDefaultAttributes( manageDefaultAttributes( values ) );
|
||||||
|
generateProductVariations( values );
|
||||||
|
},
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
function mapDefaultAttributes() {
|
||||||
|
return attributes.map( ( attribute ) => ( {
|
||||||
|
...attribute,
|
||||||
|
isDefault: entityDefaultAttributes.some(
|
||||||
|
( defaultAttribute ) =>
|
||||||
|
defaultAttribute.id === attribute.id ||
|
||||||
|
defaultAttribute.name === attribute.name
|
||||||
|
),
|
||||||
|
} ) );
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div { ...blockProps }>
|
<div { ...blockProps }>
|
||||||
<AttributeControl
|
<AttributeControl
|
||||||
value={ attributes }
|
value={ useMemo( mapDefaultAttributes, [
|
||||||
|
attributes,
|
||||||
|
entityDefaultAttributes,
|
||||||
|
] ) }
|
||||||
onChange={ handleChange }
|
onChange={ handleChange }
|
||||||
|
createNewAttributesAsGlobal={ true }
|
||||||
uiStrings={ {
|
uiStrings={ {
|
||||||
globalAttributeHelperMessage: '',
|
globalAttributeHelperMessage: '',
|
||||||
customAttributeHelperMessage: '',
|
customAttributeHelperMessage: '',
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
.wp-block-woocommerce-product-variations-options-field {
|
.wp-block-woocommerce-product-variations-options-field {
|
||||||
.woocommerce-sortable {
|
.woocommerce-sortable {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
|
||||||
|
&__item:not(:last-child) .woocommerce-list-item {
|
||||||
|
border-bottom: 1px solid $gray-200;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.woocommerce-list-item {
|
.woocommerce-list-item {
|
||||||
background: none;
|
background: none;
|
||||||
border: none;
|
border: none;
|
||||||
border-bottom: 1px solid $gray-200;
|
|
||||||
padding-left: 0;
|
padding-left: 0;
|
||||||
grid-template-columns: 26% auto 90px;
|
grid-template-columns: 26% auto 90px;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import { BlockConfiguration } from '@wordpress/blocks';
|
||||||
/**
|
/**
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
*/
|
*/
|
||||||
import { initBlock } from '../../utils/init-blocks';
|
import { initBlock } from '../../utils/init-block';
|
||||||
import blockConfiguration from './block.json';
|
import blockConfiguration from './block.json';
|
||||||
import { Edit } from './edit';
|
import { Edit } from './edit';
|
||||||
import { VariationOptionsBlockAttributes } from './types';
|
import { VariationOptionsBlockAttributes } from './types';
|
||||||
|
|
|
@ -34,6 +34,7 @@ import {
|
||||||
useProductAttributes,
|
useProductAttributes,
|
||||||
} from '../../hooks/use-product-attributes';
|
} from '../../hooks/use-product-attributes';
|
||||||
import { getAttributeId } from '../../components/attribute-control/utils';
|
import { getAttributeId } from '../../components/attribute-control/utils';
|
||||||
|
import { useProductVariationsHelper } from '../../hooks/use-product-variations-helper';
|
||||||
|
|
||||||
function hasAttributesUsedForVariations(
|
function hasAttributesUsedForVariations(
|
||||||
productAttributes: Product[ 'attributes' ]
|
productAttributes: Product[ 'attributes' ]
|
||||||
|
@ -41,22 +42,42 @@ function hasAttributesUsedForVariations(
|
||||||
return productAttributes.some( ( { variation } ) => variation );
|
return productAttributes.some( ( { variation } ) => variation );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getFirstOptionFromEachAttribute(
|
||||||
|
attributes: Product[ 'attributes' ]
|
||||||
|
): Product[ 'default_attributes' ] {
|
||||||
|
return attributes.map( ( attribute ) => ( {
|
||||||
|
id: attribute.id,
|
||||||
|
name: attribute.name,
|
||||||
|
option: attribute.options[ 0 ],
|
||||||
|
} ) );
|
||||||
|
}
|
||||||
|
|
||||||
export function Edit( {
|
export function Edit( {
|
||||||
attributes,
|
attributes,
|
||||||
}: BlockEditProps< VariationsBlockAttributes > ) {
|
}: BlockEditProps< VariationsBlockAttributes > ) {
|
||||||
const { description } = attributes;
|
const { description } = attributes;
|
||||||
|
|
||||||
|
const { generateProductVariations } = useProductVariationsHelper();
|
||||||
const [ isNewModalVisible, setIsNewModalVisible ] = useState( false );
|
const [ isNewModalVisible, setIsNewModalVisible ] = useState( false );
|
||||||
const [ productAttributes, setProductAttributes ] = useEntityProp<
|
const [ productAttributes, setProductAttributes ] = useEntityProp<
|
||||||
Product[ 'attributes' ]
|
Product[ 'attributes' ]
|
||||||
>( 'postType', 'product', 'attributes' );
|
>( 'postType', 'product', 'attributes' );
|
||||||
|
const [ , setDefaultProductAttributes ] = useEntityProp<
|
||||||
|
Product[ 'default_attributes' ]
|
||||||
|
>( 'postType', 'product', 'default_attributes' );
|
||||||
|
|
||||||
const { attributes: variationOptions, handleChange } = useProductAttributes(
|
const { attributes: variationOptions, handleChange } = useProductAttributes(
|
||||||
{
|
{
|
||||||
allAttributes: productAttributes,
|
allAttributes: productAttributes,
|
||||||
onChange: setProductAttributes,
|
|
||||||
isVariationAttributes: true,
|
isVariationAttributes: true,
|
||||||
productId: useEntityId( 'postType', 'product' ),
|
productId: useEntityId( 'postType', 'product' ),
|
||||||
|
onChange( values ) {
|
||||||
|
setProductAttributes( values );
|
||||||
|
setDefaultProductAttributes(
|
||||||
|
getFirstOptionFromEachAttribute( values )
|
||||||
|
);
|
||||||
|
generateProductVariations( values );
|
||||||
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -133,6 +154,7 @@ export function Edit( {
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
) }
|
) }
|
||||||
|
createNewAttributesAsGlobal={ true }
|
||||||
notice={ '' }
|
notice={ '' }
|
||||||
onCancel={ () => {
|
onCancel={ () => {
|
||||||
closeNewModal();
|
closeNewModal();
|
||||||
|
|
|
@ -7,7 +7,7 @@ import { BlockConfiguration } from '@wordpress/blocks';
|
||||||
/**
|
/**
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
*/
|
*/
|
||||||
import { initBlock } from '../../utils/init-blocks';
|
import { initBlock } from '../../utils/init-block';
|
||||||
import blockConfiguration from './block.json';
|
import blockConfiguration from './block.json';
|
||||||
import { Edit } from './edit';
|
import { Edit } from './edit';
|
||||||
import { VariationsBlockAttributes } from './types';
|
import { VariationsBlockAttributes } from './types';
|
||||||
|
|
|
@ -32,7 +32,7 @@ import { AttributeListItem } from '../attribute-list-item';
|
||||||
import { NewAttributeModal } from './new-attribute-modal';
|
import { NewAttributeModal } from './new-attribute-modal';
|
||||||
|
|
||||||
type AttributeControlProps = {
|
type AttributeControlProps = {
|
||||||
value: ProductAttribute[];
|
value: EnhancedProductAttribute[];
|
||||||
onAdd?: ( attribute: EnhancedProductAttribute[] ) => void;
|
onAdd?: ( attribute: EnhancedProductAttribute[] ) => void;
|
||||||
onChange: ( value: ProductAttribute[] ) => void;
|
onChange: ( value: ProductAttribute[] ) => void;
|
||||||
onEdit?: ( attribute: ProductAttribute ) => void;
|
onEdit?: ( attribute: ProductAttribute ) => void;
|
||||||
|
@ -44,6 +44,7 @@ type AttributeControlProps = {
|
||||||
onEditModalCancel?: ( attribute?: ProductAttribute ) => void;
|
onEditModalCancel?: ( attribute?: ProductAttribute ) => void;
|
||||||
onEditModalClose?: ( attribute?: ProductAttribute ) => void;
|
onEditModalClose?: ( attribute?: ProductAttribute ) => void;
|
||||||
onEditModalOpen?: ( attribute?: ProductAttribute ) => void;
|
onEditModalOpen?: ( attribute?: ProductAttribute ) => void;
|
||||||
|
createNewAttributesAsGlobal?: boolean;
|
||||||
uiStrings?: {
|
uiStrings?: {
|
||||||
emptyStateSubtitle?: string;
|
emptyStateSubtitle?: string;
|
||||||
newAttributeListItemLabel?: string;
|
newAttributeListItemLabel?: string;
|
||||||
|
@ -71,6 +72,7 @@ export const AttributeControl: React.FC< AttributeControlProps > = ( {
|
||||||
onRemove = () => {},
|
onRemove = () => {},
|
||||||
onRemoveCancel = () => {},
|
onRemoveCancel = () => {},
|
||||||
uiStrings,
|
uiStrings,
|
||||||
|
createNewAttributesAsGlobal = false,
|
||||||
} ) => {
|
} ) => {
|
||||||
uiStrings = {
|
uiStrings = {
|
||||||
newAttributeListItemLabel: __( 'Add new', 'woocommerce' ),
|
newAttributeListItemLabel: __( 'Add new', 'woocommerce' ),
|
||||||
|
@ -189,7 +191,7 @@ export const AttributeControl: React.FC< AttributeControlProps > = ( {
|
||||||
|
|
||||||
const currentAttribute = value.find(
|
const currentAttribute = value.find(
|
||||||
( attr ) => getAttributeId( attr ) === currentAttributeId
|
( attr ) => getAttributeId( attr ) === currentAttributeId
|
||||||
) as EnhancedProductAttribute;
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="woocommerce-attribute-field">
|
<div className="woocommerce-attribute-field">
|
||||||
|
@ -246,6 +248,7 @@ export const AttributeControl: React.FC< AttributeControlProps > = ( {
|
||||||
} }
|
} }
|
||||||
onAdd={ handleAdd }
|
onAdd={ handleAdd }
|
||||||
selectedAttributeIds={ value.map( ( attr ) => attr.id ) }
|
selectedAttributeIds={ value.map( ( attr ) => attr.id ) }
|
||||||
|
createNewAttributesAsGlobal={ createNewAttributesAsGlobal }
|
||||||
/>
|
/>
|
||||||
) }
|
) }
|
||||||
<SelectControlMenuSlot />
|
<SelectControlMenuSlot />
|
||||||
|
|
|
@ -14,7 +14,8 @@
|
||||||
width: 500px;
|
width: 500px;
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
|
|
||||||
.woocommerce-experimental-select-control + .woocommerce-experimental-select-control {
|
.woocommerce-experimental-select-control
|
||||||
|
+ .woocommerce-experimental-select-control {
|
||||||
margin-top: 1.3em;
|
margin-top: 1.3em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,6 +31,10 @@
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|
||||||
|
.components-checkbox-control .components-base-control__field {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.woocommerce-attribute-term-field {
|
.woocommerce-attribute-term-field {
|
||||||
|
|
|
@ -27,6 +27,8 @@ type EditAttributeModalProps = {
|
||||||
customAttributeHelperMessage?: string;
|
customAttributeHelperMessage?: string;
|
||||||
termsLabel?: string;
|
termsLabel?: string;
|
||||||
termsPlaceholder?: string;
|
termsPlaceholder?: string;
|
||||||
|
isDefaultLabel?: string;
|
||||||
|
isDefaultTooltip?: string;
|
||||||
visibleLabel?: string;
|
visibleLabel?: string;
|
||||||
visibleTooltip?: string;
|
visibleTooltip?: string;
|
||||||
cancelAccessibleLabel?: string;
|
cancelAccessibleLabel?: string;
|
||||||
|
@ -48,6 +50,11 @@ export const EditAttributeModal: React.FC< EditAttributeModalProps > = ( {
|
||||||
),
|
),
|
||||||
termsLabel = __( 'Values', 'woocommerce' ),
|
termsLabel = __( 'Values', 'woocommerce' ),
|
||||||
termsPlaceholder = __( 'Search or create value', 'woocommerce' ),
|
termsPlaceholder = __( 'Search or create value', 'woocommerce' ),
|
||||||
|
isDefaultLabel = __( 'Set default value', 'woocommerce' ),
|
||||||
|
isDefaultTooltip = __(
|
||||||
|
'Check to preselect the first choice when customers enter the product page.',
|
||||||
|
'woocommerce'
|
||||||
|
),
|
||||||
visibleLabel = __( 'Visible to customers', 'woocommerce' ),
|
visibleLabel = __( 'Visible to customers', 'woocommerce' ),
|
||||||
visibleTooltip = __(
|
visibleTooltip = __(
|
||||||
'Show or hide this attribute on the product page',
|
'Show or hide this attribute on the product page',
|
||||||
|
@ -120,6 +127,23 @@ export const EditAttributeModal: React.FC< EditAttributeModalProps > = ( {
|
||||||
/>
|
/>
|
||||||
) }
|
) }
|
||||||
|
|
||||||
|
<div className="woocommerce-edit-attribute-modal__options">
|
||||||
|
{ attribute.variation && (
|
||||||
|
<div className="woocommerce-edit-attribute-modal__option-container">
|
||||||
|
<CheckboxControl
|
||||||
|
onChange={ ( checked ) =>
|
||||||
|
setEditableAttribute( {
|
||||||
|
...( editableAttribute as EnhancedProductAttribute ),
|
||||||
|
isDefault: checked,
|
||||||
|
} )
|
||||||
|
}
|
||||||
|
checked={ editableAttribute?.isDefault }
|
||||||
|
label={ isDefaultLabel }
|
||||||
|
/>
|
||||||
|
<Tooltip text={ isDefaultTooltip } />
|
||||||
|
</div>
|
||||||
|
) }
|
||||||
|
|
||||||
<div className="woocommerce-edit-attribute-modal__option-container">
|
<div className="woocommerce-edit-attribute-modal__option-container">
|
||||||
<CheckboxControl
|
<CheckboxControl
|
||||||
onChange={ ( val ) =>
|
onChange={ ( val ) =>
|
||||||
|
@ -134,6 +158,7 @@ export const EditAttributeModal: React.FC< EditAttributeModalProps > = ( {
|
||||||
<Tooltip text={ visibleTooltip } />
|
<Tooltip text={ visibleTooltip } />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
<div className="woocommerce-edit-attribute-modal__buttons">
|
<div className="woocommerce-edit-attribute-modal__buttons">
|
||||||
<Button
|
<Button
|
||||||
isSecondary
|
isSecondary
|
||||||
|
|
|
@ -2,7 +2,12 @@
|
||||||
* External dependencies
|
* External dependencies
|
||||||
*/
|
*/
|
||||||
import { __ } from '@wordpress/i18n';
|
import { __ } from '@wordpress/i18n';
|
||||||
import { useState, createElement, Fragment } from '@wordpress/element';
|
import {
|
||||||
|
useState,
|
||||||
|
createElement,
|
||||||
|
Fragment,
|
||||||
|
useEffect,
|
||||||
|
} from '@wordpress/element';
|
||||||
import { trash } from '@wordpress/icons';
|
import { trash } from '@wordpress/icons';
|
||||||
import {
|
import {
|
||||||
Form,
|
Form,
|
||||||
|
@ -49,6 +54,7 @@ type NewAttributeModalProps = {
|
||||||
onCancel: () => void;
|
onCancel: () => void;
|
||||||
onAdd: ( newCategories: EnhancedProductAttribute[] ) => void;
|
onAdd: ( newCategories: EnhancedProductAttribute[] ) => void;
|
||||||
selectedAttributeIds?: number[];
|
selectedAttributeIds?: number[];
|
||||||
|
createNewAttributesAsGlobal?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
type AttributeForm = {
|
type AttributeForm = {
|
||||||
|
@ -81,6 +87,7 @@ export const NewAttributeModal: React.FC< NewAttributeModalProps > = ( {
|
||||||
onCancel,
|
onCancel,
|
||||||
onAdd,
|
onAdd,
|
||||||
selectedAttributeIds = [],
|
selectedAttributeIds = [],
|
||||||
|
createNewAttributesAsGlobal = false,
|
||||||
} ) => {
|
} ) => {
|
||||||
const scrollAttributeIntoView = ( index: number ) => {
|
const scrollAttributeIntoView = ( index: number ) => {
|
||||||
setTimeout( () => {
|
setTimeout( () => {
|
||||||
|
@ -201,6 +208,15 @@ export const NewAttributeModal: React.FC< NewAttributeModalProps > = ( {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect( function focusFirstAttributeField() {
|
||||||
|
const firstAttributeFieldLabel =
|
||||||
|
document.querySelector< HTMLLabelElement >(
|
||||||
|
'.woocommerce-new-attribute-modal__table-row .woocommerce-attribute-input-field label'
|
||||||
|
);
|
||||||
|
|
||||||
|
firstAttributeFieldLabel?.focus();
|
||||||
|
}, [] );
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Form< AttributeForm >
|
<Form< AttributeForm >
|
||||||
|
@ -298,6 +314,9 @@ export const NewAttributeModal: React.FC< NewAttributeModalProps > = ( {
|
||||||
undefined
|
undefined
|
||||||
),
|
),
|
||||||
] }
|
] }
|
||||||
|
createNewAttributesAsGlobal={
|
||||||
|
createNewAttributesAsGlobal
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
<td className="woocommerce-new-attribute-modal__table-attribute-value-column">
|
<td className="woocommerce-new-attribute-modal__table-attribute-value-column">
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* External dependencies
|
* External dependencies
|
||||||
*/
|
*/
|
||||||
import { sprintf, __ } from '@wordpress/i18n';
|
import { sprintf, __ } from '@wordpress/i18n';
|
||||||
import { useSelect } from '@wordpress/data';
|
import { useDispatch, useSelect } from '@wordpress/data';
|
||||||
import { Spinner, Icon } from '@wordpress/components';
|
import { Spinner, Icon } from '@wordpress/components';
|
||||||
import { plus } from '@wordpress/icons';
|
import { plus } from '@wordpress/icons';
|
||||||
import { createElement } from '@wordpress/element';
|
import { createElement } from '@wordpress/element';
|
||||||
|
@ -11,6 +11,8 @@ import {
|
||||||
QueryProductAttribute,
|
QueryProductAttribute,
|
||||||
ProductAttribute,
|
ProductAttribute,
|
||||||
WCDataSelector,
|
WCDataSelector,
|
||||||
|
ProductAttributesActions,
|
||||||
|
WPDataActions,
|
||||||
} from '@woocommerce/data';
|
} from '@woocommerce/data';
|
||||||
import { recordEvent } from '@woocommerce/tracks';
|
import { recordEvent } from '@woocommerce/tracks';
|
||||||
import {
|
import {
|
||||||
|
@ -38,6 +40,7 @@ type AttributeInputFieldProps = {
|
||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
ignoredAttributeIds?: number[];
|
ignoredAttributeIds?: number[];
|
||||||
|
createNewAttributesAsGlobal?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
function isNewAttributeListItem( attribute: NarrowedQueryAttribute ): boolean {
|
function isNewAttributeListItem( attribute: NarrowedQueryAttribute ): boolean {
|
||||||
|
@ -51,7 +54,12 @@ export const AttributeInputField: React.FC< AttributeInputFieldProps > = ( {
|
||||||
label,
|
label,
|
||||||
disabled,
|
disabled,
|
||||||
ignoredAttributeIds = [],
|
ignoredAttributeIds = [],
|
||||||
|
createNewAttributesAsGlobal = false,
|
||||||
} ) => {
|
} ) => {
|
||||||
|
const { createErrorNotice } = useDispatch( 'core/notices' );
|
||||||
|
const { createProductAttribute, invalidateResolution } = useDispatch(
|
||||||
|
EXPERIMENTAL_PRODUCT_ATTRIBUTES_STORE_NAME
|
||||||
|
) as ProductAttributesActions & WPDataActions;
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const { attributes, isLoading } = useSelect( ( select: WCDataSelector ) => {
|
const { attributes, isLoading } = useSelect( ( select: WCDataSelector ) => {
|
||||||
|
@ -99,6 +107,35 @@ export const AttributeInputField: React.FC< AttributeInputFieldProps > = ( {
|
||||||
return filteredItems;
|
return filteredItems;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const addNewAttribute = ( attribute: NarrowedQueryAttribute ) => {
|
||||||
|
recordEvent( 'product_attribute_add_custom_attribute', {
|
||||||
|
source: TRACKS_SOURCE,
|
||||||
|
} );
|
||||||
|
if ( createNewAttributesAsGlobal ) {
|
||||||
|
createProductAttribute( { name: attribute.name } ).then(
|
||||||
|
( newAttr ) => {
|
||||||
|
invalidateResolution( 'getProductAttributes' );
|
||||||
|
onChange( { ...newAttr, options: [] } );
|
||||||
|
},
|
||||||
|
( error ) => {
|
||||||
|
let message = __(
|
||||||
|
'Failed to create new attribute.',
|
||||||
|
'woocommerce'
|
||||||
|
);
|
||||||
|
if ( error.code === 'woocommerce_rest_cannot_create' ) {
|
||||||
|
message = error.message;
|
||||||
|
}
|
||||||
|
|
||||||
|
createErrorNotice( message, {
|
||||||
|
explicitDismiss: true,
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
onChange( attribute.name );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SelectControl< NarrowedQueryAttribute >
|
<SelectControl< NarrowedQueryAttribute >
|
||||||
className="woocommerce-attribute-input-field"
|
className="woocommerce-attribute-input-field"
|
||||||
|
@ -112,19 +149,14 @@ export const AttributeInputField: React.FC< AttributeInputFieldProps > = ( {
|
||||||
selected={ value }
|
selected={ value }
|
||||||
onSelect={ ( attribute ) => {
|
onSelect={ ( attribute ) => {
|
||||||
if ( isNewAttributeListItem( attribute ) ) {
|
if ( isNewAttributeListItem( attribute ) ) {
|
||||||
recordEvent( 'product_attribute_add_custom_attribute', {
|
addNewAttribute( attribute );
|
||||||
source: TRACKS_SOURCE,
|
} else {
|
||||||
} );
|
onChange( {
|
||||||
}
|
|
||||||
onChange(
|
|
||||||
isNewAttributeListItem( attribute )
|
|
||||||
? attribute.name
|
|
||||||
: {
|
|
||||||
id: attribute.id,
|
id: attribute.id,
|
||||||
name: attribute.name,
|
name: attribute.name,
|
||||||
options: [],
|
options: [],
|
||||||
|
} );
|
||||||
}
|
}
|
||||||
);
|
|
||||||
} }
|
} }
|
||||||
onRemove={ () => onChange() }
|
onRemove={ () => onChange() }
|
||||||
__experimentalOpenMenuOnFocus
|
__experimentalOpenMenuOnFocus
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
/**
|
/**
|
||||||
* External dependencies
|
* External dependencies
|
||||||
*/
|
*/
|
||||||
import { render } from '@testing-library/react';
|
import { render, waitFor } from '@testing-library/react';
|
||||||
import { useSelect } from '@wordpress/data';
|
import { useDispatch, useSelect } from '@wordpress/data';
|
||||||
import { useState, createElement } from '@wordpress/element';
|
import { useState, createElement } from '@wordpress/element';
|
||||||
import { ProductAttribute, QueryProductAttribute } from '@woocommerce/data';
|
import { ProductAttribute, QueryProductAttribute } from '@woocommerce/data';
|
||||||
|
|
||||||
|
@ -14,6 +14,11 @@ import { AttributeInputField } from '../attribute-input-field';
|
||||||
jest.mock( '@wordpress/data', () => ( {
|
jest.mock( '@wordpress/data', () => ( {
|
||||||
...jest.requireActual( '@wordpress/data' ),
|
...jest.requireActual( '@wordpress/data' ),
|
||||||
useSelect: jest.fn(),
|
useSelect: jest.fn(),
|
||||||
|
useDispatch: jest.fn().mockReturnValue( {
|
||||||
|
createErrorNotice: jest.fn(),
|
||||||
|
createProductAttribute: jest.fn(),
|
||||||
|
invalidateResolution: jest.fn(),
|
||||||
|
} ),
|
||||||
} ) );
|
} ) );
|
||||||
|
|
||||||
jest.mock( '@wordpress/components', () => ( {
|
jest.mock( '@wordpress/components', () => ( {
|
||||||
|
@ -265,4 +270,97 @@ describe( 'AttributeInputField', () => {
|
||||||
queryByText( 'Create "Co"' )?.click();
|
queryByText( 'Create "Co"' )?.click();
|
||||||
expect( onChangeMock ).toHaveBeenCalledWith( 'Co' );
|
expect( onChangeMock ).toHaveBeenCalledWith( 'Co' );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
describe( 'createNewAttributesAsGlobal is true', () => {
|
||||||
|
it( 'should create a new global attribute and invalidate product attributes', async () => {
|
||||||
|
const onChangeMock = jest.fn();
|
||||||
|
( useSelect as jest.Mock ).mockReturnValue( {
|
||||||
|
isLoading: false,
|
||||||
|
attributes: [ attributeList[ 0 ] ],
|
||||||
|
} );
|
||||||
|
const createProductAttributeMock = jest
|
||||||
|
.fn()
|
||||||
|
.mockImplementation(
|
||||||
|
(
|
||||||
|
newAttribute: Partial< Omit< ProductAttribute, 'id' > >
|
||||||
|
) => {
|
||||||
|
return Promise.resolve( {
|
||||||
|
name: newAttribute.name,
|
||||||
|
id: 123,
|
||||||
|
slug: newAttribute.name?.toLowerCase(),
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
);
|
||||||
|
const invalidateResolutionMock = jest.fn();
|
||||||
|
( useDispatch as jest.Mock ).mockReturnValue( {
|
||||||
|
createErrorNotice: jest.fn(),
|
||||||
|
createProductAttribute: createProductAttributeMock,
|
||||||
|
invalidateResolution: invalidateResolutionMock,
|
||||||
|
} );
|
||||||
|
const { queryByText } = render(
|
||||||
|
<AttributeInputField
|
||||||
|
onChange={ onChangeMock }
|
||||||
|
createNewAttributesAsGlobal={ true }
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
queryByText( 'Update Input' )?.click();
|
||||||
|
queryByText( 'Create "Co"' )?.click();
|
||||||
|
expect( createProductAttributeMock ).toHaveBeenCalledWith( {
|
||||||
|
name: 'Co',
|
||||||
|
} );
|
||||||
|
await waitFor( () => {
|
||||||
|
expect( invalidateResolutionMock ).toHaveBeenCalledWith(
|
||||||
|
'getProductAttributes'
|
||||||
|
);
|
||||||
|
} );
|
||||||
|
expect( onChangeMock ).toHaveBeenCalledWith( {
|
||||||
|
name: 'Co',
|
||||||
|
slug: 'co',
|
||||||
|
id: 123,
|
||||||
|
options: [],
|
||||||
|
} );
|
||||||
|
} );
|
||||||
|
|
||||||
|
it( 'should show an error notice and not call onChange when creation failed', async () => {
|
||||||
|
const onChangeMock = jest.fn();
|
||||||
|
( useSelect as jest.Mock ).mockReturnValue( {
|
||||||
|
isLoading: false,
|
||||||
|
attributes: [ attributeList[ 0 ] ],
|
||||||
|
} );
|
||||||
|
const createProductAttributeMock = jest
|
||||||
|
.fn()
|
||||||
|
.mockImplementation( () => {
|
||||||
|
return Promise.reject( {
|
||||||
|
code: 'woocommerce_rest_cannot_create',
|
||||||
|
message: 'Duplicate slug',
|
||||||
|
} );
|
||||||
|
} );
|
||||||
|
const invalidateResolutionMock = jest.fn();
|
||||||
|
const createErrorNoticeMock = jest.fn();
|
||||||
|
( useDispatch as jest.Mock ).mockReturnValue( {
|
||||||
|
createErrorNotice: createErrorNoticeMock,
|
||||||
|
createProductAttribute: createProductAttributeMock,
|
||||||
|
invalidateResolution: invalidateResolutionMock,
|
||||||
|
} );
|
||||||
|
const { queryByText } = render(
|
||||||
|
<AttributeInputField
|
||||||
|
onChange={ onChangeMock }
|
||||||
|
createNewAttributesAsGlobal={ true }
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
queryByText( 'Update Input' )?.click();
|
||||||
|
queryByText( 'Create "Co"' )?.click();
|
||||||
|
expect( createProductAttributeMock ).toHaveBeenCalledWith( {
|
||||||
|
name: 'Co',
|
||||||
|
} );
|
||||||
|
await waitFor( () => {
|
||||||
|
expect( createErrorNoticeMock ).toHaveBeenCalledWith(
|
||||||
|
'Duplicate slug',
|
||||||
|
{ explicitDismiss: true }
|
||||||
|
);
|
||||||
|
} );
|
||||||
|
expect( invalidateResolutionMock ).not.toHaveBeenCalled();
|
||||||
|
expect( onChangeMock ).not.toHaveBeenCalled();
|
||||||
|
} );
|
||||||
|
} );
|
||||||
} );
|
} );
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
*/
|
*/
|
||||||
import { sprintf, __ } from '@wordpress/i18n';
|
import { sprintf, __ } from '@wordpress/i18n';
|
||||||
import { CheckboxControl, Icon, Spinner } from '@wordpress/components';
|
import { CheckboxControl, Icon, Spinner } from '@wordpress/components';
|
||||||
import { resolveSelect } from '@wordpress/data';
|
import { resolveSelect, useDispatch } from '@wordpress/data';
|
||||||
import {
|
import {
|
||||||
useCallback,
|
useCallback,
|
||||||
useEffect,
|
useEffect,
|
||||||
|
@ -12,6 +12,7 @@ import {
|
||||||
createElement,
|
createElement,
|
||||||
Fragment,
|
Fragment,
|
||||||
} from '@wordpress/element';
|
} from '@wordpress/element';
|
||||||
|
import { recordEvent } from '@woocommerce/tracks';
|
||||||
import { useDebounce } from '@wordpress/compose';
|
import { useDebounce } from '@wordpress/compose';
|
||||||
import { plus } from '@wordpress/icons';
|
import { plus } from '@wordpress/icons';
|
||||||
import {
|
import {
|
||||||
|
@ -24,11 +25,13 @@ import {
|
||||||
__experimentalSelectControlMenu as Menu,
|
__experimentalSelectControlMenu as Menu,
|
||||||
__experimentalSelectControlMenuItem as MenuItem,
|
__experimentalSelectControlMenuItem as MenuItem,
|
||||||
} from '@woocommerce/components';
|
} from '@woocommerce/components';
|
||||||
|
import { cleanForSlug } from '@wordpress/url';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
*/
|
*/
|
||||||
import { CreateAttributeTermModal } from './create-attribute-term-modal';
|
import { CreateAttributeTermModal } from './create-attribute-term-modal';
|
||||||
|
import { TRACKS_SOURCE } from '../../constants';
|
||||||
|
|
||||||
type AttributeTermInputFieldProps = {
|
type AttributeTermInputFieldProps = {
|
||||||
value?: ProductAttributeTerm[];
|
value?: ProductAttributeTerm[];
|
||||||
|
@ -37,8 +40,14 @@ type AttributeTermInputFieldProps = {
|
||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
label?: string;
|
label?: string;
|
||||||
|
autoCreateOnSelect?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
interface customError extends Error {
|
||||||
|
code: string;
|
||||||
|
message: string;
|
||||||
|
}
|
||||||
|
|
||||||
let uniqueId = 0;
|
let uniqueId = 0;
|
||||||
|
|
||||||
export const AttributeTermInputField: React.FC<
|
export const AttributeTermInputField: React.FC<
|
||||||
|
@ -50,6 +59,7 @@ export const AttributeTermInputField: React.FC<
|
||||||
disabled,
|
disabled,
|
||||||
attributeId,
|
attributeId,
|
||||||
label = '',
|
label = '',
|
||||||
|
autoCreateOnSelect = true,
|
||||||
} ) => {
|
} ) => {
|
||||||
const attributeTermInputId = useRef(
|
const attributeTermInputId = useRef(
|
||||||
`woocommerce-attribute-term-field-${ ++uniqueId }`
|
`woocommerce-attribute-term-field-${ ++uniqueId }`
|
||||||
|
@ -58,8 +68,12 @@ export const AttributeTermInputField: React.FC<
|
||||||
ProductAttributeTerm[]
|
ProductAttributeTerm[]
|
||||||
>( [] );
|
>( [] );
|
||||||
const [ isFetching, setIsFetching ] = useState( false );
|
const [ isFetching, setIsFetching ] = useState( false );
|
||||||
|
const [ isCreatingTerm, setIsCreatingTerm ] = useState( false );
|
||||||
const [ addNewAttributeTermName, setAddNewAttributeTermName ] =
|
const [ addNewAttributeTermName, setAddNewAttributeTermName ] =
|
||||||
useState< string >();
|
useState< string >();
|
||||||
|
const { createNotice } = useDispatch( 'core/notices' );
|
||||||
|
const { createProductAttributeTerm, invalidateResolutionForStoreSelector } =
|
||||||
|
useDispatch( EXPERIMENTAL_PRODUCT_ATTRIBUTE_TERMS_STORE_NAME );
|
||||||
|
|
||||||
const fetchItems = useCallback(
|
const fetchItems = useCallback(
|
||||||
( searchString?: string | undefined ) => {
|
( searchString?: string | undefined ) => {
|
||||||
|
@ -102,20 +116,6 @@ export const AttributeTermInputField: React.FC<
|
||||||
onChange( value.filter( ( opt ) => opt.slug !== item.slug ) );
|
onChange( value.filter( ( opt ) => opt.slug !== item.slug ) );
|
||||||
};
|
};
|
||||||
|
|
||||||
const onSelect = ( item: ProductAttributeTerm ) => {
|
|
||||||
// Add new item.
|
|
||||||
if ( item.id === -99 ) {
|
|
||||||
setAddNewAttributeTermName( item.name );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const isSelected = value.find( ( i ) => i.slug === item.slug );
|
|
||||||
if ( isSelected ) {
|
|
||||||
onRemove( item );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
onChange( [ ...value, item ] );
|
|
||||||
};
|
|
||||||
|
|
||||||
const focusSelectControl = () => {
|
const focusSelectControl = () => {
|
||||||
const selectControlInputField: HTMLInputElement | null =
|
const selectControlInputField: HTMLInputElement | null =
|
||||||
document.querySelector(
|
document.querySelector(
|
||||||
|
@ -130,6 +130,78 @@ export const AttributeTermInputField: React.FC<
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const createAttributeTerm = async (
|
||||||
|
attribute: Partial< ProductAttributeTerm >
|
||||||
|
) => {
|
||||||
|
recordEvent( 'product_attribute_term_add', {
|
||||||
|
source: TRACKS_SOURCE,
|
||||||
|
} );
|
||||||
|
setIsCreatingTerm( true );
|
||||||
|
try {
|
||||||
|
const newAttribute: ProductAttributeTerm =
|
||||||
|
await createProductAttributeTerm( {
|
||||||
|
...attribute,
|
||||||
|
attribute_id: attributeId,
|
||||||
|
} );
|
||||||
|
recordEvent( 'product_attribute_term_add_success', {
|
||||||
|
source: TRACKS_SOURCE,
|
||||||
|
} );
|
||||||
|
onChange( [ ...value, newAttribute ] );
|
||||||
|
invalidateResolutionForStoreSelector( 'getProductAttributes' );
|
||||||
|
invalidateResolutionForStoreSelector( 'getProductAttributeTerms' );
|
||||||
|
setIsCreatingTerm( false );
|
||||||
|
} catch ( err: unknown ) {
|
||||||
|
let error = {
|
||||||
|
source: TRACKS_SOURCE,
|
||||||
|
code: 'Unknown error.',
|
||||||
|
message: 'An unknown error occurred.',
|
||||||
|
};
|
||||||
|
let noticeMessage = __(
|
||||||
|
'Failed to create attribute term.',
|
||||||
|
'woocommerce'
|
||||||
|
);
|
||||||
|
const errorResponse = err as customError;
|
||||||
|
if ( errorResponse?.code && errorResponse?.message ) {
|
||||||
|
error = {
|
||||||
|
...error,
|
||||||
|
code: errorResponse.code,
|
||||||
|
message: errorResponse.message,
|
||||||
|
};
|
||||||
|
if ( errorResponse.code === 'term_exists' ) {
|
||||||
|
noticeMessage = __(
|
||||||
|
'Attribute term already exists.',
|
||||||
|
'woocommerce'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
recordEvent( 'product_attribute_term_add_failed', error );
|
||||||
|
createNotice( 'error', noticeMessage );
|
||||||
|
setIsCreatingTerm( false );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const onSelect = ( item: ProductAttributeTerm ) => {
|
||||||
|
// Add new item.
|
||||||
|
if ( item.id === -99 ) {
|
||||||
|
if ( autoCreateOnSelect ) {
|
||||||
|
createAttributeTerm( {
|
||||||
|
name: item.name,
|
||||||
|
slug: cleanForSlug( item.name ),
|
||||||
|
} );
|
||||||
|
focusSelectControl();
|
||||||
|
} else {
|
||||||
|
setAddNewAttributeTermName( item.name );
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const isSelected = value.find( ( i ) => i.slug === item.slug );
|
||||||
|
if ( isSelected ) {
|
||||||
|
onRemove( item );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
onChange( [ ...value, item ] );
|
||||||
|
};
|
||||||
|
|
||||||
const selectedTermSlugs = ( value || [] ).map( ( term ) => term.slug );
|
const selectedTermSlugs = ( value || [] ).map( ( term ) => term.slug );
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -166,8 +238,12 @@ export const AttributeTermInputField: React.FC<
|
||||||
const { changes, type } = actionAndChanges;
|
const { changes, type } = actionAndChanges;
|
||||||
switch ( type ) {
|
switch ( type ) {
|
||||||
case selectControlStateChangeTypes.ControlledPropUpdatedSelectedItem:
|
case selectControlStateChangeTypes.ControlledPropUpdatedSelectedItem:
|
||||||
|
const listIsOpen = isCreatingTerm
|
||||||
|
? { isOpen: isCreatingTerm }
|
||||||
|
: {};
|
||||||
return {
|
return {
|
||||||
...changes,
|
...changes,
|
||||||
|
...listIsOpen,
|
||||||
inputValue: state.inputValue,
|
inputValue: state.inputValue,
|
||||||
};
|
};
|
||||||
case selectControlStateChangeTypes.ItemClick:
|
case selectControlStateChangeTypes.ItemClick:
|
||||||
|
@ -206,7 +282,7 @@ export const AttributeTermInputField: React.FC<
|
||||||
return (
|
return (
|
||||||
<Menu isOpen={ isOpen } getMenuProps={ getMenuProps }>
|
<Menu isOpen={ isOpen } getMenuProps={ getMenuProps }>
|
||||||
{ [
|
{ [
|
||||||
isFetching ? (
|
isFetching || isCreatingTerm ? (
|
||||||
<div
|
<div
|
||||||
key="loading-spinner"
|
key="loading-spinner"
|
||||||
className="woocommerce-attribute-term-field__loading-spinner"
|
className="woocommerce-attribute-term-field__loading-spinner"
|
||||||
|
@ -275,7 +351,9 @@ export const AttributeTermInputField: React.FC<
|
||||||
);
|
);
|
||||||
} }
|
} }
|
||||||
</SelectControl>
|
</SelectControl>
|
||||||
{ addNewAttributeTermName && attributeId !== undefined && (
|
{ ! autoCreateOnSelect &&
|
||||||
|
addNewAttributeTermName &&
|
||||||
|
attributeId !== undefined && (
|
||||||
<CreateAttributeTermModal
|
<CreateAttributeTermModal
|
||||||
initialAttributeTermName={ addNewAttributeTermName }
|
initialAttributeTermName={ addNewAttributeTermName }
|
||||||
onCancel={ () => {
|
onCancel={ () => {
|
||||||
|
@ -286,6 +364,9 @@ export const AttributeTermInputField: React.FC<
|
||||||
onCreated={ ( newAttribute ) => {
|
onCreated={ ( newAttribute ) => {
|
||||||
onSelect( newAttribute );
|
onSelect( newAttribute );
|
||||||
setAddNewAttributeTermName( undefined );
|
setAddNewAttributeTermName( undefined );
|
||||||
|
invalidateResolutionForStoreSelector(
|
||||||
|
'getProductAttributeTerms'
|
||||||
|
);
|
||||||
focusSelectControl();
|
focusSelectControl();
|
||||||
} }
|
} }
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -24,6 +24,13 @@ jest.mock( '@woocommerce/navigation', () => ( {
|
||||||
getQuery: jest.fn().mockReturnValue( {} ),
|
getQuery: jest.fn().mockReturnValue( {} ),
|
||||||
} ) );
|
} ) );
|
||||||
|
|
||||||
|
const blockProps = {
|
||||||
|
setAttributes: () => {},
|
||||||
|
className: '',
|
||||||
|
clientId: '',
|
||||||
|
isSelected: false,
|
||||||
|
};
|
||||||
|
|
||||||
function MockTabs( { onChange = jest.fn() } ) {
|
function MockTabs( { onChange = jest.fn() } ) {
|
||||||
const [ selected, setSelected ] = useState< string | null >( null );
|
const [ selected, setSelected ] = useState< string | null >( null );
|
||||||
const mockContext = {
|
const mockContext = {
|
||||||
|
@ -39,15 +46,18 @@ function MockTabs( { onChange = jest.fn() } ) {
|
||||||
} }
|
} }
|
||||||
/>
|
/>
|
||||||
<Tab
|
<Tab
|
||||||
attributes={ { id: 'test1', title: 'Test button 1' } }
|
{ ...blockProps }
|
||||||
|
attributes={ { id: 'test1', title: 'Test button 1', order: 1 } }
|
||||||
context={ mockContext }
|
context={ mockContext }
|
||||||
/>
|
/>
|
||||||
<Tab
|
<Tab
|
||||||
attributes={ { id: 'test2', title: 'Test button 2' } }
|
{ ...blockProps }
|
||||||
|
attributes={ { id: 'test2', title: 'Test button 2', order: 2 } }
|
||||||
context={ mockContext }
|
context={ mockContext }
|
||||||
/>
|
/>
|
||||||
<Tab
|
<Tab
|
||||||
attributes={ { id: 'test3', title: 'Test button 3' } }
|
{ ...blockProps }
|
||||||
|
attributes={ { id: 'test3', title: 'Test button 3', order: 3 } }
|
||||||
context={ mockContext }
|
context={ mockContext }
|
||||||
/>
|
/>
|
||||||
</SlotFillProvider>
|
</SlotFillProvider>
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
/**
|
||||||
|
* External dependencies
|
||||||
|
*/
|
||||||
|
import { createElement } from '@wordpress/element';
|
||||||
|
|
||||||
|
export default function HiddenIcon( {
|
||||||
|
width = 24,
|
||||||
|
height = 24,
|
||||||
|
...props
|
||||||
|
}: React.SVGProps< SVGSVGElement > ) {
|
||||||
|
return (
|
||||||
|
<svg
|
||||||
|
{ ...props }
|
||||||
|
width={ width }
|
||||||
|
height={ height }
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
fill="none"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
aria-hidden="true"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
fillRule="evenodd"
|
||||||
|
clipRule="evenodd"
|
||||||
|
d="M13.7226 6.2125C13.1641 6.0766 12.5883 6 11.9999 6C8.10055 6 4.75407 9.36447 3.31899 11.0546C2.8507 11.6061 2.8507 12.3939 3.31899 12.9454C4.17896 13.9582 5.72533 15.5723 7.66574 16.7033L8.41572 15.4043C8.13761 15.242 7.86389 15.0655 7.59553 14.8776C6.25019 13.9359 5.15775 12.7905 4.48406 12C5.15775 11.2095 6.25019 10.0641 7.59553 9.12235C8.96667 8.16257 10.4775 7.5 11.9999 7.5C12.3118 7.5 12.6231 7.5278 12.9329 7.58027L13.7226 6.2125ZM12.3504 8.58923C12.2352 8.57753 12.1182 8.57153 11.9999 8.57153C10.1063 8.57153 8.57132 10.1066 8.57132 12.0001C8.57132 12.7505 8.81237 13.4445 9.22126 14.0091L10.1233 12.4467C10.0893 12.3034 10.0713 12.1538 10.0713 12.0001C10.0713 11.1266 10.652 10.3888 11.4484 10.1515L12.3504 8.58923ZM12.8092 10.2491L13.5611 8.94679C14.6697 9.51479 15.4285 10.6688 15.4285 12.0001C15.4285 13.8937 13.8934 15.4287 11.9999 15.4287C11.3128 15.4287 10.6729 15.2266 10.1364 14.8785L10.8883 13.5763C11.2025 13.7983 11.5859 13.9287 11.9999 13.9287C13.065 13.9287 13.9285 13.0652 13.9285 12.0001C13.9285 11.224 13.4701 10.555 12.8092 10.2491ZM9.51376 15.957C10.3246 16.2986 11.1605 16.5 11.9999 16.5C13.5223 16.5 15.0331 15.8374 16.4043 14.8776C17.7496 13.9359 18.842 12.7905 19.5157 12C18.842 11.2095 17.7496 10.0641 16.4043 9.12235C15.6875 8.62066 14.9327 8.20018 14.1579 7.91308L14.917 6.59839C17.5164 7.64275 19.6204 9.80575 20.6808 11.0546C21.1491 11.6061 21.1491 12.3939 20.6808 12.9454C19.2457 14.6355 15.8992 18 11.9999 18C10.8611 18 9.76945 17.713 8.7588 17.2646L9.51376 15.957Z"
|
||||||
|
fill="currentColor"
|
||||||
|
/>
|
||||||
|
<rect
|
||||||
|
x="16.0625"
|
||||||
|
y="4.61377"
|
||||||
|
width="1.22727"
|
||||||
|
height="16"
|
||||||
|
transform="rotate(30 16.0625 4.61377)"
|
||||||
|
fill="currentColor"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
);
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
export * from './variations-table';
|
|
@ -0,0 +1,103 @@
|
||||||
|
.woocommerce-product-variations {
|
||||||
|
ol {
|
||||||
|
@media ( min-width: #{ ($break-medium) } ) {
|
||||||
|
min-height: 420px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
> div {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
flex-grow: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__status-dot {
|
||||||
|
margin-right: $gap-smaller;
|
||||||
|
&.green {
|
||||||
|
color: $alert-green;
|
||||||
|
}
|
||||||
|
&.yellow {
|
||||||
|
color: $alert-yellow;
|
||||||
|
}
|
||||||
|
&.red {
|
||||||
|
color: $alert-red;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&__price--fade,
|
||||||
|
&__quantity--fade {
|
||||||
|
opacity: 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__actions {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: flex-end;
|
||||||
|
|
||||||
|
.components-button {
|
||||||
|
position: relative;
|
||||||
|
color: var(--wp-admin-theme-color);
|
||||||
|
|
||||||
|
&:disabled,
|
||||||
|
&[aria-disabled="true"] {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.components-spinner {
|
||||||
|
margin: 4px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.components-button svg {
|
||||||
|
fill: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.components-button--visible {
|
||||||
|
color: $gray-700;
|
||||||
|
}
|
||||||
|
|
||||||
|
.components-button--hidden {
|
||||||
|
color: $alert-red;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.woocommerce-list-item {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: auto 25% 25% 88px;
|
||||||
|
padding: 0;
|
||||||
|
min-height: calc($grid-unit * 9);
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.woocommerce-sortable {
|
||||||
|
margin: 0;
|
||||||
|
flex: 1 0 auto;
|
||||||
|
|
||||||
|
&__item:not(:last-child) .woocommerce-list-item {
|
||||||
|
border-bottom: 1px solid $gray-200;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__handle {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&.is-loading {
|
||||||
|
min-height: 476px;
|
||||||
|
|
||||||
|
.components-spinner {
|
||||||
|
width: 34px;
|
||||||
|
height: 34px;
|
||||||
|
left: 50%;
|
||||||
|
top: 50%;
|
||||||
|
transform: translate(-50%, -50%);
|
||||||
|
position: absolute;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&__footer {
|
||||||
|
padding: $gap;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,288 @@
|
||||||
|
/**
|
||||||
|
* External dependencies
|
||||||
|
*/
|
||||||
|
import { __ } from '@wordpress/i18n';
|
||||||
|
import { Button, Spinner, Tooltip } from '@wordpress/components';
|
||||||
|
import {
|
||||||
|
EXPERIMENTAL_PRODUCT_VARIATIONS_STORE_NAME,
|
||||||
|
ProductAttribute,
|
||||||
|
ProductVariation,
|
||||||
|
} from '@woocommerce/data';
|
||||||
|
import {
|
||||||
|
Link,
|
||||||
|
ListItem,
|
||||||
|
Pagination,
|
||||||
|
Sortable,
|
||||||
|
Tag,
|
||||||
|
} from '@woocommerce/components';
|
||||||
|
import { getNewPath } from '@woocommerce/navigation';
|
||||||
|
import { useContext, useState, createElement } from '@wordpress/element';
|
||||||
|
import { useSelect, useDispatch } from '@wordpress/data';
|
||||||
|
import classnames from 'classnames';
|
||||||
|
import truncate from 'lodash/truncate';
|
||||||
|
import { CurrencyContext } from '@woocommerce/currency';
|
||||||
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
|
// @ts-ignore No types for this exist yet.
|
||||||
|
// eslint-disable-next-line @woocommerce/dependency-group
|
||||||
|
import { useEntityId, useEntityProp } from '@wordpress/core-data';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal dependencies
|
||||||
|
*/
|
||||||
|
import HiddenIcon from './hidden-icon';
|
||||||
|
import VisibleIcon from './visible-icon';
|
||||||
|
import { getProductStockStatus, getProductStockStatusClass } from '../../utils';
|
||||||
|
import {
|
||||||
|
DEFAULT_PER_PAGE_OPTION,
|
||||||
|
PRODUCT_VARIATION_TITLE_LIMIT,
|
||||||
|
} from '../../constants';
|
||||||
|
|
||||||
|
const NOT_VISIBLE_TEXT = __( 'Not visible to customers', 'woocommerce' );
|
||||||
|
const VISIBLE_TEXT = __( 'Visible to customers', 'woocommerce' );
|
||||||
|
const UPDATING_TEXT = __( 'Updating product variation', 'woocommerce' );
|
||||||
|
|
||||||
|
export function VariationsTable() {
|
||||||
|
const [ currentPage, setCurrentPage ] = useState( 1 );
|
||||||
|
const [ perPage, setPerPage ] = useState( DEFAULT_PER_PAGE_OPTION );
|
||||||
|
const [ isUpdating, setIsUpdating ] = useState< Record< string, boolean > >(
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
const [ entityAttributes ] = useEntityProp< ProductAttribute[] >(
|
||||||
|
'postType',
|
||||||
|
'product',
|
||||||
|
'attributes'
|
||||||
|
);
|
||||||
|
const variableAttributeTags = entityAttributes
|
||||||
|
.filter( ( attr ) => attr.variation )
|
||||||
|
.map( ( attr ) => attr.options )
|
||||||
|
.flat();
|
||||||
|
|
||||||
|
const productId = useEntityId( 'postType', 'product' );
|
||||||
|
const context = useContext( CurrencyContext );
|
||||||
|
const { formatAmount } = context;
|
||||||
|
const { isLoading, variations, totalCount } = useSelect(
|
||||||
|
( select ) => {
|
||||||
|
const {
|
||||||
|
getProductVariations,
|
||||||
|
hasFinishedResolution,
|
||||||
|
getProductVariationsTotalCount,
|
||||||
|
} = select( EXPERIMENTAL_PRODUCT_VARIATIONS_STORE_NAME );
|
||||||
|
const requestParams = {
|
||||||
|
product_id: productId,
|
||||||
|
page: currentPage,
|
||||||
|
per_page: perPage,
|
||||||
|
order: 'asc',
|
||||||
|
orderby: 'menu_order',
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
isLoading: ! hasFinishedResolution( 'getProductVariations', [
|
||||||
|
requestParams,
|
||||||
|
] ),
|
||||||
|
variations:
|
||||||
|
getProductVariations< ProductVariation[] >( requestParams ),
|
||||||
|
totalCount:
|
||||||
|
getProductVariationsTotalCount< number >( requestParams ),
|
||||||
|
};
|
||||||
|
},
|
||||||
|
[ currentPage, perPage, productId ]
|
||||||
|
);
|
||||||
|
|
||||||
|
const { updateProductVariation } = useDispatch(
|
||||||
|
EXPERIMENTAL_PRODUCT_VARIATIONS_STORE_NAME
|
||||||
|
);
|
||||||
|
|
||||||
|
if ( ! variations || isLoading ) {
|
||||||
|
return (
|
||||||
|
<div className="woocommerce-product-variations is-loading">
|
||||||
|
<Spinner />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleCustomerVisibilityClick(
|
||||||
|
variationId: number,
|
||||||
|
status: 'private' | 'publish'
|
||||||
|
) {
|
||||||
|
if ( isUpdating[ variationId ] ) return;
|
||||||
|
setIsUpdating( ( prevState ) => ( {
|
||||||
|
...prevState,
|
||||||
|
[ variationId ]: true,
|
||||||
|
} ) );
|
||||||
|
updateProductVariation< Promise< ProductVariation > >(
|
||||||
|
{ product_id: productId, id: variationId },
|
||||||
|
{ status }
|
||||||
|
).finally( () =>
|
||||||
|
setIsUpdating( ( prevState ) => ( {
|
||||||
|
...prevState,
|
||||||
|
[ variationId ]: false,
|
||||||
|
} ) )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="woocommerce-product-variations">
|
||||||
|
<Sortable>
|
||||||
|
{ variations.map( ( variation ) => (
|
||||||
|
<ListItem key={ `${ variation.id }` }>
|
||||||
|
<div className="woocommerce-product-variations__attributes">
|
||||||
|
{ variation.attributes
|
||||||
|
.filter( ( attribute ) =>
|
||||||
|
variableAttributeTags.includes(
|
||||||
|
attribute.option
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.map( ( attribute ) => {
|
||||||
|
const tag = (
|
||||||
|
/* eslint-disable-next-line @typescript-eslint/ban-ts-comment */
|
||||||
|
/* @ts-ignore Additional props are not required. */
|
||||||
|
<Tag
|
||||||
|
id={ attribute.id }
|
||||||
|
className="woocommerce-product-variations__attribute"
|
||||||
|
key={ attribute.id }
|
||||||
|
label={ truncate(
|
||||||
|
attribute.option,
|
||||||
|
{
|
||||||
|
length: PRODUCT_VARIATION_TITLE_LIMIT,
|
||||||
|
}
|
||||||
|
) }
|
||||||
|
screenReaderLabel={
|
||||||
|
attribute.option
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
|
||||||
|
return attribute.option.length <=
|
||||||
|
PRODUCT_VARIATION_TITLE_LIMIT ? (
|
||||||
|
tag
|
||||||
|
) : (
|
||||||
|
<Tooltip
|
||||||
|
key={ attribute.id }
|
||||||
|
text={ attribute.option }
|
||||||
|
position="top center"
|
||||||
|
>
|
||||||
|
<span>{ tag }</span>
|
||||||
|
</Tooltip>
|
||||||
|
);
|
||||||
|
} ) }
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className={ classnames(
|
||||||
|
'woocommerce-product-variations__price',
|
||||||
|
{
|
||||||
|
'woocommerce-product-variations__price--fade':
|
||||||
|
variation.status === 'private',
|
||||||
|
}
|
||||||
|
) }
|
||||||
|
>
|
||||||
|
{ formatAmount( variation.price ) }
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className={ classnames(
|
||||||
|
'woocommerce-product-variations__quantity',
|
||||||
|
{
|
||||||
|
'woocommerce-product-variations__quantity--fade':
|
||||||
|
variation.status === 'private',
|
||||||
|
}
|
||||||
|
) }
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
className={ classnames(
|
||||||
|
'woocommerce-product-variations__status-dot',
|
||||||
|
getProductStockStatusClass( variation )
|
||||||
|
) }
|
||||||
|
>
|
||||||
|
●
|
||||||
|
</span>
|
||||||
|
{ getProductStockStatus( variation ) }
|
||||||
|
</div>
|
||||||
|
<div className="woocommerce-product-variations__actions">
|
||||||
|
{ variation.status === 'private' && (
|
||||||
|
<Tooltip
|
||||||
|
position="top center"
|
||||||
|
text={ NOT_VISIBLE_TEXT }
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
className="components-button--hidden"
|
||||||
|
aria-label={
|
||||||
|
isUpdating[ variation.id ]
|
||||||
|
? UPDATING_TEXT
|
||||||
|
: NOT_VISIBLE_TEXT
|
||||||
|
}
|
||||||
|
aria-disabled={
|
||||||
|
isUpdating[ variation.id ]
|
||||||
|
}
|
||||||
|
onClick={ () =>
|
||||||
|
handleCustomerVisibilityClick(
|
||||||
|
variation.id,
|
||||||
|
'publish'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{ isUpdating[ variation.id ] ? (
|
||||||
|
<Spinner />
|
||||||
|
) : (
|
||||||
|
<HiddenIcon />
|
||||||
|
) }
|
||||||
|
</Button>
|
||||||
|
</Tooltip>
|
||||||
|
) }
|
||||||
|
|
||||||
|
{ variation.status === 'publish' && (
|
||||||
|
<Tooltip
|
||||||
|
position="top center"
|
||||||
|
text={ VISIBLE_TEXT }
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
className="components-button--visible"
|
||||||
|
aria-label={
|
||||||
|
isUpdating[ variation.id ]
|
||||||
|
? UPDATING_TEXT
|
||||||
|
: VISIBLE_TEXT
|
||||||
|
}
|
||||||
|
aria-disabled={
|
||||||
|
isUpdating[ variation.id ]
|
||||||
|
}
|
||||||
|
onClick={ () =>
|
||||||
|
handleCustomerVisibilityClick(
|
||||||
|
variation.id,
|
||||||
|
'private'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{ isUpdating[ variation.id ] ? (
|
||||||
|
<Spinner />
|
||||||
|
) : (
|
||||||
|
<VisibleIcon />
|
||||||
|
) }
|
||||||
|
</Button>
|
||||||
|
</Tooltip>
|
||||||
|
) }
|
||||||
|
|
||||||
|
<Link
|
||||||
|
href={ getNewPath(
|
||||||
|
{},
|
||||||
|
`/product/${ productId }/variation/${ variation.id }`,
|
||||||
|
{}
|
||||||
|
) }
|
||||||
|
type="wc-admin"
|
||||||
|
className="components-button"
|
||||||
|
>
|
||||||
|
{ __( 'Edit', 'woocommerce' ) }
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
</ListItem>
|
||||||
|
) ) }
|
||||||
|
</Sortable>
|
||||||
|
|
||||||
|
<Pagination
|
||||||
|
className="woocommerce-product-variations__footer"
|
||||||
|
page={ currentPage }
|
||||||
|
perPage={ perPage }
|
||||||
|
total={ totalCount }
|
||||||
|
showPagePicker={ false }
|
||||||
|
onPageChange={ setCurrentPage }
|
||||||
|
onPerPageChange={ setPerPage }
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
/**
|
||||||
|
* External dependencies
|
||||||
|
*/
|
||||||
|
import { createElement } from '@wordpress/element';
|
||||||
|
|
||||||
|
export default function VisibleIcon( {
|
||||||
|
width = 24,
|
||||||
|
height = 24,
|
||||||
|
...props
|
||||||
|
}: React.SVGProps< SVGSVGElement > ) {
|
||||||
|
return (
|
||||||
|
<svg
|
||||||
|
{ ...props }
|
||||||
|
width={ width }
|
||||||
|
height={ height }
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
fill="none"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
aria-hidden="true"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
d="M20.1091 11.54C20.3396 11.8116 20.3396 12.1884 20.1091 12.46C19.4144 13.2781 18.266 14.4899 16.8343 15.4921C15.397 16.4982 13.7359 17.25 11.9999 17.25C10.2638 17.25 8.60268 16.4982 7.1654 15.4921C5.73376 14.4899 4.58533 13.2781 3.89066 12.46C3.6601 12.1884 3.6601 11.8116 3.89066 11.54C4.58533 10.7219 5.73376 9.51006 7.1654 8.50792C8.60268 7.50184 10.2638 6.75 11.9999 6.75C13.7359 6.75 15.397 7.50184 16.8343 8.50792C18.266 9.51006 19.4144 10.7219 20.1091 11.54Z"
|
||||||
|
stroke="currentColor"
|
||||||
|
strokeWidth="1.5"
|
||||||
|
strokeLinejoin="round"
|
||||||
|
/>
|
||||||
|
<circle
|
||||||
|
cx="11.9999"
|
||||||
|
cy="11.9999"
|
||||||
|
r="2.67857"
|
||||||
|
stroke="currentColor"
|
||||||
|
strokeWidth="1.5"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
);
|
||||||
|
}
|
|
@ -52,3 +52,13 @@ export const PRODUCT_DETAILS_SLUG = 'product-details';
|
||||||
export const PRODUCT_SCHEDULED_SALE_SLUG = 'product-scheduled-sale';
|
export const PRODUCT_SCHEDULED_SALE_SLUG = 'product-scheduled-sale';
|
||||||
|
|
||||||
export const TRACKS_SOURCE = 'product-block-editor-v1';
|
export const TRACKS_SOURCE = 'product-block-editor-v1';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Since the pagination component does not exposes the way of
|
||||||
|
* changing the per page options which are [25, 50, 75, 100]
|
||||||
|
* the default per page option will be the min in the list to
|
||||||
|
* keep compatibility.
|
||||||
|
*
|
||||||
|
* @see https://github.com/woocommerce/woocommerce/blob/trunk/packages/js/components/src/pagination/index.js#L12
|
||||||
|
*/
|
||||||
|
export const DEFAULT_PER_PAGE_OPTION = 25;
|
||||||
|
|
|
@ -44,6 +44,14 @@ const attributeTerms: Record< number, ProductAttributeTerm[] > = {
|
||||||
menu_order: 0,
|
menu_order: 0,
|
||||||
count: 2,
|
count: 2,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: 66,
|
||||||
|
name: 'Yellow',
|
||||||
|
slug: 'yellow',
|
||||||
|
description: '',
|
||||||
|
menu_order: 0,
|
||||||
|
count: 2,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
3: [
|
3: [
|
||||||
{
|
{
|
||||||
|
@ -353,7 +361,7 @@ describe( 'useProductAttributes', () => {
|
||||||
);
|
);
|
||||||
} );
|
} );
|
||||||
|
|
||||||
it( 'sets terms for any global attributes and options to empty array', async () => {
|
it( 'sets terms for any global attributes and leaves options the same', async () => {
|
||||||
const allAttributes = [
|
const allAttributes = [
|
||||||
{ ...testAttributes[ 0 ] },
|
{ ...testAttributes[ 0 ] },
|
||||||
{ ...testAttributes[ 1 ] },
|
{ ...testAttributes[ 1 ] },
|
||||||
|
@ -375,13 +383,16 @@ describe( 'useProductAttributes', () => {
|
||||||
await waitForNextUpdate();
|
await waitForNextUpdate();
|
||||||
expect( result.current.attributes.length ).toBe( 3 );
|
expect( result.current.attributes.length ).toBe( 3 );
|
||||||
expect( result.current.attributes[ 0 ].terms ).toEqual(
|
expect( result.current.attributes[ 0 ].terms ).toEqual(
|
||||||
attributeTerms[ result.current.attributes[ 0 ].id ]
|
attributeTerms[ result.current.attributes[ 0 ].id ].filter(
|
||||||
|
( t ) => allAttributes[ 1 ].options.includes( t.name )
|
||||||
|
)
|
||||||
|
);
|
||||||
|
expect( result.current.attributes[ 0 ].options ).toEqual(
|
||||||
|
result.current.attributes[ 0 ].options
|
||||||
);
|
);
|
||||||
expect( result.current.attributes[ 0 ].options ).toEqual( [] );
|
|
||||||
expect( result.current.attributes[ 1 ].terms ).toEqual(
|
expect( result.current.attributes[ 1 ].terms ).toEqual(
|
||||||
attributeTerms[ result.current.attributes[ 1 ].id ]
|
attributeTerms[ result.current.attributes[ 1 ].id ]
|
||||||
);
|
);
|
||||||
expect( result.current.attributes[ 1 ].options ).toEqual( [] );
|
|
||||||
} );
|
} );
|
||||||
} );
|
} );
|
||||||
} );
|
} );
|
||||||
|
|
|
@ -14,6 +14,12 @@ import { useCallback, useEffect, useState } from '@wordpress/element';
|
||||||
*/
|
*/
|
||||||
import { sift } from '../utils';
|
import { sift } from '../utils';
|
||||||
|
|
||||||
|
export type EnhancedProductAttribute = ProductAttribute & {
|
||||||
|
isDefault?: boolean;
|
||||||
|
terms?: ProductAttributeTerm[];
|
||||||
|
visible?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
type useProductAttributesProps = {
|
type useProductAttributesProps = {
|
||||||
allAttributes: ProductAttribute[];
|
allAttributes: ProductAttribute[];
|
||||||
isVariationAttributes?: boolean;
|
isVariationAttributes?: boolean;
|
||||||
|
@ -21,11 +27,6 @@ type useProductAttributesProps = {
|
||||||
productId?: number;
|
productId?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type EnhancedProductAttribute = ProductAttribute & {
|
|
||||||
terms?: ProductAttributeTerm[];
|
|
||||||
visible?: boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
const getFilteredAttributes = (
|
const getFilteredAttributes = (
|
||||||
attr: ProductAttribute[],
|
attr: ProductAttribute[],
|
||||||
isVariationAttributes: boolean
|
isVariationAttributes: boolean
|
||||||
|
@ -52,7 +53,6 @@ export function useProductAttributes( {
|
||||||
)
|
)
|
||||||
.getProductAttributeTerms< ProductAttributeTerm[] >( {
|
.getProductAttributeTerms< ProductAttributeTerm[] >( {
|
||||||
attribute_id: attributeId,
|
attribute_id: attributeId,
|
||||||
product: productId,
|
|
||||||
} )
|
} )
|
||||||
.then(
|
.then(
|
||||||
( attributeTerms ) => {
|
( attributeTerms ) => {
|
||||||
|
@ -68,28 +68,29 @@ export function useProductAttributes( {
|
||||||
|
|
||||||
const enhanceAttribute = (
|
const enhanceAttribute = (
|
||||||
globalAttribute: ProductAttribute,
|
globalAttribute: ProductAttribute,
|
||||||
terms: ProductAttributeTerm[]
|
allTerms: ProductAttributeTerm[]
|
||||||
) => {
|
) => {
|
||||||
return {
|
return {
|
||||||
...globalAttribute,
|
...globalAttribute,
|
||||||
terms: terms.length > 0 ? terms : undefined,
|
terms: ( allTerms || [] ).filter( ( term ) =>
|
||||||
options: terms.length === 0 ? globalAttribute.options : [],
|
globalAttribute.options.includes( term.name )
|
||||||
|
),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const getAugmentedAttributes = (
|
const getAugmentedAttributes = (
|
||||||
atts: ProductAttribute[],
|
atts: EnhancedProductAttribute[],
|
||||||
variation: boolean,
|
variation: boolean,
|
||||||
startPosition: number
|
startPosition: number
|
||||||
) => {
|
): ProductAttribute[] => {
|
||||||
return atts.map( ( attribute, index ) => ( {
|
return atts.map( ( { isDefault, terms, ...attribute }, index ) => ( {
|
||||||
...attribute,
|
...attribute,
|
||||||
variation,
|
variation,
|
||||||
position: startPosition + index,
|
position: startPosition + index,
|
||||||
} ) );
|
} ) );
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleChange = ( newAttributes: ProductAttribute[] ) => {
|
const handleChange = ( newAttributes: EnhancedProductAttribute[] ) => {
|
||||||
let otherAttributes = isVariationAttributes
|
let otherAttributes = isVariationAttributes
|
||||||
? allAttributes.filter( ( attribute ) => ! attribute.variation )
|
? allAttributes.filter( ( attribute ) => ! attribute.variation )
|
||||||
: allAttributes.filter( ( attribute ) => !! attribute.variation );
|
: allAttributes.filter( ( attribute ) => !! attribute.variation );
|
||||||
|
|
|
@ -0,0 +1,77 @@
|
||||||
|
/**
|
||||||
|
* External dependencies
|
||||||
|
*/
|
||||||
|
import { useDispatch } from '@wordpress/data';
|
||||||
|
import { useEntityProp } from '@wordpress/core-data';
|
||||||
|
import { useCallback, useState } from '@wordpress/element';
|
||||||
|
import {
|
||||||
|
Product,
|
||||||
|
EXPERIMENTAL_PRODUCT_VARIATIONS_STORE_NAME,
|
||||||
|
} from '@woocommerce/data';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal dependencies
|
||||||
|
*/
|
||||||
|
import { EnhancedProductAttribute } from './use-product-attributes';
|
||||||
|
|
||||||
|
export function useProductVariationsHelper() {
|
||||||
|
const [ productId ] = useEntityProp< number >(
|
||||||
|
'postType',
|
||||||
|
'product',
|
||||||
|
'id'
|
||||||
|
);
|
||||||
|
const { saveEntityRecord } = useDispatch( 'core' );
|
||||||
|
const {
|
||||||
|
generateProductVariations: _generateProductVariations,
|
||||||
|
invalidateResolutionForStoreSelector,
|
||||||
|
} = useDispatch( EXPERIMENTAL_PRODUCT_VARIATIONS_STORE_NAME );
|
||||||
|
|
||||||
|
const [ isGenerating, setIsGenerating ] = useState( false );
|
||||||
|
|
||||||
|
const generateProductVariations = useCallback(
|
||||||
|
async ( attributes: EnhancedProductAttribute[] ) => {
|
||||||
|
setIsGenerating( true );
|
||||||
|
|
||||||
|
const updateProductAttributes = async () => {
|
||||||
|
const hasVariableAttribute = attributes.some(
|
||||||
|
( attr ) => attr.variation
|
||||||
|
);
|
||||||
|
await saveEntityRecord< Promise< Product > >(
|
||||||
|
'postType',
|
||||||
|
'product',
|
||||||
|
{
|
||||||
|
id: productId,
|
||||||
|
type: hasVariableAttribute ? 'variable' : 'simple',
|
||||||
|
attributes,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
return updateProductAttributes()
|
||||||
|
.then( () => {
|
||||||
|
return _generateProductVariations< { count: number } >( {
|
||||||
|
product_id: productId,
|
||||||
|
} );
|
||||||
|
} )
|
||||||
|
.then( ( data ) => {
|
||||||
|
if ( data.count > 0 ) {
|
||||||
|
invalidateResolutionForStoreSelector(
|
||||||
|
'getProductVariations'
|
||||||
|
);
|
||||||
|
return invalidateResolutionForStoreSelector(
|
||||||
|
'getProductVariationsTotalCount'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} )
|
||||||
|
.finally( () => {
|
||||||
|
setIsGenerating( false );
|
||||||
|
} );
|
||||||
|
},
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
generateProductVariations,
|
||||||
|
isGenerating,
|
||||||
|
};
|
||||||
|
}
|
|
@ -31,7 +31,7 @@
|
||||||
@import 'components/attribute-input-field/attribute-input-field.scss';
|
@import 'components/attribute-input-field/attribute-input-field.scss';
|
||||||
@import 'components/attribute-list-item/attribute-list-item.scss';
|
@import 'components/attribute-list-item/attribute-list-item.scss';
|
||||||
@import 'components/attribute-term-input-field/attribute-term-input-field.scss';
|
@import 'components/attribute-term-input-field/attribute-term-input-field.scss';
|
||||||
@import 'components/attribute-term-input-field/create-attribute-term-modal.scss';
|
@import 'components/variations-table/styles.scss';
|
||||||
|
|
||||||
/* Field Blocks */
|
/* Field Blocks */
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ import { isValidEmail } from './validate-email';
|
||||||
|
|
||||||
export * from './create-ordered-children';
|
export * from './create-ordered-children';
|
||||||
export * from './sort-fills-by-order';
|
export * from './sort-fills-by-order';
|
||||||
export * from './init-blocks';
|
export * from './init-block';
|
||||||
export * from './product-apifetch-middleware';
|
export * from './product-apifetch-middleware';
|
||||||
export * from './sift';
|
export * from './sift';
|
||||||
|
|
||||||
|
|
|
@ -2,38 +2,30 @@
|
||||||
* External dependencies
|
* External dependencies
|
||||||
*/
|
*/
|
||||||
import {
|
import {
|
||||||
|
Block,
|
||||||
BlockConfiguration,
|
BlockConfiguration,
|
||||||
BlockEditProps,
|
|
||||||
registerBlockType,
|
registerBlockType,
|
||||||
} from '@wordpress/blocks';
|
} from '@wordpress/blocks';
|
||||||
import { ComponentType } from 'react';
|
|
||||||
|
|
||||||
type BlockRepresentation = {
|
interface BlockRepresentation< T extends Record< string, object > > {
|
||||||
name: string;
|
name?: string;
|
||||||
metadata: BlockConfiguration;
|
metadata: BlockConfiguration< T >;
|
||||||
settings: Partial< Omit< BlockConfiguration, 'edit' > > & {
|
settings: Partial< BlockConfiguration< T > >;
|
||||||
readonly edit?:
|
}
|
||||||
| ComponentType<
|
|
||||||
BlockEditProps< object > & {
|
|
||||||
context?: Record< string, unknown >;
|
|
||||||
}
|
|
||||||
>
|
|
||||||
| undefined;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to register an individual block.
|
* Function to register an individual block.
|
||||||
*
|
*
|
||||||
* @param {Object} block The block to be registered.
|
* @param block The block to be registered.
|
||||||
*
|
* @return The block, if it has been successfully registered; otherwise `undefined`.
|
||||||
* @return {WPBlockType|void} The block, if it has been successfully registered;
|
|
||||||
* otherwise `undefined`.
|
|
||||||
*/
|
*/
|
||||||
export default function initBlock( block: BlockRepresentation ) {
|
export function initBlock<
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
T extends Record< string, any > = Record< string, any >
|
||||||
|
>( block: BlockRepresentation< T > ): Block< T > | undefined {
|
||||||
if ( ! block ) {
|
if ( ! block ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const { metadata, settings, name } = block;
|
const { metadata, settings, name } = block;
|
||||||
return registerBlockType( { name, ...metadata }, settings );
|
return registerBlockType< T >( { name, ...metadata }, settings );
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,31 +0,0 @@
|
||||||
/**
|
|
||||||
* External dependencies
|
|
||||||
*/
|
|
||||||
import {
|
|
||||||
Block,
|
|
||||||
BlockConfiguration,
|
|
||||||
registerBlockType,
|
|
||||||
} from '@wordpress/blocks';
|
|
||||||
|
|
||||||
interface BlockRepresentation< T extends Record< string, object > > {
|
|
||||||
name?: string;
|
|
||||||
metadata: BlockConfiguration< T >;
|
|
||||||
settings: Partial< BlockConfiguration< T > >;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Function to register an individual block.
|
|
||||||
*
|
|
||||||
* @param block The block to be registered.
|
|
||||||
* @return The block, if it has been successfully registered; otherwise `undefined`.
|
|
||||||
*/
|
|
||||||
export function initBlock<
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
T extends Record< string, any > = Record< string, any >
|
|
||||||
>( block: BlockRepresentation< T > ): Block< T > | undefined {
|
|
||||||
if ( ! block ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const { metadata, settings, name } = block;
|
|
||||||
return registerBlockType< T >( { name, ...metadata }, settings );
|
|
||||||
}
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
Significance: minor
|
||||||
|
Type: add
|
||||||
|
|
||||||
|
[Woo AI] Add Store Branding data to product description generation prompt.
|
|
@ -29,6 +29,16 @@ class Woo_AI_Settings {
|
||||||
*/
|
*/
|
||||||
protected $id = 'woo-ai-settings-tab';
|
protected $id = 'woo-ai-settings-tab';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tone of voice select options.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private $tone_of_voice_select_options;
|
||||||
|
|
||||||
|
private const STORE_DESCRIPTION_OPTION_KEY = 'woo_ai_describe_store_description';
|
||||||
|
private const TONE_OF_VOICE_OPTION_KEY = 'woo_ai_tone_of_voice_select';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main Instance.
|
* Main Instance.
|
||||||
*/
|
*/
|
||||||
|
@ -44,10 +54,64 @@ class Woo_AI_Settings {
|
||||||
add_action( 'admin_enqueue_scripts', array( $this, 'add_woo_ai_settings_script' ) );
|
add_action( 'admin_enqueue_scripts', array( $this, 'add_woo_ai_settings_script' ) );
|
||||||
add_action( 'woocommerce_settings_save_advanced', array( $this, 'action_save_woo_ai_settings_tab' ) );
|
add_action( 'woocommerce_settings_save_advanced', array( $this, 'action_save_woo_ai_settings_tab' ) );
|
||||||
add_action( 'woocommerce_settings_page_init', array( $this, 'add_ui' ) );
|
add_action( 'woocommerce_settings_page_init', array( $this, 'add_ui' ) );
|
||||||
|
add_filter( 'woocommerce_settings_groups', array( $this, 'add_woo_ai_settings_group' ) );
|
||||||
|
add_filter( 'woocommerce_settings-woo-ai', array( $this, 'add_woo_ai_settings_group_settings' ) );
|
||||||
|
|
||||||
|
$this->tone_of_voice_select_options = array(
|
||||||
|
'informal' => __( 'Informal', 'woocommerce' ),
|
||||||
|
'humorous' => __( 'Humorous', 'woocommerce' ),
|
||||||
|
'neutral' => __( 'Neutral', 'woocommerce' ),
|
||||||
|
'youthful' => __( 'Youthful', 'woocommerce' ),
|
||||||
|
'formal' => __( 'Formal', 'woocommerce' ),
|
||||||
|
'motivational' => __( 'Motivational', 'woocommerce' ),
|
||||||
|
);
|
||||||
|
|
||||||
$this->add_sanitization_hooks();
|
$this->add_sanitization_hooks();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds settings which can be retrieved via the WooCommerce Settings API.
|
||||||
|
*
|
||||||
|
* @see https://github.com/woocommerce/woocommerce/wiki/Settings-API
|
||||||
|
*
|
||||||
|
* @param array $settings The original settings array.
|
||||||
|
* @return array The modified settings array.
|
||||||
|
*/
|
||||||
|
public function add_woo_ai_settings_group_settings( $settings ) {
|
||||||
|
$settings[] = array(
|
||||||
|
'id' => 'tone-of-voice',
|
||||||
|
'option_key' => self::TONE_OF_VOICE_OPTION_KEY,
|
||||||
|
'label' => __( 'Storewide Tone of Voice', 'woocommerce' ),
|
||||||
|
'description' => __( 'This controls the conversational tone that will be used when generating content.', 'woocommerce' ),
|
||||||
|
'default' => 'neutral',
|
||||||
|
'type' => 'select',
|
||||||
|
'options' => $this->tone_of_voice_select_options,
|
||||||
|
);
|
||||||
|
$settings[] = array(
|
||||||
|
'id' => 'store-description',
|
||||||
|
'option_key' => self::STORE_DESCRIPTION_OPTION_KEY,
|
||||||
|
'label' => __( 'Store Description', 'woocommerce' ),
|
||||||
|
'description' => __( 'This is a short description of your store which could be used to help generate content.', 'woocommerce' ),
|
||||||
|
'type' => 'textarea',
|
||||||
|
);
|
||||||
|
return $settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register our Woo AI plugin group to the WooCommerce Settings API.
|
||||||
|
*
|
||||||
|
* @param array $locations The original settings array.
|
||||||
|
* @return array The modified settings array.
|
||||||
|
*/
|
||||||
|
public function add_woo_ai_settings_group( $locations ) {
|
||||||
|
$locations[] = array(
|
||||||
|
'id' => 'woo-ai',
|
||||||
|
'label' => __( 'Woo AI', 'woocommerce' ),
|
||||||
|
'description' => __( 'Settings for the Woo AI plugin.', 'woocommerce' ),
|
||||||
|
);
|
||||||
|
return $locations;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add UI related hooks.
|
* Add UI related hooks.
|
||||||
*/
|
*/
|
||||||
|
@ -147,25 +211,18 @@ class Woo_AI_Settings {
|
||||||
|
|
||||||
array(
|
array(
|
||||||
'title' => __( 'Tone of voice', 'woocommerce' ),
|
'title' => __( 'Tone of voice', 'woocommerce' ),
|
||||||
'id' => 'woo_ai_tone_of_voice_select',
|
'id' => self::TONE_OF_VOICE_OPTION_KEY,
|
||||||
'css' => 'min-width:300px;',
|
'css' => 'min-width:300px;',
|
||||||
'default' => 'neutral',
|
'default' => 'neutral',
|
||||||
'type' => 'select',
|
'type' => 'select',
|
||||||
'desc' => $markup_str,
|
'desc' => $markup_str,
|
||||||
'desc_tip' => __( 'Choose the language style that best resonates with your customers. It\'ll be used in text-based content, like product descriptions.', 'woocommerce' ),
|
'desc_tip' => __( 'Choose the language style that best resonates with your customers. It\'ll be used in text-based content, like product descriptions.', 'woocommerce' ),
|
||||||
'custom_attributes' => array( 'disabled' => 'true' ),
|
'custom_attributes' => array( 'disabled' => 'true' ),
|
||||||
'options' => array(
|
'options' => $this->tone_of_voice_select_options,
|
||||||
'informal' => esc_html__( 'Informal', 'woocommerce' ),
|
|
||||||
'humorous' => esc_html__( 'Humorous', 'woocommerce' ),
|
|
||||||
'neutral' => esc_html__( 'Neutral', 'woocommerce' ),
|
|
||||||
'youthful' => esc_html__( 'Youthful', 'woocommerce' ),
|
|
||||||
'formal' => esc_html__( 'Formal', 'woocommerce' ),
|
|
||||||
'motivational' => esc_html__( 'Motivational', 'woocommerce' ),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
|
|
||||||
array(
|
array(
|
||||||
'id' => 'woo_ai_describe_store_description',
|
'id' => self::STORE_DESCRIPTION_OPTION_KEY,
|
||||||
'type' => 'textarea',
|
'type' => 'textarea',
|
||||||
'custom_attributes' => array( 'disabled' => 'true' ),
|
'custom_attributes' => array( 'disabled' => 'true' ),
|
||||||
'title' => __( 'Describe your business', 'woocommerce' ),
|
'title' => __( 'Describe your business', 'woocommerce' ),
|
||||||
|
|
|
@ -39,9 +39,11 @@
|
||||||
"@wordpress/element": "wp-6.0",
|
"@wordpress/element": "wp-6.0",
|
||||||
"@wordpress/hooks": "wp-6.0",
|
"@wordpress/hooks": "wp-6.0",
|
||||||
"@wordpress/i18n": "wp-6.0",
|
"@wordpress/i18n": "wp-6.0",
|
||||||
|
"@wordpress/notices": "wp-6.0",
|
||||||
"@wordpress/plugins": "wp-6.0",
|
"@wordpress/plugins": "wp-6.0",
|
||||||
"debug": "^4.3.3",
|
"debug": "^4.3.3",
|
||||||
"prop-types": "^15.8.1"
|
"prop-types": "^15.8.1",
|
||||||
|
"react-query": "^3.39.3"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@types/react": "^17.0.2",
|
"@types/react": "^17.0.2",
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
declare module '@wordpress/notices';
|
||||||
|
declare module '@wordpress/data';
|
|
@ -1,3 +1,4 @@
|
||||||
export * from './useTinyEditor';
|
export * from './useTinyEditor';
|
||||||
export * from './useFeedbackSnackbar';
|
export * from './useFeedbackSnackbar';
|
||||||
export * from './useProductSlug';
|
export * from './useProductSlug';
|
||||||
|
export * from './useStoreBranding';
|
||||||
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
/**
|
||||||
|
* External dependencies
|
||||||
|
*/
|
||||||
|
import { useEffect } from 'react';
|
||||||
|
import { useQuery, UseQueryResult } from 'react-query';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal dependencies
|
||||||
|
*/
|
||||||
|
import { getToneOfVoice, getBusinessDescription } from '../utils/branding';
|
||||||
|
|
||||||
|
// Define your data type
|
||||||
|
interface BrandingData {
|
||||||
|
toneOfVoice: string;
|
||||||
|
businessDescription: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Define your error type
|
||||||
|
interface BrandingError {
|
||||||
|
message: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
type UseStoreBrandingOptions = {
|
||||||
|
onError?: ( error: BrandingError ) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Async function to fetch branding data
|
||||||
|
async function fetchBrandingData(): Promise< BrandingData > {
|
||||||
|
const [ toneOfVoice, businessDescription ] = await Promise.all( [
|
||||||
|
getToneOfVoice(),
|
||||||
|
getBusinessDescription(),
|
||||||
|
] );
|
||||||
|
|
||||||
|
return { toneOfVoice, businessDescription };
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useStoreBranding( {
|
||||||
|
onError,
|
||||||
|
}: UseStoreBrandingOptions = {} ): UseQueryResult<
|
||||||
|
BrandingData,
|
||||||
|
BrandingError
|
||||||
|
> {
|
||||||
|
const result = useQuery< BrandingData, BrandingError >(
|
||||||
|
'storeBranding',
|
||||||
|
fetchBrandingData,
|
||||||
|
{
|
||||||
|
refetchOnWindowFocus: false, // Do not refetch when window gains focus
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect( () => {
|
||||||
|
if ( result.isError && onError ) {
|
||||||
|
onError( result.error as BrandingError );
|
||||||
|
}
|
||||||
|
}, [ result.isError, result.error, onError ] );
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
|
@ -2,6 +2,7 @@
|
||||||
* External dependencies
|
* External dependencies
|
||||||
*/
|
*/
|
||||||
import { render, createRoot } from '@wordpress/element';
|
import { render, createRoot } from '@wordpress/element';
|
||||||
|
import { QueryClient, QueryClientProvider } from 'react-query';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
|
@ -11,15 +12,23 @@ import { ProductNameSuggestions } from './product-name';
|
||||||
|
|
||||||
import './index.scss';
|
import './index.scss';
|
||||||
|
|
||||||
|
const queryClient = new QueryClient();
|
||||||
|
|
||||||
const renderComponent = ( Component, rootElement ) => {
|
const renderComponent = ( Component, rootElement ) => {
|
||||||
if ( ! rootElement ) {
|
if ( ! rootElement ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const WrappedComponent = () => (
|
||||||
|
<QueryClientProvider client={ queryClient }>
|
||||||
|
<Component />
|
||||||
|
</QueryClientProvider>
|
||||||
|
);
|
||||||
|
|
||||||
if ( createRoot ) {
|
if ( createRoot ) {
|
||||||
createRoot( rootElement ).render( <Component /> );
|
createRoot( rootElement ).render( <WrappedComponent /> );
|
||||||
} else {
|
} else {
|
||||||
render( <Component />, rootElement );
|
render( <WrappedComponent />, rootElement );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
/**
|
/**
|
||||||
* External dependencies
|
* External dependencies
|
||||||
*/
|
*/
|
||||||
|
import { useDispatch } from '@wordpress/data';
|
||||||
|
import { store as noticesStore } from '@wordpress/notices';
|
||||||
import { __ } from '@wordpress/i18n';
|
import { __ } from '@wordpress/i18n';
|
||||||
import { useState, useEffect, useRef } from '@wordpress/element';
|
import { useState, useEffect, useRef } from '@wordpress/element';
|
||||||
import {
|
import {
|
||||||
__experimentalUseCompletion as useCompletion,
|
__experimentalUseCompletion as useCompletion,
|
||||||
UseCompletionError,
|
UseCompletionError,
|
||||||
} from '@woocommerce/ai';
|
} from '@woocommerce/ai';
|
||||||
import { useDispatch } from '@wordpress/data';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
|
@ -18,7 +19,7 @@ import {
|
||||||
WOO_AI_PLUGIN_FEATURE_NAME,
|
WOO_AI_PLUGIN_FEATURE_NAME,
|
||||||
} from '../constants';
|
} from '../constants';
|
||||||
import { StopCompletionBtn, WriteItForMeBtn } from '../components';
|
import { StopCompletionBtn, WriteItForMeBtn } from '../components';
|
||||||
import { useFeedbackSnackbar, useTinyEditor } from '../hooks';
|
import { useFeedbackSnackbar, useStoreBranding, useTinyEditor } from '../hooks';
|
||||||
import {
|
import {
|
||||||
getProductName,
|
getProductName,
|
||||||
getPostId,
|
getPostId,
|
||||||
|
@ -65,6 +66,28 @@ export function WriteItForMeButtonContainer() {
|
||||||
const [ productTitle, setProductTitle ] = useState< string >(
|
const [ productTitle, setProductTitle ] = useState< string >(
|
||||||
titleEl.current?.value || ''
|
titleEl.current?.value || ''
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const { createErrorNotice } = useDispatch( noticesStore );
|
||||||
|
const [ errorNoticeDismissed, setErrorNoticeDismissed ] = useState( false );
|
||||||
|
const { data: brandingData } = useStoreBranding( {
|
||||||
|
onError: () => {
|
||||||
|
if ( ! errorNoticeDismissed ) {
|
||||||
|
createErrorNotice(
|
||||||
|
__(
|
||||||
|
'Error fetching branding data, content generation may be degraded.',
|
||||||
|
'woocommerce'
|
||||||
|
),
|
||||||
|
{
|
||||||
|
id: 'woo-ai-branding-error',
|
||||||
|
type: 'snackbar',
|
||||||
|
isDismissible: true,
|
||||||
|
onDismiss: () => setErrorNoticeDismissed( true ),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
} );
|
||||||
|
|
||||||
const tinyEditor = useTinyEditor();
|
const tinyEditor = useTinyEditor();
|
||||||
const shortTinyEditor = useTinyEditor( 'excerpt' );
|
const shortTinyEditor = useTinyEditor( 'excerpt' );
|
||||||
|
|
||||||
|
@ -174,7 +197,7 @@ export function WriteItForMeButtonContainer() {
|
||||||
productPropsInstructions.push(
|
productPropsInstructions.push(
|
||||||
`Tagged with: ${ productTags.join( ', ' ) }.`
|
`Tagged with: ${ productTags.join( ', ' ) }.`
|
||||||
);
|
);
|
||||||
includedProps.push( 'categories' );
|
includedProps.push( 'tags' );
|
||||||
}
|
}
|
||||||
productAttributes.forEach( ( { name, values } ) => {
|
productAttributes.forEach( ( { name, values } ) => {
|
||||||
productPropsInstructions.push(
|
productPropsInstructions.push(
|
||||||
|
@ -183,21 +206,41 @@ export function WriteItForMeButtonContainer() {
|
||||||
includedProps.push( name );
|
includedProps.push( name );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
return [
|
// WooCommerce doesn't set a limit for the product title. Set a limit to control the token usage.
|
||||||
`Compose an engaging product description for a product named "${ productName.slice(
|
const truncatedProductName = productName.slice( 0, MAX_TITLE_LENGTH );
|
||||||
0,
|
|
||||||
MAX_TITLE_LENGTH
|
const instructions = [
|
||||||
) }".`,
|
`Compose an engaging product description for a product named "${ truncatedProductName }."`,
|
||||||
...productPropsInstructions,
|
...productPropsInstructions,
|
||||||
'Identify the language used in the product name, and craft the description in the same language.',
|
`Use a 9th grade reading level.`,
|
||||||
`Ensure the description is concise, containing no more than ${ DESCRIPTION_MAX_LENGTH } words.`,
|
`Ensure the description is concise, containing no more than ${ DESCRIPTION_MAX_LENGTH } words.`,
|
||||||
'Structure the content into paragraphs using <p> tags, and use HTML elements like <strong> and <em> for emphasis.',
|
'Structure the content into paragraphs using <p> tags, and use HTML elements like <strong> and <em> for emphasis.',
|
||||||
'Only if appropriate, use <ul> and <li> for listing product features.',
|
'Identify the language used in the product name, and craft the description in the same language.',
|
||||||
|
'Only if appropriate, use <ul> and <li> tags to list product features.',
|
||||||
|
'Do not include a top-level heading at the beginning of the description.',
|
||||||
|
];
|
||||||
|
|
||||||
|
if ( includedProps.length > 0 ) {
|
||||||
|
instructions.push(
|
||||||
`Avoid including the properties (${ includedProps.join(
|
`Avoid including the properties (${ includedProps.join(
|
||||||
', '
|
', '
|
||||||
) }) directly in the description, but utilize them to create an engaging and enticing portrayal of the product.`,
|
) }) directly in the description, but utilize them to create an engaging and enticing portrayal of the product.`
|
||||||
'Do not include a top-level heading at the beginning description.',
|
);
|
||||||
].join( ' ' );
|
}
|
||||||
|
|
||||||
|
if ( brandingData?.toneOfVoice ) {
|
||||||
|
instructions.push(
|
||||||
|
`Generate the description using a ${ brandingData.toneOfVoice } tone.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( brandingData?.businessDescription ) {
|
||||||
|
instructions.push(
|
||||||
|
`For more context on the business, refer to the following business description: "${ brandingData.businessDescription }."`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return instructions.join( '\n' );
|
||||||
};
|
};
|
||||||
|
|
||||||
const onWriteItForMeClick = async () => {
|
const onWriteItForMeClick = async () => {
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
/**
|
||||||
|
* External dependencies
|
||||||
|
*/
|
||||||
|
import apiFetch from '@wordpress/api-fetch';
|
||||||
|
|
||||||
|
// Define the expected shape of the API response
|
||||||
|
type ApiResponse = {
|
||||||
|
value: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch the tone of voice setting.
|
||||||
|
*
|
||||||
|
* @return {Promise<string>} A promise that resolves with the tone of voice or 'neutral' if the API call fails.
|
||||||
|
*/
|
||||||
|
export async function getToneOfVoice(): Promise< string > {
|
||||||
|
try {
|
||||||
|
const { value } = await apiFetch< ApiResponse >( {
|
||||||
|
path: '/wc/v3/settings/woo-ai/tone-of-voice',
|
||||||
|
} );
|
||||||
|
return value;
|
||||||
|
} catch ( error ) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch the business description setting.
|
||||||
|
*
|
||||||
|
* @return {Promise<string>} A promise that resolves with the business description.
|
||||||
|
*/
|
||||||
|
export async function getBusinessDescription(): Promise< string > {
|
||||||
|
try {
|
||||||
|
const { value } = await apiFetch< ApiResponse >( {
|
||||||
|
path: '/wc/v3/settings/woo-ai/store-description',
|
||||||
|
} );
|
||||||
|
return value;
|
||||||
|
} catch ( error ) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
|
@ -342,22 +342,27 @@ const redirectToJetpackAuthPage = (
|
||||||
window.location.href = event.data.url + '&installed_ext_success=1';
|
window.location.href = event.data.url + '&installed_ext_success=1';
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateTrackingOption = (
|
const updateTrackingOption = async (
|
||||||
_context: CoreProfilerStateMachineContext,
|
context: CoreProfilerStateMachineContext
|
||||||
event: IntroOptInEvent
|
|
||||||
) => {
|
) => {
|
||||||
|
await new Promise< void >( ( resolve ) => {
|
||||||
if (
|
if (
|
||||||
event.payload.optInDataSharing &&
|
context.optInDataSharing &&
|
||||||
typeof window.wcTracks.enable === 'function'
|
typeof window.wcTracks.enable === 'function'
|
||||||
) {
|
) {
|
||||||
window.wcTracks.enable( () => {
|
window.wcTracks.enable( () => {
|
||||||
initializeExPlat();
|
initializeExPlat();
|
||||||
|
resolve(); // resolve the promise only after explat is enabled by the callback
|
||||||
} );
|
} );
|
||||||
} else if ( ! event.payload.optInDataSharing ) {
|
} else {
|
||||||
|
if ( ! context.optInDataSharing ) {
|
||||||
window.wcTracks.isEnabled = false;
|
window.wcTracks.isEnabled = false;
|
||||||
}
|
}
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
|
||||||
const trackingValue = event.payload.optInDataSharing ? 'yes' : 'no';
|
const trackingValue = context.optInDataSharing ? 'yes' : 'no';
|
||||||
dispatch( OPTIONS_STORE_NAME ).updateOptions( {
|
dispatch( OPTIONS_STORE_NAME ).updateOptions( {
|
||||||
woocommerce_allow_tracking: trackingValue,
|
woocommerce_allow_tracking: trackingValue,
|
||||||
} );
|
} );
|
||||||
|
@ -563,7 +568,6 @@ const coreProfilerMachineActions = {
|
||||||
...recordTracksActions,
|
...recordTracksActions,
|
||||||
handlePlugins,
|
handlePlugins,
|
||||||
updateQueryStep,
|
updateQueryStep,
|
||||||
updateTrackingOption,
|
|
||||||
handleTrackingOption,
|
handleTrackingOption,
|
||||||
handleGeolocation,
|
handleGeolocation,
|
||||||
handleStoreNameOption,
|
handleStoreNameOption,
|
||||||
|
@ -591,6 +595,7 @@ const coreProfilerMachineServices = {
|
||||||
getPlugins,
|
getPlugins,
|
||||||
browserPopstateHandler,
|
browserPopstateHandler,
|
||||||
updateBusinessInfo,
|
updateBusinessInfo,
|
||||||
|
updateTrackingOption,
|
||||||
};
|
};
|
||||||
export const coreProfilerStateMachineDefinition = createMachine( {
|
export const coreProfilerStateMachineDefinition = createMachine( {
|
||||||
id: 'coreProfiler',
|
id: 'coreProfiler',
|
||||||
|
@ -725,11 +730,8 @@ export const coreProfilerStateMachineDefinition = createMachine( {
|
||||||
introOptIn: {
|
introOptIn: {
|
||||||
on: {
|
on: {
|
||||||
INTRO_COMPLETED: {
|
INTRO_COMPLETED: {
|
||||||
target: '#userProfile',
|
target: 'postIntroOptIn',
|
||||||
actions: [
|
actions: [ 'assignOptInDataSharing' ],
|
||||||
'assignOptInDataSharing',
|
|
||||||
'updateTrackingOption',
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
INTRO_SKIPPED: {
|
INTRO_SKIPPED: {
|
||||||
// if the user skips the intro, we set the optInDataSharing to false and go to the Business Location page
|
// if the user skips the intro, we set the optInDataSharing to false and go to the Business Location page
|
||||||
|
@ -740,35 +742,20 @@ export const coreProfilerStateMachineDefinition = createMachine( {
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
entry: [
|
|
||||||
{
|
|
||||||
type: 'recordTracksStepViewed',
|
|
||||||
step: 'intro_opt_in',
|
|
||||||
},
|
|
||||||
{ type: 'updateQueryStep', step: 'intro-opt-in' },
|
|
||||||
],
|
|
||||||
exit: actions.choose( [
|
|
||||||
{
|
|
||||||
cond: ( _context, event ) =>
|
|
||||||
event.type === 'INTRO_COMPLETED',
|
|
||||||
actions: 'recordTracksIntroCompleted',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
cond: ( _context, event ) =>
|
|
||||||
event.type === 'INTRO_SKIPPED',
|
|
||||||
actions: [
|
|
||||||
{
|
|
||||||
type: 'recordTracksStepSkipped',
|
|
||||||
step: 'intro_opt_in',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
] ),
|
|
||||||
meta: {
|
meta: {
|
||||||
progress: 20,
|
progress: 20,
|
||||||
component: IntroOptIn,
|
component: IntroOptIn,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
postIntroOptIn: {
|
||||||
|
invoke: {
|
||||||
|
src: 'updateTrackingOption',
|
||||||
|
onDone: {
|
||||||
|
actions: [ 'recordTracksIntroCompleted' ],
|
||||||
|
target: '#userProfile',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
userProfile: {
|
userProfile: {
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
export * from './options';
|
|
|
@ -1,79 +0,0 @@
|
||||||
/**
|
|
||||||
* External dependencies
|
|
||||||
*/
|
|
||||||
import { __ } from '@wordpress/i18n';
|
|
||||||
import { Product, ProductAttribute } from '@woocommerce/data';
|
|
||||||
import { recordEvent } from '@woocommerce/tracks';
|
|
||||||
import { useFormContext } from '@woocommerce/components';
|
|
||||||
import { AttributeControl } from '@woocommerce/product-editor/src/components/attribute-control';
|
|
||||||
import { useProductAttributes } from '@woocommerce/product-editor/src/hooks/use-product-attributes';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Internal dependencies
|
|
||||||
*/
|
|
||||||
import { useProductVariationsHelper } from '../../hooks/use-product-variations-helper';
|
|
||||||
|
|
||||||
type OptionsProps = {
|
|
||||||
value: ProductAttribute[];
|
|
||||||
onChange: ( value: ProductAttribute[] ) => void;
|
|
||||||
productId?: number;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const Options: React.FC< OptionsProps > = ( {
|
|
||||||
value,
|
|
||||||
onChange,
|
|
||||||
productId,
|
|
||||||
} ) => {
|
|
||||||
const { values } = useFormContext< Product >();
|
|
||||||
const { generateProductVariations } = useProductVariationsHelper();
|
|
||||||
|
|
||||||
const { attributes, handleChange } = useProductAttributes( {
|
|
||||||
allAttributes: value,
|
|
||||||
isVariationAttributes: true,
|
|
||||||
onChange: ( newAttributes ) => {
|
|
||||||
onChange( newAttributes );
|
|
||||||
generateProductVariations( {
|
|
||||||
...values,
|
|
||||||
attributes: newAttributes,
|
|
||||||
} );
|
|
||||||
},
|
|
||||||
productId,
|
|
||||||
} );
|
|
||||||
|
|
||||||
return (
|
|
||||||
<AttributeControl
|
|
||||||
value={ attributes }
|
|
||||||
onAdd={ () => {
|
|
||||||
recordEvent( 'product_add_options_modal_add_button_click' );
|
|
||||||
} }
|
|
||||||
onChange={ handleChange }
|
|
||||||
onNewModalCancel={ () => {
|
|
||||||
recordEvent( 'product_add_options_modal_cancel_button_click' );
|
|
||||||
} }
|
|
||||||
onNewModalOpen={ () => {
|
|
||||||
if ( ! attributes.length ) {
|
|
||||||
recordEvent( 'product_add_first_option_button_click' );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
recordEvent( 'product_add_option_button' );
|
|
||||||
} }
|
|
||||||
uiStrings={ {
|
|
||||||
emptyStateSubtitle: __( 'No options yet', 'woocommerce' ),
|
|
||||||
newAttributeListItemLabel: __( 'Add option', 'woocommerce' ),
|
|
||||||
newAttributeModalTitle: __( 'Add options', 'woocommerce' ),
|
|
||||||
globalAttributeHelperMessage: __(
|
|
||||||
`You can change the option's name in {{link}}Attributes{{/link}}.`,
|
|
||||||
'woocommerce'
|
|
||||||
),
|
|
||||||
} }
|
|
||||||
onRemove={ () =>
|
|
||||||
recordEvent(
|
|
||||||
'product_remove_option_confirmation_confirm_click'
|
|
||||||
)
|
|
||||||
}
|
|
||||||
onRemoveCancel={ () =>
|
|
||||||
recordEvent( 'product_remove_option_confirmation_cancel_click' )
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
};
|
|
|
@ -20,7 +20,6 @@ import { PricingSectionFills } from './pricing-section';
|
||||||
import { InventorySectionFills } from './inventory-section';
|
import { InventorySectionFills } from './inventory-section';
|
||||||
import { AttributesSectionFills } from './attributes-section';
|
import { AttributesSectionFills } from './attributes-section';
|
||||||
import { ImagesSectionFills } from './images-section';
|
import { ImagesSectionFills } from './images-section';
|
||||||
import { OptionsSection } from '../sections/options-section';
|
|
||||||
import { ProductVariationsSection } from '../sections/product-variations-section';
|
import { ProductVariationsSection } from '../sections/product-variations-section';
|
||||||
import {
|
import {
|
||||||
TAB_GENERAL_ID,
|
TAB_GENERAL_ID,
|
||||||
|
@ -113,7 +112,6 @@ const Tabs = () => {
|
||||||
tabProps={ tabPropData.options }
|
tabProps={ tabPropData.options }
|
||||||
>
|
>
|
||||||
<>
|
<>
|
||||||
<OptionsSection />
|
|
||||||
<ProductVariationsSection />
|
<ProductVariationsSection />
|
||||||
</>
|
</>
|
||||||
</WooProductTabItem>
|
</WooProductTabItem>
|
||||||
|
|
|
@ -1,70 +0,0 @@
|
||||||
/**
|
|
||||||
* External dependencies
|
|
||||||
*/
|
|
||||||
import { AUTO_DRAFT_NAME } from '@woocommerce/product-editor';
|
|
||||||
import { useDispatch } from '@wordpress/data';
|
|
||||||
import { useCallback, useState } from '@wordpress/element';
|
|
||||||
import {
|
|
||||||
Product,
|
|
||||||
EXPERIMENTAL_PRODUCT_VARIATIONS_STORE_NAME,
|
|
||||||
PRODUCTS_STORE_NAME,
|
|
||||||
} from '@woocommerce/data';
|
|
||||||
import { useFormContext } from '@woocommerce/components';
|
|
||||||
|
|
||||||
export function useProductVariationsHelper() {
|
|
||||||
const {
|
|
||||||
generateProductVariations: _generateProductVariations,
|
|
||||||
invalidateResolutionForStoreSelector,
|
|
||||||
} = useDispatch( EXPERIMENTAL_PRODUCT_VARIATIONS_STORE_NAME );
|
|
||||||
const { createProduct, updateProduct } = useDispatch( PRODUCTS_STORE_NAME );
|
|
||||||
const { resetForm } = useFormContext< Product >();
|
|
||||||
|
|
||||||
const [ isGenerating, setIsGenerating ] = useState( false );
|
|
||||||
|
|
||||||
const generateProductVariations = useCallback(
|
|
||||||
async ( product: Partial< Product > ) => {
|
|
||||||
setIsGenerating( true );
|
|
||||||
|
|
||||||
const createOrUpdateProduct = product.id
|
|
||||||
? () =>
|
|
||||||
updateProduct< Promise< Product > >(
|
|
||||||
product.id,
|
|
||||||
product
|
|
||||||
)
|
|
||||||
: () => {
|
|
||||||
return createProduct< Promise< Product > >( {
|
|
||||||
...product,
|
|
||||||
status: 'auto-draft',
|
|
||||||
name: product.name || AUTO_DRAFT_NAME,
|
|
||||||
} );
|
|
||||||
};
|
|
||||||
|
|
||||||
return createOrUpdateProduct()
|
|
||||||
.then( ( createdOrUpdatedProduct ) => {
|
|
||||||
if ( ! product.id ) {
|
|
||||||
resetForm( {
|
|
||||||
...createdOrUpdatedProduct,
|
|
||||||
name: product.name || '',
|
|
||||||
} );
|
|
||||||
}
|
|
||||||
return _generateProductVariations( {
|
|
||||||
product_id: createdOrUpdatedProduct.id,
|
|
||||||
} );
|
|
||||||
} )
|
|
||||||
.then( () => {
|
|
||||||
return invalidateResolutionForStoreSelector(
|
|
||||||
'getProductVariations'
|
|
||||||
);
|
|
||||||
} )
|
|
||||||
.finally( () => {
|
|
||||||
setIsGenerating( false );
|
|
||||||
} );
|
|
||||||
},
|
|
||||||
[]
|
|
||||||
);
|
|
||||||
|
|
||||||
return {
|
|
||||||
generateProductVariations,
|
|
||||||
isGenerating,
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -1,6 +0,0 @@
|
||||||
.woocommerce-product-options-section.woocommerce-form-section {
|
|
||||||
.woocommerce-form-section__content {
|
|
||||||
padding: 0;
|
|
||||||
border: 0;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,55 +0,0 @@
|
||||||
/**
|
|
||||||
* External dependencies
|
|
||||||
*/
|
|
||||||
import { __ } from '@wordpress/i18n';
|
|
||||||
import { Link, useFormContext } from '@woocommerce/components';
|
|
||||||
import { Product } from '@woocommerce/data';
|
|
||||||
import { recordEvent } from '@woocommerce/tracks';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Internal dependencies
|
|
||||||
*/
|
|
||||||
import './options-section.scss';
|
|
||||||
import { ProductSectionLayout } from '../layout/product-section-layout';
|
|
||||||
import { Options } from '../fields/options';
|
|
||||||
|
|
||||||
export const OptionsSection: React.FC = () => {
|
|
||||||
const {
|
|
||||||
getInputProps,
|
|
||||||
values: { id: productId },
|
|
||||||
} = useFormContext< Product >();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<ProductSectionLayout
|
|
||||||
title={ __( 'Options', 'woocommerce' ) }
|
|
||||||
className="woocommerce-product-options-section"
|
|
||||||
description={
|
|
||||||
<>
|
|
||||||
<span>
|
|
||||||
{ __(
|
|
||||||
'Add and manage options, such as size and color, for customers to choose on the product page.',
|
|
||||||
'woocommerce'
|
|
||||||
) }
|
|
||||||
</span>
|
|
||||||
<Link
|
|
||||||
className="woocommerce-form-section__header-link"
|
|
||||||
href="https://woocommerce.com/document/managing-product-taxonomies/#product-attributes"
|
|
||||||
target="_blank"
|
|
||||||
type="external"
|
|
||||||
onClick={ () => {
|
|
||||||
recordEvent( 'learn_more_about_options_help' );
|
|
||||||
} }
|
|
||||||
>
|
|
||||||
{ __( 'Learn more about options', 'woocommerce' ) }
|
|
||||||
</Link>
|
|
||||||
</>
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<Options
|
|
||||||
{ ...getInputProps( 'attributes', {
|
|
||||||
productId,
|
|
||||||
} ) }
|
|
||||||
/>
|
|
||||||
</ProductSectionLayout>
|
|
||||||
);
|
|
||||||
};
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"phpVersion": "7.4",
|
||||||
|
"plugins": [
|
||||||
|
".",
|
||||||
|
"https://downloads.wordpress.org/plugin/woocommerce.zip"
|
||||||
|
]
|
||||||
|
}
|
|
@ -1,4 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
defined( 'ABSPATH' ) || exit;
|
||||||
|
|
||||||
use Automattic\WooCommerce\Admin\Notes\Note;
|
use Automattic\WooCommerce\Admin\Notes\Note;
|
||||||
|
|
||||||
register_woocommerce_admin_test_helper_rest_route(
|
register_woocommerce_admin_test_helper_rest_route(
|
||||||
|
@ -6,7 +9,11 @@ register_woocommerce_admin_test_helper_rest_route(
|
||||||
'admin_notes_add_note'
|
'admin_notes_add_note'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds an admin note.
|
||||||
|
*
|
||||||
|
* @param WP_REST_Request $request Full data about the request.
|
||||||
|
*/
|
||||||
function admin_notes_add_note( $request ) {
|
function admin_notes_add_note( $request ) {
|
||||||
$note = new Note();
|
$note = new Note();
|
||||||
$mock_note_data = get_mock_note_data();
|
$mock_note_data = get_mock_note_data();
|
||||||
|
@ -15,7 +22,7 @@ function admin_notes_add_note( $request ) {
|
||||||
|
|
||||||
$note->set_name( $request->get_param( 'name' ) );
|
$note->set_name( $request->get_param( 'name' ) );
|
||||||
$note->set_title( $request->get_param( 'title' ) );
|
$note->set_title( $request->get_param( 'title' ) );
|
||||||
$note->set_content( $mock_note_data[ 'content' ] );
|
$note->set_content( $mock_note_data['content'] );
|
||||||
$note->set_image( $mock_note_data[ $type ][ $layout ] );
|
$note->set_image( $mock_note_data[ $type ][ $layout ] );
|
||||||
$note->set_layout( $layout );
|
$note->set_layout( $layout );
|
||||||
$note->set_type( $type );
|
$note->set_type( $type );
|
||||||
|
@ -30,6 +37,11 @@ function admin_notes_add_note( $request ) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds an email note parameter.
|
||||||
|
*
|
||||||
|
* @param Note $note The note to add parameters to.
|
||||||
|
*/
|
||||||
function add_email_note_params( $note ) {
|
function add_email_note_params( $note ) {
|
||||||
$additional_data = array(
|
$additional_data = array(
|
||||||
'role' => 'administrator',
|
'role' => 'administrator',
|
||||||
|
@ -37,6 +49,11 @@ function add_email_note_params( $note ) {
|
||||||
$note->set_content_data( (object) $additional_data );
|
$note->set_content_data( (object) $additional_data );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Possibly adds an action to a note.
|
||||||
|
*
|
||||||
|
* @param Note $note The note to check and add an action to.
|
||||||
|
*/
|
||||||
function possibly_add_action( $note ) {
|
function possibly_add_action( $note ) {
|
||||||
if ( $note->get_type() === 'info' ) {
|
if ( $note->get_type() === 'info' ) {
|
||||||
return;
|
return;
|
||||||
|
@ -48,6 +65,9 @@ function possibly_add_action( $note ) {
|
||||||
$note->add_action( $action_name, 'Test action', wc_admin_url() );
|
$note->add_action( $action_name, 'Test action', wc_admin_url() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets mock note data.
|
||||||
|
*/
|
||||||
function get_mock_note_data() {
|
function get_mock_note_data() {
|
||||||
$plugin_url = site_url() . '/wp-content/plugins/woocommerce-admin-test-helper/';
|
$plugin_url = site_url() . '/wp-content/plugins/woocommerce-admin-test-helper/';
|
||||||
return array(
|
return array(
|
||||||
|
@ -55,13 +75,13 @@ function get_mock_note_data() {
|
||||||
'info' => array(
|
'info' => array(
|
||||||
'banner' => $plugin_url . 'images/admin-notes/banner.jpg',
|
'banner' => $plugin_url . 'images/admin-notes/banner.jpg',
|
||||||
'thumbnail' => $plugin_url . 'images/admin-notes/thumbnail.jpg',
|
'thumbnail' => $plugin_url . 'images/admin-notes/thumbnail.jpg',
|
||||||
'plain' => ''
|
'plain' => '',
|
||||||
),
|
),
|
||||||
'email' => array(
|
'email' => array(
|
||||||
'plain' => $plugin_url . 'images/admin-notes/woocommerce-logo-vector.png'
|
'plain' => $plugin_url . 'images/admin-notes/woocommerce-logo-vector.png',
|
||||||
),
|
),
|
||||||
'update' => array(
|
'update' => array(
|
||||||
'plain' => ''
|
'plain' => '',
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,15 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
defined( 'ABSPATH' ) || exit;
|
||||||
|
|
||||||
register_woocommerce_admin_test_helper_rest_route(
|
register_woocommerce_admin_test_helper_rest_route(
|
||||||
'/admin-notes/delete-all-notes/v1',
|
'/admin-notes/delete-all-notes/v1',
|
||||||
'admin_notes_delete_all_notes'
|
'admin_notes_delete_all_notes'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes all admin notes.
|
||||||
|
*/
|
||||||
function admin_notes_delete_all_notes() {
|
function admin_notes_delete_all_notes() {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
* @package WC_Beta_Tester
|
* @package WC_Beta_Tester
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
defined( 'ABSPATH' ) || exit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register the test helper route.
|
* Register the test helper route.
|
||||||
*
|
*
|
||||||
|
@ -23,7 +25,7 @@ function register_woocommerce_admin_test_helper_rest_route( $route, $callback, $
|
||||||
if ( ! wc_rest_check_manager_permissions( 'settings', 'edit' ) ) {
|
if ( ! wc_rest_check_manager_permissions( 'settings', 'edit' ) ) {
|
||||||
return new \WP_Error(
|
return new \WP_Error(
|
||||||
'woocommerce_rest_cannot_edit',
|
'woocommerce_rest_cannot_edit',
|
||||||
__( 'Sorry, you cannot perform this action', 'woocommerce' )
|
__( 'Sorry, you cannot perform this action', 'woocommerce-beta-tester' )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -52,7 +54,7 @@ require 'tools/disable-wc-email.php';
|
||||||
require 'tools/trigger-update-callbacks.php';
|
require 'tools/trigger-update-callbacks.php';
|
||||||
require 'tracks/class-tracks-debug-log.php';
|
require 'tracks/class-tracks-debug-log.php';
|
||||||
require 'features/features.php';
|
require 'features/features.php';
|
||||||
require 'rest-api-filters/rest-api-filters.php';
|
require 'rest-api-filters/class-wca-test-helper-rest-api-filters.php';
|
||||||
require 'rest-api-filters/hook.php';
|
require 'rest-api-filters/hook.php';
|
||||||
require 'live-branches/manifest.php';
|
require 'live-branches/manifest.php';
|
||||||
require 'live-branches/install.php';
|
require 'live-branches/install.php';
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
use Automattic\WooCommerce\Admin\Features\Features;
|
|
||||||
|
defined( 'ABSPATH' ) || exit;
|
||||||
|
|
||||||
const OPTION_NAME_PREFIX = 'wc_admin_helper_feature_values';
|
const OPTION_NAME_PREFIX = 'wc_admin_helper_feature_values';
|
||||||
|
|
||||||
|
@ -27,30 +28,41 @@ register_woocommerce_admin_test_helper_rest_route(
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Toggles a feature.
|
||||||
|
*
|
||||||
|
* @param WP_REST_Request $request Full data about the request.
|
||||||
|
*/
|
||||||
function toggle_feature( $request ) {
|
function toggle_feature( $request ) {
|
||||||
$features = get_features();
|
$features = get_features();
|
||||||
$custom_feature_values = get_option( OPTION_NAME_PREFIX, array() );
|
$custom_feature_values = get_option( OPTION_NAME_PREFIX, array() );
|
||||||
$feature_name = $request->get_param( 'feature_name' );
|
$feature_name = $request->get_param( 'feature_name' );
|
||||||
|
|
||||||
if ( ! isset( $features[$feature_name ]) ) {
|
if ( ! isset( $features[ $feature_name ] ) ) {
|
||||||
return new WP_REST_Response( $features, 204 );
|
return new WP_REST_Response( $features, 204 );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( isset( $custom_feature_values[$feature_name] ) ) {
|
if ( isset( $custom_feature_values[ $feature_name ] ) ) {
|
||||||
unset( $custom_feature_values[$feature_name] );
|
unset( $custom_feature_values[ $feature_name ] );
|
||||||
} else {
|
} else {
|
||||||
$custom_feature_values[$feature_name] = ! $features[ $feature_name ];
|
$custom_feature_values[ $feature_name ] = ! $features[ $feature_name ];
|
||||||
}
|
}
|
||||||
|
|
||||||
update_option(OPTION_NAME_PREFIX, $custom_feature_values );
|
update_option( OPTION_NAME_PREFIX, $custom_feature_values );
|
||||||
return new WP_REST_Response( get_features(), 200 );
|
return new WP_REST_Response( get_features(), 200 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resets all features to their default values.
|
||||||
|
*/
|
||||||
function reset_features() {
|
function reset_features() {
|
||||||
delete_option( OPTION_NAME_PREFIX );
|
delete_option( OPTION_NAME_PREFIX );
|
||||||
return new WP_REST_Response( get_features(), 200 );
|
return new WP_REST_Response( get_features(), 200 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets all features.
|
||||||
|
*/
|
||||||
function get_features() {
|
function get_features() {
|
||||||
if ( function_exists( 'wc_admin_get_feature_config' ) ) {
|
if ( function_exists( 'wc_admin_get_feature_config' ) ) {
|
||||||
return apply_filters( 'woocommerce_admin_get_feature_config', wc_admin_get_feature_config() );
|
return apply_filters( 'woocommerce_admin_get_feature_config', wc_admin_get_feature_config() );
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
<?php // @codingStandardsIgnoreLine I don't know why it thinks the doc comment is missing.
|
<?php
|
||||||
/**
|
/**
|
||||||
* REST API endpoints for live branches installation.
|
* REST API endpoints for live branches installation.
|
||||||
*
|
*
|
||||||
* @package WC_Beta_Tester
|
* @package WC_Beta_Tester
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
defined( 'ABSPATH' ) || exit;
|
||||||
|
|
||||||
require_once __DIR__ . '/../../includes/class-wc-beta-tester-live-branches-installer.php';
|
require_once __DIR__ . '/../../includes/class-wc-beta-tester-live-branches-installer.php';
|
||||||
|
|
||||||
register_woocommerce_admin_test_helper_rest_route(
|
register_woocommerce_admin_test_helper_rest_route(
|
||||||
|
@ -37,7 +39,7 @@ register_woocommerce_admin_test_helper_rest_route(
|
||||||
} else {
|
} else {
|
||||||
return new \WP_Error(
|
return new \WP_Error(
|
||||||
'woocommerce_rest_cannot_edit',
|
'woocommerce_rest_cannot_edit',
|
||||||
__( 'Sorry, you cannot perform this action', 'woocommerce' )
|
__( 'Sorry, you cannot perform this action', 'woocommerce-beta-tester' )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
<?php // @codingStandardsIgnoreLine
|
<?php
|
||||||
/**
|
/**
|
||||||
* Register REST endpoint for fetching live branches manifest.
|
* Register REST endpoint for fetching live branches manifest.
|
||||||
*
|
*
|
||||||
* @package WC_Beta_Tester
|
* @package WC_Beta_Tester
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
defined( 'ABSPATH' ) || exit;
|
||||||
|
|
||||||
require_once __DIR__ . '/../../includes/class-wc-beta-tester-live-branches-installer.php';
|
require_once __DIR__ . '/../../includes/class-wc-beta-tester-live-branches-installer.php';
|
||||||
|
|
||||||
register_woocommerce_admin_test_helper_rest_route(
|
register_woocommerce_admin_test_helper_rest_route(
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue