2018-12-14 19:45:19 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
2019-05-28 12:06:12 +00:00
|
|
|
import { Disabled, PanelBody } from '@wordpress/components';
|
2020-05-12 20:31:49 +00:00
|
|
|
import { InspectorControls } from '@wordpress/block-editor';
|
2020-12-14 11:55:05 +00:00
|
|
|
import ServerSideRender from '@wordpress/server-side-render';
|
2020-09-02 08:21:46 +00:00
|
|
|
import GridContentControl from '@woocommerce/editor-components/grid-content-control';
|
|
|
|
import GridLayoutControl from '@woocommerce/editor-components/grid-layout-control';
|
|
|
|
import ProductCategoryControl from '@woocommerce/editor-components/product-category-control';
|
2022-01-10 13:39:24 +00:00
|
|
|
import ProductStockControl from '@woocommerce/editor-components/product-stock-control';
|
2019-11-15 15:16:18 +00:00
|
|
|
import { gridBlockPreview } from '@woocommerce/resource-previews';
|
2021-04-22 11:37:27 +00:00
|
|
|
import { getSetting } from '@woocommerce/settings';
|
2018-12-14 19:45:19 +00:00
|
|
|
|
2023-05-26 06:46:13 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { Props } from './types';
|
2018-12-14 19:45:19 +00:00
|
|
|
/**
|
|
|
|
* Component to handle edit mode of "Top Rated Products".
|
|
|
|
*/
|
2023-05-26 06:46:13 +00:00
|
|
|
export const ProductTopRatedBlock = ( {
|
|
|
|
attributes,
|
|
|
|
name,
|
|
|
|
setAttributes,
|
|
|
|
}: Props ): JSX.Element => {
|
|
|
|
const {
|
|
|
|
categories,
|
|
|
|
catOperator,
|
|
|
|
columns,
|
|
|
|
contentVisibility,
|
|
|
|
rows,
|
|
|
|
alignButtons,
|
|
|
|
stockStatus,
|
|
|
|
isPreview,
|
|
|
|
} = attributes;
|
2018-12-14 19:45:19 +00:00
|
|
|
|
2023-05-26 06:46:13 +00:00
|
|
|
const getInspectorControls = () => {
|
2018-12-14 19:45:19 +00:00
|
|
|
return (
|
|
|
|
<InspectorControls key="inspector">
|
2023-12-12 23:05:20 +00:00
|
|
|
<PanelBody title={ __( 'Layout', 'woocommerce' ) } initialOpen>
|
2019-01-31 22:55:54 +00:00
|
|
|
<GridLayoutControl
|
|
|
|
columns={ columns }
|
|
|
|
rows={ rows }
|
2019-06-27 11:13:02 +00:00
|
|
|
alignButtons={ alignButtons }
|
2019-01-31 22:55:54 +00:00
|
|
|
setAttributes={ setAttributes }
|
2023-08-07 10:30:53 +00:00
|
|
|
minColumns={ getSetting( 'minColumns', 1 ) }
|
|
|
|
maxColumns={ getSetting( 'maxColumns', 6 ) }
|
|
|
|
minRows={ getSetting( 'minRows', 1 ) }
|
|
|
|
maxRows={ getSetting( 'maxRows', 6 ) }
|
2018-12-14 19:45:19 +00:00
|
|
|
/>
|
|
|
|
</PanelBody>
|
2023-12-12 23:05:20 +00:00
|
|
|
<PanelBody title={ __( 'Content', 'woocommerce' ) } initialOpen>
|
2019-02-21 19:00:47 +00:00
|
|
|
<GridContentControl
|
|
|
|
settings={ contentVisibility }
|
2019-09-05 15:09:31 +00:00
|
|
|
onChange={ ( value ) =>
|
|
|
|
setAttributes( { contentVisibility: value } )
|
|
|
|
}
|
2019-02-21 19:00:47 +00:00
|
|
|
/>
|
|
|
|
</PanelBody>
|
2018-12-14 19:45:19 +00:00
|
|
|
<PanelBody
|
2023-12-12 23:05:20 +00:00
|
|
|
title={ __( 'Filter by Product Category', 'woocommerce' ) }
|
2018-12-14 19:45:19 +00:00
|
|
|
initialOpen={ false }
|
|
|
|
>
|
|
|
|
<ProductCategoryControl
|
2019-01-15 18:52:34 +00:00
|
|
|
selected={ categories }
|
2018-12-14 19:45:19 +00:00
|
|
|
onChange={ ( value = [] ) => {
|
|
|
|
const ids = value.map( ( { id } ) => id );
|
|
|
|
setAttributes( { categories: ids } );
|
|
|
|
} }
|
2019-01-15 18:52:34 +00:00
|
|
|
operator={ catOperator }
|
|
|
|
onOperatorChange={ ( value = 'any' ) =>
|
|
|
|
setAttributes( { catOperator: value } )
|
|
|
|
}
|
2018-12-14 19:45:19 +00:00
|
|
|
/>
|
|
|
|
</PanelBody>
|
2022-01-10 13:39:24 +00:00
|
|
|
<PanelBody
|
2023-12-12 23:05:20 +00:00
|
|
|
title={ __( 'Filter by stock status', 'woocommerce' ) }
|
2022-01-10 13:39:24 +00:00
|
|
|
initialOpen={ false }
|
|
|
|
>
|
|
|
|
<ProductStockControl
|
|
|
|
setAttributes={ setAttributes }
|
|
|
|
value={ stockStatus }
|
|
|
|
/>
|
|
|
|
</PanelBody>
|
2018-12-14 19:45:19 +00:00
|
|
|
</InspectorControls>
|
|
|
|
);
|
2023-05-26 06:46:13 +00:00
|
|
|
};
|
2018-12-14 19:45:19 +00:00
|
|
|
|
2023-05-26 06:46:13 +00:00
|
|
|
if ( isPreview ) {
|
|
|
|
return gridBlockPreview;
|
2018-12-14 19:45:19 +00:00
|
|
|
}
|
|
|
|
|
2023-05-26 06:46:13 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{ getInspectorControls() }
|
|
|
|
<Disabled>
|
|
|
|
<ServerSideRender block={ name } attributes={ attributes } />
|
|
|
|
</Disabled>
|
|
|
|
</>
|
|
|
|
);
|
2018-12-14 19:45:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default ProductTopRatedBlock;
|