Restructure Product Collection editor files (https://github.com/woocommerce/woocommerce-blocks/pull/11981)
* Move Product Collection editor experience components into /edit directory * Move Product Collection Inner Blocks structure to constants * Improve the Product Collection's variations names
This commit is contained in:
parent
4d72c559d3
commit
71640ef347
|
@ -3,6 +3,12 @@
|
|||
*/
|
||||
import { getSetting } from '@woocommerce/settings';
|
||||
import { objectOmit } from '@woocommerce/utils';
|
||||
import {
|
||||
type InnerBlockTemplate,
|
||||
createBlock,
|
||||
// @ts-expect-error Missing types in Gutenberg
|
||||
createBlocksFromInnerBlocksTemplate,
|
||||
} from '@wordpress/blocks';
|
||||
|
||||
/**
|
||||
* Internal dependencies
|
||||
|
@ -15,7 +21,10 @@ import {
|
|||
ProductCollectionDisplayLayout,
|
||||
LayoutOptions,
|
||||
} from './types';
|
||||
import { ImageSizing } from '../../atomic/blocks/product-elements/image/types';
|
||||
import { VARIATION_NAME as PRODUCT_TITLE_ID } from './variations/elements/product-title';
|
||||
import { getDefaultValueOfInheritQueryFromTemplate } from './utils';
|
||||
import blockJson from './block.json';
|
||||
|
||||
export const STOCK_STATUS_OPTIONS = getSetting< Record< string, string > >(
|
||||
'stockStatusOptions',
|
||||
|
@ -91,3 +100,85 @@ export const DEFAULT_FILTERS: Partial< ProductCollectionQuery > = {
|
|||
featured: DEFAULT_QUERY.featured,
|
||||
timeFrame: undefined,
|
||||
};
|
||||
|
||||
/**
|
||||
* Default inner block templates for the product collection block.
|
||||
* Exported for use in different collections, e.g., 'New Arrivals' collection.
|
||||
*/
|
||||
export const INNER_BLOCKS_PRODUCT_TEMPLATE: InnerBlockTemplate = [
|
||||
'woocommerce/product-template',
|
||||
{},
|
||||
[
|
||||
[
|
||||
'woocommerce/product-image',
|
||||
{
|
||||
imageSizing: ImageSizing.THUMBNAIL,
|
||||
},
|
||||
],
|
||||
[
|
||||
'core/post-title',
|
||||
{
|
||||
textAlign: 'center',
|
||||
level: 3,
|
||||
fontSize: 'medium',
|
||||
style: {
|
||||
spacing: {
|
||||
margin: {
|
||||
bottom: '0.75rem',
|
||||
top: '0',
|
||||
},
|
||||
},
|
||||
},
|
||||
isLink: true,
|
||||
__woocommerceNamespace: PRODUCT_TITLE_ID,
|
||||
},
|
||||
],
|
||||
[
|
||||
'woocommerce/product-price',
|
||||
{
|
||||
textAlign: 'center',
|
||||
fontSize: 'small',
|
||||
},
|
||||
],
|
||||
[
|
||||
'woocommerce/product-button',
|
||||
{
|
||||
textAlign: 'center',
|
||||
fontSize: 'small',
|
||||
},
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
export const INNER_BLOCKS_PAGINATION_TEMPLATE: InnerBlockTemplate = [
|
||||
'core/query-pagination',
|
||||
{
|
||||
layout: {
|
||||
type: 'flex',
|
||||
justifyContent: 'center',
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
export const INNER_BLOCKS_NO_RESULTS_TEMPLATE: InnerBlockTemplate = [
|
||||
'woocommerce/product-collection-no-results',
|
||||
];
|
||||
|
||||
export const INNER_BLOCKS_TEMPLATE: InnerBlockTemplate[] = [
|
||||
INNER_BLOCKS_PRODUCT_TEMPLATE,
|
||||
INNER_BLOCKS_PAGINATION_TEMPLATE,
|
||||
INNER_BLOCKS_NO_RESULTS_TEMPLATE,
|
||||
];
|
||||
|
||||
export const getDefaultProductCollection = () =>
|
||||
createBlock(
|
||||
blockJson.name,
|
||||
{
|
||||
...DEFAULT_ATTRIBUTES,
|
||||
query: {
|
||||
...DEFAULT_ATTRIBUTES.query,
|
||||
inherit: getDefaultValueOfInheritQueryFromTemplate(),
|
||||
},
|
||||
},
|
||||
createBlocksFromInnerBlocksTemplate( INNER_BLOCKS_TEMPLATE )
|
||||
);
|
||||
|
|
|
@ -2,82 +2,23 @@
|
|||
* External dependencies
|
||||
*/
|
||||
import { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';
|
||||
import { BlockEditProps, InnerBlockTemplate } from '@wordpress/blocks';
|
||||
import { BlockEditProps } from '@wordpress/blocks';
|
||||
import { useInstanceId } from '@wordpress/compose';
|
||||
import { useEffect } from '@wordpress/element';
|
||||
|
||||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
import { ImageSizing } from '../../atomic/blocks/product-elements/image/types';
|
||||
import type {
|
||||
ProductCollectionAttributes,
|
||||
ProductCollectionQuery,
|
||||
} from './types';
|
||||
import { VARIATION_NAME as PRODUCT_TITLE_ID } from './variations/elements/product-title';
|
||||
} from '../types';
|
||||
import InspectorControls from './inspector-controls';
|
||||
import { DEFAULT_ATTRIBUTES } from './constants';
|
||||
import { DEFAULT_ATTRIBUTES, INNER_BLOCKS_TEMPLATE } from '../constants';
|
||||
import './editor.scss';
|
||||
import { getDefaultValueOfInheritQueryFromTemplate } from './utils';
|
||||
import { getDefaultValueOfInheritQueryFromTemplate } from '../utils';
|
||||
import ToolbarControls from './toolbar-controls';
|
||||
|
||||
export const INNER_BLOCKS_TEMPLATE: InnerBlockTemplate[] = [
|
||||
[
|
||||
'woocommerce/product-template',
|
||||
{},
|
||||
[
|
||||
[
|
||||
'woocommerce/product-image',
|
||||
{
|
||||
imageSizing: ImageSizing.THUMBNAIL,
|
||||
},
|
||||
],
|
||||
[
|
||||
'core/post-title',
|
||||
{
|
||||
textAlign: 'center',
|
||||
level: 3,
|
||||
fontSize: 'medium',
|
||||
style: {
|
||||
spacing: {
|
||||
margin: {
|
||||
bottom: '0.75rem',
|
||||
top: '0',
|
||||
},
|
||||
},
|
||||
},
|
||||
isLink: true,
|
||||
__woocommerceNamespace: PRODUCT_TITLE_ID,
|
||||
},
|
||||
],
|
||||
[
|
||||
'woocommerce/product-price',
|
||||
{
|
||||
textAlign: 'center',
|
||||
fontSize: 'small',
|
||||
},
|
||||
],
|
||||
[
|
||||
'woocommerce/product-button',
|
||||
{
|
||||
textAlign: 'center',
|
||||
fontSize: 'small',
|
||||
},
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'core/query-pagination',
|
||||
{
|
||||
layout: {
|
||||
type: 'flex',
|
||||
justifyContent: 'center',
|
||||
},
|
||||
},
|
||||
],
|
||||
[ 'woocommerce/product-collection-no-results' ],
|
||||
];
|
||||
|
||||
const Edit = ( props: BlockEditProps< ProductCollectionAttributes > ) => {
|
||||
const { attributes, setAttributes } = props;
|
||||
const { queryId } = attributes;
|
|
@ -15,7 +15,7 @@ import {
|
|||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
import { QueryControlProps } from '../types';
|
||||
import { QueryControlProps } from '../../types';
|
||||
|
||||
const EDIT_ATTRIBUTES_URL = `${ ADMIN_URL }edit.php?post_type=product&page=product_attributes`;
|
||||
|
|
@ -13,8 +13,8 @@ import {
|
|||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
import { DisplayLayoutToolbarProps } from '../types';
|
||||
import { getDefaultDisplayLayout } from '../constants';
|
||||
import { DisplayLayoutToolbarProps } from '../../types';
|
||||
import { getDefaultDisplayLayout } from '../../constants';
|
||||
|
||||
const columnsLabel = __( 'Columns', 'woo-gutenberg-products-block' );
|
||||
const toggleLabel = __( 'Responsive', 'woo-gutenberg-products-block' );
|
|
@ -22,7 +22,7 @@ import {
|
|||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
import { ETimeFrameOperator, QueryControlProps } from '../types';
|
||||
import { ETimeFrameOperator, QueryControlProps } from '../../types';
|
||||
|
||||
const CreatedControl = ( props: QueryControlProps ) => {
|
||||
const { query, setQueryAttribute } = props;
|
|
@ -13,7 +13,7 @@ import {
|
|||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
import { QueryControlProps } from '../types';
|
||||
import { QueryControlProps } from '../../types';
|
||||
|
||||
const FeaturedProductsControl = ( props: QueryControlProps ) => {
|
||||
const { query, setQueryAttribute } = props;
|
|
@ -16,7 +16,7 @@ import {
|
|||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
import { QueryControlProps } from '../types';
|
||||
import { QueryControlProps } from '../../types';
|
||||
|
||||
/**
|
||||
* Returns:
|
|
@ -24,10 +24,10 @@ import {
|
|||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
import metadata from '../block.json';
|
||||
import { ProductCollectionAttributes } from '../types';
|
||||
import { setQueryAttribute } from '../utils';
|
||||
import { DEFAULT_FILTERS, getDefaultSettings } from '../constants';
|
||||
import metadata from '../../block.json';
|
||||
import { ProductCollectionAttributes } from '../../types';
|
||||
import { setQueryAttribute } from '../../utils';
|
||||
import { DEFAULT_FILTERS, getDefaultSettings } from '../../constants';
|
||||
import UpgradeNotice from './upgrade-notice';
|
||||
import ColumnsControl from './columns-control';
|
||||
import InheritQueryControl from './inherit-query-control';
|
|
@ -16,9 +16,9 @@ import {
|
|||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
import { ProductCollectionQuery } from '../types';
|
||||
import { DEFAULT_QUERY } from '../constants';
|
||||
import { getDefaultValueOfInheritQueryFromTemplate } from '../utils';
|
||||
import { ProductCollectionQuery } from '../../types';
|
||||
import { DEFAULT_QUERY } from '../../constants';
|
||||
import { getDefaultValueOfInheritQueryFromTemplate } from '../../utils';
|
||||
|
||||
const label = __(
|
||||
'Inherit query from template',
|
|
@ -14,7 +14,7 @@ import {
|
|||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
import { QueryControlProps } from '../types';
|
||||
import { QueryControlProps } from '../../types';
|
||||
|
||||
const KeywordControl = ( props: QueryControlProps ) => {
|
||||
const { query, setQueryAttribute } = props;
|
|
@ -19,7 +19,7 @@ import {
|
|||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
import { DisplayLayoutToolbarProps, LayoutOptions } from '../types';
|
||||
import { DisplayLayoutToolbarProps, LayoutOptions } from '../../types';
|
||||
|
||||
const getHelpText = ( layoutOptions: LayoutOptions ) => {
|
||||
switch ( layoutOptions ) {
|
|
@ -12,7 +12,7 @@ import {
|
|||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
import { QueryControlProps } from '../types';
|
||||
import { QueryControlProps } from '../../types';
|
||||
|
||||
const OnSaleControl = ( props: QueryControlProps ) => {
|
||||
const { query, setQueryAttribute } = props;
|
|
@ -16,8 +16,8 @@ import {
|
|||
TProductCollectionOrder,
|
||||
TProductCollectionOrderBy,
|
||||
QueryControlProps,
|
||||
} from '../types';
|
||||
import { getDefaultQuery } from '../constants';
|
||||
} from '../../types';
|
||||
import { getDefaultQuery } from '../../constants';
|
||||
|
||||
const orderOptions = [
|
||||
{
|
|
@ -13,8 +13,8 @@ import {
|
|||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
import { QueryControlProps } from '../types';
|
||||
import { STOCK_STATUS_OPTIONS, getDefaultStockStatuses } from '../constants';
|
||||
import { QueryControlProps } from '../../types';
|
||||
import { STOCK_STATUS_OPTIONS, getDefaultStockStatuses } from '../../constants';
|
||||
|
||||
/**
|
||||
* Gets the id of a specific stock status from its text label
|
|
@ -15,7 +15,7 @@ import {
|
|||
* Internal dependencies
|
||||
*/
|
||||
import TaxonomyItem from './taxonomy-item';
|
||||
import { ProductCollectionQuery } from '../../types';
|
||||
import { ProductCollectionQuery } from '../../../types';
|
||||
|
||||
interface TaxonomyControlProps {
|
||||
query: ProductCollectionQuery;
|
|
@ -12,7 +12,7 @@ import {
|
|||
DisplayLayoutToolbarProps,
|
||||
ProductCollectionDisplayLayout,
|
||||
LayoutOptions,
|
||||
} from '../types';
|
||||
} from '../../types';
|
||||
|
||||
const DisplayLayoutToolbar = ( props: DisplayLayoutToolbarProps ) => {
|
||||
const { type, columns, shrinkColumns } = props.displayLayout;
|
|
@ -16,7 +16,7 @@ import {
|
|||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
import { ProductCollectionQuery } from '../types';
|
||||
import { ProductCollectionQuery } from '../../types';
|
||||
|
||||
interface DisplaySettingsToolbarProps {
|
||||
query: ProductCollectionQuery;
|
|
@ -8,8 +8,8 @@ import { BlockControls } from '@wordpress/block-editor';
|
|||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
import { setQueryAttribute } from '../utils';
|
||||
import { ProductCollectionAttributes } from '../types';
|
||||
import { setQueryAttribute } from '../../utils';
|
||||
import { ProductCollectionAttributes } from '../../types';
|
||||
import DisplaySettingsToolbar from './display-settings-toolbar';
|
||||
import DisplayLayoutToolbar from './display-layout-toolbar';
|
||||
import PatternChooserToolbar from './pattern-chooser-toolbar';
|
|
@ -13,7 +13,7 @@ import { type BlockInstance, cloneBlock } from '@wordpress/blocks';
|
|||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
import { ProductCollectionQuery } from '../types';
|
||||
import { ProductCollectionQuery } from '../../types';
|
||||
|
||||
const blockName = 'woocommerce/product-collection';
|
||||
|
|
@ -12,9 +12,10 @@ import {
|
|||
BLOCK_DESCRIPTION,
|
||||
BLOCK_TITLE,
|
||||
} from '../../../../atomic/blocks/product-elements/summary/constants';
|
||||
import blockJson from '../../block.json';
|
||||
|
||||
export const CORE_NAME = 'core/post-excerpt';
|
||||
export const VARIATION_NAME = 'woocommerce/product-collection/product-summary';
|
||||
export const VARIATION_NAME = `${ blockJson.name }/product-summary`;
|
||||
|
||||
const registerProductSummary = () => {
|
||||
registerElementVariation( CORE_NAME, {
|
||||
|
|
|
@ -12,9 +12,10 @@ import {
|
|||
BLOCK_DESCRIPTION,
|
||||
BLOCK_TITLE,
|
||||
} from '../../../../atomic/blocks/product-elements/title/constants';
|
||||
import blockJson from '../../block.json';
|
||||
|
||||
export const CORE_NAME = 'core/post-title';
|
||||
export const VARIATION_NAME = 'woocommerce/product-collection/product-title';
|
||||
export const VARIATION_NAME = `${ blockJson.name }/product-title`;
|
||||
|
||||
const registerProductTitle = () => {
|
||||
registerElementVariation( CORE_NAME, {
|
||||
|
|
Loading…
Reference in New Issue