Filter by Attribute: Allow reselecting unselected attribute (https://github.com/woocommerce/woocommerce-blocks/pull/1264)
* Filter by Attribute: Allow reselecting unselected attribute * Run prettier
This commit is contained in:
parent
e8f0a071ba
commit
ec4ae1269d
|
@ -216,28 +216,31 @@ const Edit = ( { attributes, setAttributes, debouncedSpeak } ) => {
|
||||||
);
|
);
|
||||||
}, [] );
|
}, [] );
|
||||||
|
|
||||||
const onChange = useCallback( ( selected ) => {
|
const onChange = useCallback(
|
||||||
const selectedId = selected[ 0 ].id;
|
( selected ) => {
|
||||||
const productAttribute = find( ATTRIBUTES, [
|
const selectedId = selected[ 0 ].id;
|
||||||
'attribute_id',
|
const productAttribute = find( ATTRIBUTES, [
|
||||||
selectedId.toString(),
|
'attribute_id',
|
||||||
] );
|
selectedId.toString(),
|
||||||
|
] );
|
||||||
|
|
||||||
if ( ! productAttribute || attributeId === selectedId ) {
|
if ( ! productAttribute || attributeId === selectedId ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const attributeName = productAttribute.attribute_name;
|
const attributeName = productAttribute.attribute_name;
|
||||||
|
|
||||||
setAttributes( {
|
setAttributes( {
|
||||||
attributeId: selectedId,
|
attributeId: selectedId,
|
||||||
heading: sprintf(
|
heading: sprintf(
|
||||||
// Translators: %s attribute name.
|
// Translators: %s attribute name.
|
||||||
__( 'Filter by %s', 'woo-gutenberg-products-block' ),
|
__( 'Filter by %s', 'woo-gutenberg-products-block' ),
|
||||||
attributeName
|
attributeName
|
||||||
),
|
),
|
||||||
} );
|
} );
|
||||||
}, [] );
|
},
|
||||||
|
[ attributeId ]
|
||||||
|
);
|
||||||
|
|
||||||
const renderAttributeControl = () => {
|
const renderAttributeControl = () => {
|
||||||
const messages = {
|
const messages = {
|
||||||
|
|
Loading…
Reference in New Issue