[Single Variation] Add missing tracks events (#40996)
* Add note prop * Add note for single variation * Add event recording for generic toggle * Add changelog * Add parent_id to toggle event * move logic inside recordProductEvent * Modify postType
This commit is contained in:
parent
2639aba8a9
commit
898eb30f7e
|
@ -0,0 +1,4 @@
|
||||||
|
Significance: minor
|
||||||
|
Type: add
|
||||||
|
|
||||||
|
[Single Variation] Add missing tracks events #40996
|
|
@ -4,6 +4,11 @@
|
||||||
import { createElement } from '@wordpress/element';
|
import { createElement } from '@wordpress/element';
|
||||||
import { ToggleControl } from '@wordpress/components';
|
import { ToggleControl } from '@wordpress/components';
|
||||||
import { useWooBlockProps } from '@woocommerce/block-templates';
|
import { useWooBlockProps } from '@woocommerce/block-templates';
|
||||||
|
import { recordEvent } from '@woocommerce/tracks';
|
||||||
|
// 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 { useEntityProp, useEntityId } from '@wordpress/core-data';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
|
@ -12,6 +17,7 @@ import { ToggleBlockAttributes } from './types';
|
||||||
import { sanitizeHTML } from '../../../utils/sanitize-html';
|
import { sanitizeHTML } from '../../../utils/sanitize-html';
|
||||||
import { ProductEditorBlockEditProps } from '../../../types';
|
import { ProductEditorBlockEditProps } from '../../../types';
|
||||||
import useProductEntityProp from '../../../hooks/use-product-entity-prop';
|
import useProductEntityProp from '../../../hooks/use-product-entity-prop';
|
||||||
|
import { TRACKS_SOURCE } from '../../../constants';
|
||||||
|
|
||||||
export function Edit( {
|
export function Edit( {
|
||||||
attributes,
|
attributes,
|
||||||
|
@ -19,6 +25,7 @@ export function Edit( {
|
||||||
}: ProductEditorBlockEditProps< ToggleBlockAttributes > ) {
|
}: ProductEditorBlockEditProps< ToggleBlockAttributes > ) {
|
||||||
const blockProps = useWooBlockProps( attributes );
|
const blockProps = useWooBlockProps( attributes );
|
||||||
const {
|
const {
|
||||||
|
_templateBlockId,
|
||||||
label,
|
label,
|
||||||
property,
|
property,
|
||||||
disabled,
|
disabled,
|
||||||
|
@ -30,6 +37,12 @@ export function Edit( {
|
||||||
postType,
|
postType,
|
||||||
fallbackValue: false,
|
fallbackValue: false,
|
||||||
} );
|
} );
|
||||||
|
const productId = useEntityId( 'postType', postType );
|
||||||
|
const [ parentId ] = useEntityProp< number >(
|
||||||
|
'postType',
|
||||||
|
postType,
|
||||||
|
'parent_id'
|
||||||
|
);
|
||||||
|
|
||||||
function isChecked() {
|
function isChecked() {
|
||||||
if ( checkedValue !== undefined ) {
|
if ( checkedValue !== undefined ) {
|
||||||
|
@ -39,6 +52,11 @@ export function Edit( {
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleChange( checked: boolean ) {
|
function handleChange( checked: boolean ) {
|
||||||
|
recordEvent( 'product_toggle_click', {
|
||||||
|
block_id: _templateBlockId,
|
||||||
|
source: TRACKS_SOURCE,
|
||||||
|
product_id: parentId > 0 ? parentId : productId,
|
||||||
|
} );
|
||||||
if ( checked ) {
|
if ( checked ) {
|
||||||
setValue( checkedValue !== undefined ? checkedValue : checked );
|
setValue( checkedValue !== undefined ? checkedValue : checked );
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -18,6 +18,7 @@ const potentialTrackableProductValueKeys = [
|
||||||
'description',
|
'description',
|
||||||
'manage_stock',
|
'manage_stock',
|
||||||
'menu_order',
|
'menu_order',
|
||||||
|
'note',
|
||||||
'purchase_note',
|
'purchase_note',
|
||||||
'sale_price',
|
'sale_price',
|
||||||
'short_description',
|
'short_description',
|
||||||
|
@ -43,6 +44,11 @@ export function recordProductEvent(
|
||||||
product_type: type,
|
product_type: type,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if ( product.parent_id > 0 ) {
|
||||||
|
product.note = product.description;
|
||||||
|
delete product.description;
|
||||||
|
}
|
||||||
|
|
||||||
for ( const productValueKey of Object.keys( product ) ) {
|
for ( const productValueKey of Object.keys( product ) ) {
|
||||||
if ( potentialTrackableProductValueKeys.includes( productValueKey ) ) {
|
if ( potentialTrackableProductValueKeys.includes( productValueKey ) ) {
|
||||||
const eventPropKey =
|
const eventPropKey =
|
||||||
|
|
Loading…
Reference in New Issue