This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
All Products block: Migrate to block.json (#6754)
* All Products: Use block.json to register * Simplify edit def * Separate file for save * No more client-side registration * Remove uncommented, now-obsolete code * Add back client-side block registration * Remove stray textdomain from keywords field * Add textdomain field * Set apiVersion to 1
- Loading branch information
Showing
6 changed files
with
147 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ | ||
"$schema": "https://schemas.wp.org/trunk/block.json", | ||
"apiVersion": 1, | ||
"textdomain": "woo-gutenberg-products-block", | ||
"name": "woocommerce/all-products", | ||
"title": "All Products", | ||
"category": "woocommerce", | ||
"keywords": [ "WooCommerce" ], | ||
"description": "Display products from your store in a grid layout.", | ||
"supports": { | ||
"align": [ "wide", "full" ], | ||
"html": false, | ||
"multiple": false | ||
}, | ||
"example": { | ||
"attributes": { | ||
"isPreview": true | ||
} | ||
}, | ||
"attributes": { | ||
"columns": { | ||
"type": "number" | ||
}, | ||
"rows": { | ||
"type": "number" | ||
}, | ||
"alignButtons": { | ||
"type": "boolean" | ||
}, | ||
"contentVisibility": { | ||
"type": "object" | ||
}, | ||
"orderby": { | ||
"type": "string" | ||
}, | ||
"layoutConfig": { | ||
"type": "array" | ||
}, | ||
"isPreview": { | ||
"type": "boolean", | ||
"default": false | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { getSetting } from '@woocommerce/settings'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { DEFAULT_PRODUCT_LIST_LAYOUT } from '../base-utils'; | ||
|
||
export default { | ||
columns: getSetting( 'default_columns', 3 ), | ||
rows: getSetting( 'default_rows', 3 ), | ||
alignButtons: false, | ||
contentVisibility: { | ||
orderBy: true, | ||
}, | ||
orderby: 'date', | ||
layoutConfig: DEFAULT_PRODUCT_LIST_LAYOUT, | ||
isPreview: false, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { InnerBlocks } from '@wordpress/block-editor'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import metadata from './block.json'; | ||
import { getBlockClassName } from '../utils.js'; | ||
|
||
const { attributes: attributeDefinitions } = metadata; | ||
|
||
const v1 = { | ||
attributes: Object.assign( {}, attributeDefinitions, { | ||
rows: { type: 'number', default: 1 }, | ||
} ), | ||
save( { attributes } ) { | ||
const data = { | ||
'data-attributes': JSON.stringify( attributes ), | ||
}; | ||
return ( | ||
<div | ||
className={ getBlockClassName( | ||
'wc-block-all-products', | ||
attributes | ||
) } | ||
{ ...data } | ||
> | ||
<InnerBlocks.Content /> | ||
</div> | ||
); | ||
}, | ||
}; | ||
|
||
export default [ v1 ]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { InnerBlocks } from '@wordpress/block-editor'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { getBlockClassName } from '../utils.js'; | ||
|
||
export default function save( { attributes } ) { | ||
const dataAttributes = {}; | ||
Object.keys( attributes ) | ||
.sort() | ||
.forEach( ( key ) => { | ||
dataAttributes[ key ] = attributes[ key ]; | ||
} ); | ||
const data = { | ||
'data-attributes': JSON.stringify( dataAttributes ), | ||
}; | ||
return ( | ||
<div | ||
className={ getBlockClassName( | ||
'wc-block-all-products', | ||
attributes | ||
) } | ||
{ ...data } | ||
> | ||
<InnerBlocks.Content /> | ||
</div> | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.