From 245f6013ac1b1c7002ca83a4421983c5e34816e8 Mon Sep 17 00:00:00 2001
From: Hritik Chaudhary <33057454+hritikchaudhary@users.noreply.github.com>
Date: Tue, 18 Jul 2023 12:49:15 +0530
Subject: [PATCH 1/5] renamed edit.tsx to block.tsx
---
.../js/blocks/reviews/reviews-by-product/{edit.tsx => block.tsx} | 0
1 file changed, 0 insertions(+), 0 deletions(-)
rename assets/js/blocks/reviews/reviews-by-product/{edit.tsx => block.tsx} (100%)
diff --git a/assets/js/blocks/reviews/reviews-by-product/edit.tsx b/assets/js/blocks/reviews/reviews-by-product/block.tsx
similarity index 100%
rename from assets/js/blocks/reviews/reviews-by-product/edit.tsx
rename to assets/js/blocks/reviews/reviews-by-product/block.tsx
From 8a5dce080641243f5e25419e6cd6429b2276d5a3 Mon Sep 17 00:00:00 2001
From: Hritik Chaudhary <33057454+hritikchaudhary@users.noreply.github.com>
Date: Tue, 18 Jul 2023 12:49:49 +0530
Subject: [PATCH 2/5] renamed index.js to index.tsx
---
.../js/blocks/reviews/reviews-by-product/{index.js => index.tsx} | 0
1 file changed, 0 insertions(+), 0 deletions(-)
rename assets/js/blocks/reviews/reviews-by-product/{index.js => index.tsx} (100%)
diff --git a/assets/js/blocks/reviews/reviews-by-product/index.js b/assets/js/blocks/reviews/reviews-by-product/index.tsx
similarity index 100%
rename from assets/js/blocks/reviews/reviews-by-product/index.js
rename to assets/js/blocks/reviews/reviews-by-product/index.tsx
From 82df858969c04e864146c3daf8b2fe3329164ee6 Mon Sep 17 00:00:00 2001
From: Hritik Chaudhary <33057454+hritikchaudhary@users.noreply.github.com>
Date: Tue, 18 Jul 2023 12:50:28 +0530
Subject: [PATCH 3/5] renamed no-reviews-placeholder.js to
no-reviews-placeholder.tsx
---
.../{no-reviews-placeholder.js => no-reviews-placeholder.tsx} | 0
1 file changed, 0 insertions(+), 0 deletions(-)
rename assets/js/blocks/reviews/reviews-by-product/{no-reviews-placeholder.js => no-reviews-placeholder.tsx} (100%)
diff --git a/assets/js/blocks/reviews/reviews-by-product/no-reviews-placeholder.js b/assets/js/blocks/reviews/reviews-by-product/no-reviews-placeholder.tsx
similarity index 100%
rename from assets/js/blocks/reviews/reviews-by-product/no-reviews-placeholder.js
rename to assets/js/blocks/reviews/reviews-by-product/no-reviews-placeholder.tsx
From 51b76a917c2fed243a31c4b3a290350447628293 Mon Sep 17 00:00:00 2001
From: Hritik Chaudhary <33057454+hritikchaudhary@users.noreply.github.com>
Date: Tue, 18 Jul 2023 12:54:56 +0530
Subject: [PATCH 4/5] TS error fixes
---
.../reviews/reviews-by-product/block.tsx | 16 ++++++--------
.../reviews/reviews-by-product/edit.tsx | 22 +++++++++++++++++++
.../reviews/reviews-by-product/index.tsx | 6 ++---
.../no-reviews-placeholder.tsx | 22 +++++++++----------
.../reviews/reviews-by-product/types.ts | 16 ++++++++++++++
5 files changed, 57 insertions(+), 25 deletions(-)
create mode 100644 assets/js/blocks/reviews/reviews-by-product/edit.tsx
diff --git a/assets/js/blocks/reviews/reviews-by-product/block.tsx b/assets/js/blocks/reviews/reviews-by-product/block.tsx
index 3c9155a69a3..b7c0392f333 100644
--- a/assets/js/blocks/reviews/reviews-by-product/block.tsx
+++ b/assets/js/blocks/reviews/reviews-by-product/block.tsx
@@ -23,7 +23,7 @@ import {
getSharedReviewContentControls,
getSharedReviewListControls,
} from '../edit-utils.js';
-import { ReviewsByProductEditorProps } from './types';
+import type { ReviewsByProductEditorProps, SearchListItemProps } from './types';
const ReviewsByProductEditor = ( {
attributes,
@@ -32,9 +32,7 @@ const ReviewsByProductEditor = ( {
}: ReviewsByProductEditorProps ) => {
const { editMode, productId } = attributes;
- const renderProductControlItem = ( args ) => {
- const { item = 0 } = args;
-
+ const renderProductControlItem = ( args: SearchListItemProps ) => {
return (
);
diff --git a/assets/js/blocks/reviews/reviews-by-product/edit.tsx b/assets/js/blocks/reviews/reviews-by-product/edit.tsx
new file mode 100644
index 00000000000..e241189c5f7
--- /dev/null
+++ b/assets/js/blocks/reviews/reviews-by-product/edit.tsx
@@ -0,0 +1,22 @@
+/**
+ * External dependencies
+ */
+import { useBlockProps } from '@wordpress/block-editor';
+
+/**
+ * Internal dependencies
+ */
+import Block from './block';
+import type { ReviewsByProductEditorProps } from './types';
+
+export const Edit = (
+ props: unknown & ReviewsByProductEditorProps
+): JSX.Element => {
+ const blockProps = useBlockProps();
+
+ return (
+
+
+
+ );
+};
diff --git a/assets/js/blocks/reviews/reviews-by-product/index.tsx b/assets/js/blocks/reviews/reviews-by-product/index.tsx
index ff6d152d41b..c9927088dc7 100644
--- a/assets/js/blocks/reviews/reviews-by-product/index.tsx
+++ b/assets/js/blocks/reviews/reviews-by-product/index.tsx
@@ -8,7 +8,7 @@ import { Icon, commentContent } from '@wordpress/icons';
* Internal dependencies
*/
import '../editor.scss';
-import Editor from './edit';
+import { Edit } from './edit';
import sharedAttributes from '../attributes';
import save from '../save.js';
import { example } from '../example';
@@ -64,9 +64,7 @@ registerBlockType( 'woocommerce/reviews-by-product', {
*
* @param {Object} props Props to pass to block.
*/
- edit( props ) {
- return ;
- },
+ edit: Edit,
/**
* Save the props to post content.
diff --git a/assets/js/blocks/reviews/reviews-by-product/no-reviews-placeholder.tsx b/assets/js/blocks/reviews/reviews-by-product/no-reviews-placeholder.tsx
index 9d17ee9e350..85301538094 100644
--- a/assets/js/blocks/reviews/reviews-by-product/no-reviews-placeholder.tsx
+++ b/assets/js/blocks/reviews/reviews-by-product/no-reviews-placeholder.tsx
@@ -3,13 +3,21 @@
*/
import { __, sprintf } from '@wordpress/i18n';
import { Placeholder, Spinner } from '@wordpress/components';
-import PropTypes from 'prop-types';
import ErrorPlaceholder from '@woocommerce/editor-components/error-placeholder';
import { Icon, commentContent } from '@wordpress/icons';
import { withProduct } from '@woocommerce/block-hocs';
import { decodeEntities } from '@wordpress/html-entities';
+/**
+ * Internal dependencies
+ */
+import type { NoReviewsPlaceholderProps } from './types';
-const NoReviewsPlaceholder = ( { error, getProduct, isLoading, product } ) => {
+const NoReviewsPlaceholder = ( {
+ error,
+ getProduct,
+ isLoading,
+ product,
+}: NoReviewsPlaceholderProps ) => {
const renderApiError = () => (
{
);
};
-NoReviewsPlaceholder.propTypes = {
- // from withProduct
- error: PropTypes.object,
- isLoading: PropTypes.bool,
- product: PropTypes.shape( {
- name: PropTypes.node,
- review_count: PropTypes.number,
- } ),
-};
-
export default withProduct( NoReviewsPlaceholder );
diff --git a/assets/js/blocks/reviews/reviews-by-product/types.ts b/assets/js/blocks/reviews/reviews-by-product/types.ts
index 297d7f62fbe..7fc268ca592 100644
--- a/assets/js/blocks/reviews/reviews-by-product/types.ts
+++ b/assets/js/blocks/reviews/reviews-by-product/types.ts
@@ -1,6 +1,8 @@
/**
* External dependencies
*/
+import { ErrorObject } from '@woocommerce/editor-components/error-placeholder';
+import { renderItemArgs } from '@woocommerce/editor-components/search-list-control/types';
import { BlockEditProps } from '@wordpress/blocks';
interface ReviewByProductAttributes {
@@ -13,3 +15,17 @@ export interface ReviewsByProductEditorProps
attributes: ReviewByProductAttributes;
debouncedSpeak: ( message: string ) => void;
}
+
+export interface NoReviewsPlaceholderProps {
+ error: ErrorObject;
+ getProduct: () => void;
+ isLoading: boolean;
+ product?: {
+ name: string;
+ };
+}
+
+export interface SearchListItemProps extends renderItemArgs {
+ name: string;
+ reviewCount: number;
+}
From ad9c37c5a90a99239d110d15c35e120bd447713e Mon Sep 17 00:00:00 2001
From: Hritik Chaudhary <33057454+hritikchaudhary@users.noreply.github.com>
Date: Tue, 18 Jul 2023 13:12:07 +0530
Subject: [PATCH 5/5] fixed an import
---
assets/js/blocks/reviews/reviews-by-product/block.tsx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/assets/js/blocks/reviews/reviews-by-product/block.tsx b/assets/js/blocks/reviews/reviews-by-product/block.tsx
index b7c0392f333..60992c9eba7 100644
--- a/assets/js/blocks/reviews/reviews-by-product/block.tsx
+++ b/assets/js/blocks/reviews/reviews-by-product/block.tsx
@@ -17,7 +17,7 @@ import { commentContent, Icon } from '@wordpress/icons';
* Internal dependencies
*/
import EditorContainerBlock from '../editor-container-block.js';
-import NoReviewsPlaceholder from './no-reviews-placeholder.js';
+import NoReviewsPlaceholder from './no-reviews-placeholder';
import {
getBlockControls,
getSharedReviewContentControls,