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:
Albert Juhé Lluveras 2019-11-26 17:43:27 +01:00 committed by GitHub
parent e8f0a071ba
commit ec4ae1269d
1 changed files with 22 additions and 19 deletions

View File

@ -216,28 +216,31 @@ const Edit = ( { attributes, setAttributes, debouncedSpeak } ) => {
);
}, [] );
const onChange = useCallback( ( selected ) => {
const selectedId = selected[ 0 ].id;
const productAttribute = find( ATTRIBUTES, [
'attribute_id',
selectedId.toString(),
] );
const onChange = useCallback(
( selected ) => {
const selectedId = selected[ 0 ].id;
const productAttribute = find( ATTRIBUTES, [
'attribute_id',
selectedId.toString(),
] );
if ( ! productAttribute || attributeId === selectedId ) {
return;
}
if ( ! productAttribute || attributeId === selectedId ) {
return;
}
const attributeName = productAttribute.attribute_name;
const attributeName = productAttribute.attribute_name;
setAttributes( {
attributeId: selectedId,
heading: sprintf(
// Translators: %s attribute name.
__( 'Filter by %s', 'woo-gutenberg-products-block' ),
attributeName
),
} );
}, [] );
setAttributes( {
attributeId: selectedId,
heading: sprintf(
// Translators: %s attribute name.
__( 'Filter by %s', 'woo-gutenberg-products-block' ),
attributeName
),
} );
},
[ attributeId ]
);
const renderAttributeControl = () => {
const messages = {