Remove propTypes definitions from All Reviews block (https://github.com/woocommerce/woocommerce-blocks/pull/9631)
* converted all-reviews block to tsx and removed proptypes * Update assets/js/blocks/reviews/all-reviews/index.tsx Co-authored-by: Niels Lange <niels.lange@a8c.com> * Update assets/js/blocks/reviews/all-reviews/edit.tsx Co-authored-by: Niels Lange <niels.lange@a8c.com> * Update assets/js/blocks/reviews/all-reviews/block.tsx Co-authored-by: Niels Lange <niels.lange@a8c.com> --------- Co-authored-by: Niels Lange <info@nielslange.de> Co-authored-by: Niels Lange <niels.lange@a8c.com>
This commit is contained in:
parent
525bd58c74
commit
93119e9de6
|
@ -4,18 +4,18 @@
|
||||||
import { __ } from '@wordpress/i18n';
|
import { __ } from '@wordpress/i18n';
|
||||||
import { InspectorControls } from '@wordpress/block-editor';
|
import { InspectorControls } from '@wordpress/block-editor';
|
||||||
import { PanelBody, ToggleControl } from '@wordpress/components';
|
import { PanelBody, ToggleControl } from '@wordpress/components';
|
||||||
import PropTypes from 'prop-types';
|
|
||||||
import { Icon, postComments } from '@wordpress/icons';
|
import { Icon, postComments } from '@wordpress/icons';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
*/
|
*/
|
||||||
import EditorContainerBlock from '../editor-container-block.js';
|
import EditorContainerBlock from '../editor-container-block.js';
|
||||||
import NoReviewsPlaceholder from './no-reviews-placeholder.js';
|
import NoReviewsPlaceholder from './no-reviews-placeholder';
|
||||||
import {
|
import {
|
||||||
getSharedReviewContentControls,
|
getSharedReviewContentControls,
|
||||||
getSharedReviewListControls,
|
getSharedReviewListControls,
|
||||||
} from '../edit-utils.js';
|
} from '../edit-utils.js';
|
||||||
|
import type { AllReviewsEditorProps } from './types';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Component to handle edit mode of "All Reviews".
|
* Component to handle edit mode of "All Reviews".
|
||||||
|
@ -24,7 +24,10 @@ import {
|
||||||
* @param {Object} props.attributes Incoming block attributes.
|
* @param {Object} props.attributes Incoming block attributes.
|
||||||
* @param {function(any):any} props.setAttributes Setter for block attributes.
|
* @param {function(any):any} props.setAttributes Setter for block attributes.
|
||||||
*/
|
*/
|
||||||
const AllReviewsEditor = ( { attributes, setAttributes } ) => {
|
const AllReviewsEditor = ( {
|
||||||
|
attributes,
|
||||||
|
setAttributes,
|
||||||
|
}: AllReviewsEditorProps ) => {
|
||||||
const getInspectorControls = () => {
|
const getInspectorControls = () => {
|
||||||
return (
|
return (
|
||||||
<InspectorControls key="inspector">
|
<InspectorControls key="inspector">
|
||||||
|
@ -72,25 +75,10 @@ const AllReviewsEditor = ( { attributes, setAttributes } ) => {
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
name={ __( 'All Reviews', 'woo-gutenberg-products-block' ) }
|
name={ __( 'All Reviews', 'woo-gutenberg-products-block' ) }
|
||||||
noReviewsPlaceholder={ NoReviewsPlaceholder }
|
noReviewsPlaceholder={ NoReviewsPlaceholder() }
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
AllReviewsEditor.propTypes = {
|
|
||||||
/**
|
|
||||||
* The attributes for this block.
|
|
||||||
*/
|
|
||||||
attributes: PropTypes.object.isRequired,
|
|
||||||
/**
|
|
||||||
* The register block name.
|
|
||||||
*/
|
|
||||||
name: PropTypes.string.isRequired,
|
|
||||||
/**
|
|
||||||
* A callback to update attributes.
|
|
||||||
*/
|
|
||||||
setAttributes: PropTypes.func.isRequired,
|
|
||||||
};
|
|
||||||
|
|
||||||
export default AllReviewsEditor;
|
export default AllReviewsEditor;
|
|
@ -0,0 +1,20 @@
|
||||||
|
/**
|
||||||
|
* External dependencies
|
||||||
|
*/
|
||||||
|
import { useBlockProps } from '@wordpress/block-editor';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal dependencies
|
||||||
|
*/
|
||||||
|
import Block from './block';
|
||||||
|
import type { AllReviewsEditorProps } from './types';
|
||||||
|
|
||||||
|
export const Edit = ( props: unknown & AllReviewsEditorProps ): JSX.Element => {
|
||||||
|
const blockProps = useBlockProps();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div { ...blockProps }>
|
||||||
|
<Block { ...props } />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
|
@ -9,10 +9,11 @@ import { Icon, postComments } from '@wordpress/icons';
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
*/
|
*/
|
||||||
import '../editor.scss';
|
import '../editor.scss';
|
||||||
import edit from './edit';
|
import { Edit } from './edit';
|
||||||
import sharedAttributes from '../attributes';
|
import sharedAttributes from '../attributes';
|
||||||
import save from '../save.js';
|
import save from '../save.js';
|
||||||
import { example } from '../example';
|
import { example } from '../example';
|
||||||
|
import type { AllReviewsEditorProps } from './types';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register and run the "All Reviews" block.
|
* Register and run the "All Reviews" block.
|
||||||
|
@ -68,7 +69,7 @@ registerBlockType( 'woocommerce/all-reviews', {
|
||||||
type: 'block',
|
type: 'block',
|
||||||
blocks: [ 'core/legacy-widget' ],
|
blocks: [ 'core/legacy-widget' ],
|
||||||
// We can't transform if raw instance isn't shown in the REST API.
|
// We can't transform if raw instance isn't shown in the REST API.
|
||||||
isMatch: ( { idBase, instance } ) =>
|
isMatch: ( { idBase, instance }: AllReviewsEditorProps ) =>
|
||||||
idBase === 'woocommerce_recent_reviews' && !! instance?.raw,
|
idBase === 'woocommerce_recent_reviews' && !! instance?.raw,
|
||||||
transform: ( { instance } ) =>
|
transform: ( { instance } ) =>
|
||||||
createBlock( 'woocommerce/all-reviews', {
|
createBlock( 'woocommerce/all-reviews', {
|
||||||
|
@ -83,6 +84,6 @@ registerBlockType( 'woocommerce/all-reviews', {
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
||||||
edit,
|
edit: Edit,
|
||||||
save,
|
save,
|
||||||
} );
|
} );
|
|
@ -5,7 +5,7 @@ import { __ } from '@wordpress/i18n';
|
||||||
import { Placeholder } from '@wordpress/components';
|
import { Placeholder } from '@wordpress/components';
|
||||||
import { Icon, postComments } from '@wordpress/icons';
|
import { Icon, postComments } from '@wordpress/icons';
|
||||||
|
|
||||||
const NoCategoryReviewsPlaceholder = () => {
|
const NoCategoryReviewsPlaceholder = (): JSX.Element => {
|
||||||
return (
|
return (
|
||||||
<Placeholder
|
<Placeholder
|
||||||
className="wc-block-all-reviews"
|
className="wc-block-all-reviews"
|
|
@ -0,0 +1,13 @@
|
||||||
|
export interface AllReviewsEditorProps {
|
||||||
|
attributes: {
|
||||||
|
showProductName: boolean;
|
||||||
|
};
|
||||||
|
setAttributes: ( attributes: { showProductName?: boolean } ) => void;
|
||||||
|
debouncedSpeak: ( message: string ) => void;
|
||||||
|
idBase: unknown;
|
||||||
|
instance: {
|
||||||
|
raw: {
|
||||||
|
number: number;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in New Issue