Add a visibility toggle to the Quick actions list (#40464)
* Create toggle-visibility-menu-item component * Add toggle-visibility-menu-item to variation-actions-menu * Add toggle-visibility-menu-item to variations-actions-menu * Add changelog file
This commit is contained in:
parent
5b06aace54
commit
e6df583c65
|
@ -0,0 +1,4 @@
|
|||
Significance: minor
|
||||
Type: add
|
||||
|
||||
Add a visibility toggle to the Quick actions list
|
|
@ -0,0 +1 @@
|
|||
export * from './toggle-visibility-menu-item';
|
|
@ -0,0 +1,62 @@
|
|||
/**
|
||||
* External dependencies
|
||||
*/
|
||||
import { MenuItem } from '@wordpress/components';
|
||||
import { createElement } from '@wordpress/element';
|
||||
import { __ } from '@wordpress/i18n';
|
||||
import { recordEvent } from '@woocommerce/tracks';
|
||||
|
||||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
import { TRACKS_SOURCE } from '../../../constants';
|
||||
import { VariationActionsMenuItemProps } from '../types';
|
||||
|
||||
export function ToggleVisibilityMenuItem( {
|
||||
selection,
|
||||
onChange,
|
||||
onClose,
|
||||
}: VariationActionsMenuItemProps ) {
|
||||
function toggleStatus( currentStatus: string ) {
|
||||
return currentStatus === 'private' ? 'publish' : 'private';
|
||||
}
|
||||
|
||||
function handleMenuItemClick() {
|
||||
const ids = Array.isArray( selection )
|
||||
? selection.map( ( { id } ) => id )
|
||||
: selection.id;
|
||||
|
||||
recordEvent( 'product_variations_menu_toggle_visibility_select', {
|
||||
source: TRACKS_SOURCE,
|
||||
action: 'status_set',
|
||||
variation_id: ids,
|
||||
} );
|
||||
|
||||
if ( Array.isArray( selection ) ) {
|
||||
onChange(
|
||||
selection.map( ( { id, status } ) => ( {
|
||||
id,
|
||||
status: toggleStatus( status ),
|
||||
} ) )
|
||||
);
|
||||
} else {
|
||||
onChange( {
|
||||
status: toggleStatus( selection.status ),
|
||||
} );
|
||||
}
|
||||
|
||||
recordEvent( 'product_variations_toggle_visibility_update', {
|
||||
source: TRACKS_SOURCE,
|
||||
action: 'status_set',
|
||||
variation_id: ids,
|
||||
} );
|
||||
|
||||
onClose();
|
||||
}
|
||||
|
||||
return (
|
||||
<MenuItem onClick={ handleMenuItemClick }>
|
||||
{ __( 'Toggle visibility', 'woocommerce' ) }
|
||||
</MenuItem>
|
||||
);
|
||||
}
|
|
@ -15,6 +15,7 @@ import { TRACKS_SOURCE } from '../../../constants';
|
|||
import { ShippingMenuItem } from '../shipping-menu-item';
|
||||
import { InventoryMenuItem } from '../inventory-menu-item';
|
||||
import { PricingMenuItem } from '../pricing-menu-item';
|
||||
import { ToggleVisibilityMenuItem } from '../toggle-visibility-menu-item';
|
||||
|
||||
export function VariationActionsMenu( {
|
||||
selection,
|
||||
|
@ -56,6 +57,11 @@ export function VariationActionsMenu( {
|
|||
>
|
||||
{ __( 'Preview', 'woocommerce' ) }
|
||||
</MenuItem>
|
||||
<ToggleVisibilityMenuItem
|
||||
selection={ selection }
|
||||
onChange={ onChange }
|
||||
onClose={ onClose }
|
||||
/>
|
||||
</MenuGroup>
|
||||
<MenuGroup>
|
||||
<PricingMenuItem
|
||||
|
|
|
@ -15,6 +15,7 @@ import { PricingMenuItem } from '../pricing-menu-item';
|
|||
import { SetListPriceMenuItem } from '../set-list-price-menu-item';
|
||||
import { InventoryMenuItem } from '../inventory-menu-item';
|
||||
import { ShippingMenuItem } from '../shipping-menu-item';
|
||||
import { ToggleVisibilityMenuItem } from '../toggle-visibility-menu-item';
|
||||
|
||||
export function VariationsActionsMenu( {
|
||||
selection,
|
||||
|
@ -50,6 +51,11 @@ export function VariationsActionsMenu( {
|
|||
onChange={ onChange }
|
||||
onClose={ onClose }
|
||||
/>
|
||||
<ToggleVisibilityMenuItem
|
||||
selection={ selection }
|
||||
onChange={ onChange }
|
||||
onClose={ onClose }
|
||||
/>
|
||||
</MenuGroup>
|
||||
<MenuGroup>
|
||||
<PricingMenuItem
|
||||
|
|
Loading…
Reference in New Issue