* Converted config files

* Converted constants file

* Converted attributes file

* Coverted edit file

* Convert block file

* Remove space from config
This commit is contained in:
Tom Cafferkey 2021-10-12 09:21:00 +01:00 committed by GitHub
parent 8475bc7bad
commit 0f4161aff9
7 changed files with 27 additions and 17 deletions

View File

@ -1,4 +1,4 @@
export const blockAttributes = { export const blockAttributes: Record< string, Record< string, unknown > > = {
productId: { productId: {
type: 'number', type: 'number',
default: 0, default: 0,

View File

@ -2,7 +2,6 @@
* External dependencies * External dependencies
*/ */
import { __ } from '@wordpress/i18n'; import { __ } from '@wordpress/i18n';
import PropTypes from 'prop-types';
import classnames from 'classnames'; import classnames from 'classnames';
import { import {
useInnerBlockLayoutContext, useInnerBlockLayoutContext,
@ -10,11 +9,15 @@ import {
} from '@woocommerce/shared-context'; } from '@woocommerce/shared-context';
import { isEmpty } from 'lodash'; import { isEmpty } from 'lodash';
import { withProductDataContext } from '@woocommerce/shared-hocs'; import { withProductDataContext } from '@woocommerce/shared-hocs';
import { HTMLAttributes } from 'react';
/** /**
* Internal dependencies * Internal dependencies
*/ */
import './style.scss'; import './style.scss';
import { Attributes } from './types';
type Props = Attributes & HTMLAttributes< HTMLDivElement >;
/** /**
* Product Category Block Component. * Product Category Block Component.
@ -23,7 +26,7 @@ import './style.scss';
* @param {string} [props.className] CSS Class name for the component. * @param {string} [props.className] CSS Class name for the component.
* @return {*} The component. * @return {*} The component.
*/ */
const Block = ( { className } ) => { const Block = ( { className }: Props ): JSX.Element | null => {
const { parentClassName } = useInnerBlockLayoutContext(); const { parentClassName } = useInnerBlockLayoutContext();
const { product } = useProductDataContext(); const { product } = useProductDataContext();
@ -57,8 +60,4 @@ const Block = ( { className } ) => {
); );
}; };
Block.propTypes = {
className: PropTypes.string,
};
export default withProductDataContext( Block ); export default withProductDataContext( Block );

View File

@ -4,12 +4,12 @@
import { __ } from '@wordpress/i18n'; import { __ } from '@wordpress/i18n';
import { folder, Icon } from '@woocommerce/icons'; import { folder, Icon } from '@woocommerce/icons';
export const BLOCK_TITLE = __( export const BLOCK_TITLE: string = __(
'Product Category List', 'Product Category List',
'woo-gutenberg-products-block' 'woo-gutenberg-products-block'
); );
export const BLOCK_ICON = <Icon srcElement={ folder } />; export const BLOCK_ICON: JSX.Element = <Icon srcElement={ folder } />;
export const BLOCK_DESCRIPTION = __( export const BLOCK_DESCRIPTION: string = __(
'Display a list of categories belonging to a product.', 'Display a list of categories belonging to a product.',
'woo-gutenberg-products-block' 'woo-gutenberg-products-block'
); );

View File

@ -11,8 +11,13 @@ import EditProductLink from '@woocommerce/editor-components/edit-product-link';
import Block from './block'; import Block from './block';
import withProductSelector from '../shared/with-product-selector'; import withProductSelector from '../shared/with-product-selector';
import { BLOCK_TITLE, BLOCK_ICON } from './constants'; import { BLOCK_TITLE, BLOCK_ICON } from './constants';
import { Attributes } from './types';
const Edit = ( { attributes } ) => { interface Props {
attributes: Attributes;
}
const Edit = ( { attributes }: Props ): JSX.Element => {
return ( return (
<> <>
<EditProductLink /> <EditProductLink />

View File

@ -2,11 +2,12 @@
* External dependencies * External dependencies
*/ */
import { registerExperimentalBlockType } from '@woocommerce/block-settings'; import { registerExperimentalBlockType } from '@woocommerce/block-settings';
import { BlockConfiguration } from '@wordpress/blocks';
/** /**
* Internal dependencies * Internal dependencies
*/ */
import sharedConfig from '../shared/config'; import sharedConfig from './../shared/config';
import attributes from './attributes'; import attributes from './attributes';
import edit from './edit'; import edit from './edit';
import { import {
@ -15,7 +16,8 @@ import {
BLOCK_DESCRIPTION as description, BLOCK_DESCRIPTION as description,
} from './constants'; } from './constants';
const blockConfig = { const blockConfig: BlockConfiguration = {
...sharedConfig,
title, title,
description, description,
icon: { icon: {
@ -26,7 +28,7 @@ const blockConfig = {
edit, edit,
}; };
registerExperimentalBlockType( 'woocommerce/product-category-list', { registerExperimentalBlockType(
...sharedConfig, 'woocommerce/product-category-list',
...blockConfig, blockConfig
} ); );

View File

@ -0,0 +1,3 @@
export interface Attributes {
productId: number;
}

View File

@ -52,6 +52,7 @@
"@woocommerce/knobs": [ "storybook/knobs" ], "@woocommerce/knobs": [ "storybook/knobs" ],
"@woocommerce/settings": [ "assets/js/settings/shared" ], "@woocommerce/settings": [ "assets/js/settings/shared" ],
"@woocommerce/shared-context": [ "assets/js/shared/context" ], "@woocommerce/shared-context": [ "assets/js/shared/context" ],
"@woocommerce/shared-hocs": [ "assets/js/shared/hocs" ],
"@woocommerce/type-defs/*": [ "assets/js/types/type-defs/*" ], "@woocommerce/type-defs/*": [ "assets/js/types/type-defs/*" ],
"@woocommerce/types": [ "assets/js/types" ] "@woocommerce/types": [ "assets/js/types" ]
} }