This repository was archived by the owner on Feb 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 221
/
Copy pathpopular-presets.tsx
66 lines (60 loc) · 1.56 KB
/
popular-presets.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* External dependencies
*/
import { CustomSelectControl, PanelBody } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import { ProductQueryBlock, ProductQueryBlockQuery } from '../types';
import { setQueryAttribute } from '../utils';
const PRESETS = [
{ key: 'date/desc', name: __( 'Newest', 'woo-gutenberg-products-block' ) },
{
key: 'popularity/desc',
name: __( 'Best Selling', 'woo-gutenberg-products-block' ),
},
{
key: 'rating/desc',
name: __( 'Top Rated', 'woo-gutenberg-products-block' ),
},
];
export function PopularPresets( props: ProductQueryBlock ) {
const { query } = props.attributes;
return (
<PanelBody
className="woocommerce-product-query-panel__sort"
title={ __( 'Popular Filters', 'woo-gutenberg-products-block' ) }
initialOpen={ true }
>
<p>
{ __(
'Arrange products by popular pre-sets.',
'woo-gutenberg-products-block'
) }
</p>
<CustomSelectControl
hideLabelFromVision={ true }
label={ __(
'Choose among these pre-sets',
'woo-gutenberg-products-block'
) }
onChange={ ( option ) => {
if ( ! option.selectedItem?.key ) return;
const [ orderBy, order ] = option.selectedItem?.key?.split(
'/'
) as [
ProductQueryBlockQuery[ 'orderBy' ],
ProductQueryBlockQuery[ 'order' ]
];
setQueryAttribute( props, { order, orderBy } );
} }
options={ PRESETS }
value={ PRESETS.find(
( option ) =>
option.key === `${ query.orderBy }/${ query.order }`
) }
/>
</PanelBody>
);
}