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

Commit 51b76a9

Browse files
TS error fixes
1 parent 82df858 commit 51b76a9

File tree

5 files changed

+57
-25
lines changed

5 files changed

+57
-25
lines changed

assets/js/blocks/reviews/reviews-by-product/block.tsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
getSharedReviewContentControls,
2424
getSharedReviewListControls,
2525
} from '../edit-utils.js';
26-
import { ReviewsByProductEditorProps } from './types';
26+
import type { ReviewsByProductEditorProps, SearchListItemProps } from './types';
2727

2828
const ReviewsByProductEditor = ( {
2929
attributes,
@@ -32,9 +32,7 @@ const ReviewsByProductEditor = ( {
3232
}: ReviewsByProductEditorProps ) => {
3333
const { editMode, productId } = attributes;
3434

35-
const renderProductControlItem = ( args ) => {
36-
const { item = 0 } = args;
37-
35+
const renderProductControlItem = ( args: SearchListItemProps ) => {
3836
return (
3937
<SearchListItem
4038
{ ...args }
@@ -43,21 +41,21 @@ const ReviewsByProductEditor = ( {
4341
_n(
4442
'%d review',
4543
'%d reviews',
46-
item.review_count,
44+
args.reviewCount,
4745
'woo-gutenberg-products-block'
4846
),
49-
item.review_count
47+
args.reviewCount
5048
) }
5149
aria-label={ sprintf(
5250
/* translators: %1$s is the item name, and %2$d is the number of reviews for the item. */
5351
_n(
5452
'%1$s, has %2$d review',
5553
'%1$s, has %2$d reviews',
56-
item.review_count,
54+
args.reviewCount,
5755
'woo-gutenberg-products-block'
5856
),
59-
item.name,
60-
item.review_count
57+
args.name,
58+
args.reviewCount
6159
) }
6260
/>
6361
);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* External dependencies
3+
*/
4+
import { useBlockProps } from '@wordpress/block-editor';
5+
6+
/**
7+
* Internal dependencies
8+
*/
9+
import Block from './block';
10+
import type { ReviewsByProductEditorProps } from './types';
11+
12+
export const Edit = (
13+
props: unknown & ReviewsByProductEditorProps
14+
): JSX.Element => {
15+
const blockProps = useBlockProps();
16+
17+
return (
18+
<div { ...blockProps }>
19+
<Block { ...props } />
20+
</div>
21+
);
22+
};

assets/js/blocks/reviews/reviews-by-product/index.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { Icon, commentContent } from '@wordpress/icons';
88
* Internal dependencies
99
*/
1010
import '../editor.scss';
11-
import Editor from './edit';
11+
import { Edit } from './edit';
1212
import sharedAttributes from '../attributes';
1313
import save from '../save.js';
1414
import { example } from '../example';
@@ -64,9 +64,7 @@ registerBlockType( 'woocommerce/reviews-by-product', {
6464
*
6565
* @param {Object} props Props to pass to block.
6666
*/
67-
edit( props ) {
68-
return <Editor { ...props } />;
69-
},
67+
edit: Edit,
7068

7169
/**
7270
* Save the props to post content.

assets/js/blocks/reviews/reviews-by-product/no-reviews-placeholder.tsx

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,21 @@
33
*/
44
import { __, sprintf } from '@wordpress/i18n';
55
import { Placeholder, Spinner } from '@wordpress/components';
6-
import PropTypes from 'prop-types';
76
import ErrorPlaceholder from '@woocommerce/editor-components/error-placeholder';
87
import { Icon, commentContent } from '@wordpress/icons';
98
import { withProduct } from '@woocommerce/block-hocs';
109
import { decodeEntities } from '@wordpress/html-entities';
10+
/**
11+
* Internal dependencies
12+
*/
13+
import type { NoReviewsPlaceholderProps } from './types';
1114

12-
const NoReviewsPlaceholder = ( { error, getProduct, isLoading, product } ) => {
15+
const NoReviewsPlaceholder = ( {
16+
error,
17+
getProduct,
18+
isLoading,
19+
product,
20+
}: NoReviewsPlaceholderProps ) => {
1321
const renderApiError = () => (
1422
<ErrorPlaceholder
1523
className="wc-block-featured-product-error"
@@ -53,14 +61,4 @@ const NoReviewsPlaceholder = ( { error, getProduct, isLoading, product } ) => {
5361
);
5462
};
5563

56-
NoReviewsPlaceholder.propTypes = {
57-
// from withProduct
58-
error: PropTypes.object,
59-
isLoading: PropTypes.bool,
60-
product: PropTypes.shape( {
61-
name: PropTypes.node,
62-
review_count: PropTypes.number,
63-
} ),
64-
};
65-
6664
export default withProduct( NoReviewsPlaceholder );

assets/js/blocks/reviews/reviews-by-product/types.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/**
22
* External dependencies
33
*/
4+
import { ErrorObject } from '@woocommerce/editor-components/error-placeholder';
5+
import { renderItemArgs } from '@woocommerce/editor-components/search-list-control/types';
46
import { BlockEditProps } from '@wordpress/blocks';
57

68
interface ReviewByProductAttributes {
@@ -13,3 +15,17 @@ export interface ReviewsByProductEditorProps
1315
attributes: ReviewByProductAttributes;
1416
debouncedSpeak: ( message: string ) => void;
1517
}
18+
19+
export interface NoReviewsPlaceholderProps {
20+
error: ErrorObject;
21+
getProduct: () => void;
22+
isLoading: boolean;
23+
product?: {
24+
name: string;
25+
};
26+
}
27+
28+
export interface SearchListItemProps extends renderItemArgs {
29+
name: string;
30+
reviewCount: number;
31+
}

0 commit comments

Comments
 (0)