Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Move the usage of Notices from @wordpress/components from frontend to editor (Filter by Rating) #8444

Merged
merged 4 commits into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 5 additions & 16 deletions assets/js/blocks/rating-filter/block.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* External dependencies
*/
import { type ReactElement } from 'react';
import { __, sprintf } from '@wordpress/i18n';
import { speak } from '@wordpress/a11y';
import { Icon, chevronDown } from '@wordpress/icons';
Expand All @@ -12,7 +13,6 @@ import {
useShallowEqual,
useBorderProps,
} from '@woocommerce/base-hooks';
import { Notice } from 'wordpress-components';
import {
useQueryStateByKey,
useQueryStateByContext,
Expand Down Expand Up @@ -65,17 +65,15 @@ const translations = {

/**
* Component displaying a rating filter.
*
* @param {Object} props Incoming props for the component.
* @param {Object} props.attributes Incoming block attributes.
* @param {boolean} props.isEditor Whether the component is being rendered in the editor.
*/
const RatingFilterBlock = ( {
attributes: blockAttributes,
isEditor,
noRatingsNotice = null,
}: {
isEditor: boolean;
attributes: Attributes;
isEditor: boolean;
noRatingsNotice?: ReactElement | null;
} ) => {
const setWrapperVisibility = useSetWraperVisibility();

Expand Down Expand Up @@ -335,16 +333,7 @@ const RatingFilterBlock = ( {

return (
<>
{ displayNoProductRatingsNotice && (
<Notice status="warning" isDismissible={ false }>
<p>
{ __(
"Your store doesn't have any products with ratings yet. This filter option will display when a product receives a review.",
'woo-gutenberg-products-block'
) }
</p>
</Notice>
) }
{ displayNoProductRatingsNotice && noRatingsNotice }
<div
className={ classnames(
'wc-block-rating-filter',
Expand Down
18 changes: 17 additions & 1 deletion assets/js/blocks/rating-filter/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useBlockProps, InspectorControls } from '@wordpress/block-editor';
import type { BlockEditProps } from '@wordpress/blocks';
import {
Disabled,
Notice,
PanelBody,
ToggleControl,
withSpokenMessages,
Expand All @@ -23,6 +24,17 @@ import Block from './block';
import { Attributes } from './types';
import './editor.scss';

const noRatingsNotice = (
<Notice status="warning" isDismissible={ false }>
<p>
{ __(
"Your store doesn't have any products with ratings yet. This filter option will display when a product receives a review.",
'woo-gutenberg-products-block'
) }
</p>
</Notice>
);

const Edit = ( {
attributes,
setAttributes,
Expand Down Expand Up @@ -143,7 +155,11 @@ const Edit = ( {
{
<div { ...blockProps }>
<Disabled>
<Block attributes={ attributes } isEditor={ true } />
<Block
attributes={ attributes }
isEditor={ true }
noRatingsNotice={ noRatingsNotice }
/>
</Disabled>
</div>
}
Expand Down