Update List price Pricing link on the general tab to navigate to the Pricing tab (#37961)

* Update List price Pricing link on the general tab to navigate to the Pricing tab

* Add changelog files

* Simplify the event name to product_pricing_help_click
This commit is contained in:
Maikel David Pérez Gómez 2023-04-28 11:33:56 -04:00 committed by GitHub
parent 1514333162
commit a35f2c3d5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 81 additions and 64 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: add
Update List price Pricing link on the general tab to navigate to the Pricing tab

View File

@ -15,8 +15,8 @@
"label": {
"type": "string"
},
"showPricingSection": {
"type": "boolean"
"help": {
"type": "string"
}
},
"supports": {

View File

@ -1,19 +1,20 @@
/**
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import { Link } from '@woocommerce/components';
import { CurrencyContext } from '@woocommerce/currency';
import { getNewPath } from '@woocommerce/navigation';
import { recordEvent } from '@woocommerce/tracks';
import { useBlockProps } from '@wordpress/block-editor';
import { BlockEditProps } from '@wordpress/blocks';
import { useInstanceId } from '@wordpress/compose';
import { useEntityProp } from '@wordpress/core-data';
import {
createElement,
useContext,
createInterpolateElement,
} from '@wordpress/element';
import { Link } from '@woocommerce/components';
import { useBlockProps } from '@wordpress/block-editor';
import { useEntityProp } from '@wordpress/core-data';
import { BlockAttributes } from '@wordpress/blocks';
import { CurrencyContext } from '@woocommerce/currency';
import { getSetting } from '@woocommerce/settings';
import { recordEvent } from '@woocommerce/tracks';
import { __ } from '@wordpress/i18n';
import {
BaseControl,
// @ts-expect-error `__experimentalInputControl` does exist.
@ -23,13 +24,16 @@ import {
/**
* Internal dependencies
*/
import { formatCurrencyDisplayValue } from '../../utils';
import { useCurrencyInputProps } from '../../hooks/use-currency-input-props';
import { formatCurrencyDisplayValue } from '../../utils';
import { PricingBlockAttributes } from './types';
export function Edit( { attributes }: { attributes: BlockAttributes } ) {
export function Edit( {
attributes,
}: BlockEditProps< PricingBlockAttributes > ) {
const blockProps = useBlockProps();
const { name, label, showPricingSection = false } = attributes;
const [ regularPrice, setRegularPrice ] = useEntityProp< string >(
const { name, label, help } = attributes;
const [ price, setPrice ] = useEntityProp< string >(
'postType',
'product',
name
@ -38,51 +42,42 @@ export function Edit( { attributes }: { attributes: BlockAttributes } ) {
const { getCurrencyConfig, formatAmount } = context;
const currencyConfig = getCurrencyConfig();
const inputProps = useCurrencyInputProps( {
value: regularPrice,
setValue: setRegularPrice,
value: price,
setValue: setPrice,
} );
const taxSettingsElement = showPricingSection
? createInterpolateElement(
__(
'Manage more settings in <link>Pricing.</link>',
'woocommerce'
const interpolatedHelp = help
? createInterpolateElement( help, {
PricingTab: (
<Link
href={ getNewPath( { tab: 'pricing' } ) }
onClick={ () => {
recordEvent( 'product_pricing_help_click' );
} }
/>
),
{
link: (
<Link
href={ `${ getSetting(
'adminUrl'
) }admin.php?page=wc-settings&tab=tax` }
target="_blank"
type="external"
onClick={ () => {
recordEvent(
'product_pricing_list_price_help_tax_settings_click'
);
} }
></Link>
),
}
)
} )
: null;
const priceId = useInstanceId(
BaseControl,
'wp-block-woocommerce-product-pricing-field'
) as string;
return (
<div { ...blockProps }>
<BaseControl
id={ 'product_pricing_' + name }
help={ taxSettingsElement ? taxSettingsElement : '' }
>
<BaseControl id={ priceId } help={ interpolatedHelp }>
<InputControl
{ ...inputProps }
id={ priceId }
name={ name }
onChange={ setRegularPrice }
onChange={ setPrice }
label={ label || __( 'Price', 'woocommerce' ) }
value={ formatCurrencyDisplayValue(
String( regularPrice ),
String( price ),
currencyConfig,
formatAmount
) }
{ ...inputProps }
/>
</BaseControl>
</div>

View File

@ -1,22 +1,27 @@
/**
* External dependencies
*/
import { BlockConfiguration } from '@wordpress/blocks';
/**
* Internal dependencies
*/
import { initBlock } from '../../utils';
import metadata from './block.json';
import { initBlock } from '../../utils/init-blocks';
import blockConfiguration from './block.json';
import { Edit } from './edit';
import { PricingBlockAttributes } from './types';
const { name } = metadata;
const { name, ...metadata } =
blockConfiguration as BlockConfiguration< PricingBlockAttributes >;
export { metadata, name };
export const settings = {
example: {},
edit: Edit,
};
export const settings: Partial< BlockConfiguration< PricingBlockAttributes > > =
{
example: {},
edit: Edit,
};
export const init = () =>
initBlock( {
name,
metadata: metadata as never,
settings,
} );
export function init() {
return initBlock( { name, metadata, settings } );
}

View File

@ -0,0 +1,10 @@
/**
* External dependencies
*/
import { BlockAttributes } from '@wordpress/blocks';
export interface PricingBlockAttributes extends BlockAttributes {
name: string;
label: string;
help?: string;
}

View File

@ -0,0 +1,4 @@
Significance: minor
Type: add
Update List price Pricing link on the general tab to navigate to the Pricing tab

View File

@ -405,9 +405,9 @@ class WC_Post_Types {
array(
'woocommerce/product-pricing-field',
array(
'name' => 'regular_price',
'name' => 'regular_price',
'label' => __( 'List price', 'woocommerce' ),
'showPricingSection' => true,
'help' => __( 'Manage more settings in <PricingTab>Pricing.</PricingTab>', 'woocommerce' ),
),
),
),
@ -421,7 +421,7 @@ class WC_Post_Types {
array(
'woocommerce/product-pricing-field',
array(
'name' => 'sale_price',
'name' => 'sale_price',
'label' => __( 'Sale price', 'woocommerce' ),
),
),
@ -521,9 +521,8 @@ class WC_Post_Types {
array(
'woocommerce/product-pricing-field',
array(
'name' => 'regular_price',
'name' => 'regular_price',
'label' => __( 'List price', 'woocommerce' ),
'showPricingSection' => true,
),
),
),
@ -537,7 +536,7 @@ class WC_Post_Types {
array(
'woocommerce/product-pricing-field',
array(
'name' => 'sale_price',
'name' => 'sale_price',
'label' => __( 'Sale price', 'woocommerce' ),
),
),