New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding test name block with support for entity data store #37132
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4143fc4
Adding test name block with support for entity data store
joelclimbsthings cd1ab11
Adding changelog
joelclimbsthings 66246d7
Changing block.ts to block.json and amending TS config to support
joelclimbsthings e19c0e5
Experiment in loading blocks from settings template
joelclimbsthings 08f5e5d
Enable the use of templates with the block editor
louwie17 46d5a53
Fix dependency
louwie17 eb2c9db
Add changelog
louwie17 0cf8eaf
Fix lint error and remove unused utils
louwie17 ca24f9e
Fix tests by fixing mocks
louwie17 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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,4 @@ | ||
Significance: minor | ||
Type: add | ||
|
||
Adding name field block to product editor. |
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
23 changes: 23 additions & 0 deletions
23
packages/js/product-editor/src/components/details-name-block/block.json
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,23 @@ | ||
{ | ||
"$schema": "https://schemas.wp.org/trunk/block.json", | ||
"apiVersion": 2, | ||
"name": "woocommerce/product-name", | ||
"title": "Product name", | ||
"category": "widgets", | ||
"description": "The product name.", | ||
"keywords": [ "products", "name", "title" ], | ||
"textdomain": "default", | ||
"attributes": { | ||
"name": { | ||
"type": "string" | ||
} | ||
}, | ||
"supports": { | ||
"align": false, | ||
"html": false, | ||
"multiple": false, | ||
"reusable": false, | ||
"inserter": false, | ||
"lock": false | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
packages/js/product-editor/src/components/details-name-block/edit.tsx
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,38 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { createElement } from '@wordpress/element'; | ||
import interpolateComponents from '@automattic/interpolate-components'; | ||
import { TextControl } from '@woocommerce/components'; | ||
import { useBlockProps } from '@wordpress/block-editor'; | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore No types for this exist yet. | ||
// eslint-disable-next-line @woocommerce/dependency-group | ||
import { useEntityProp } from '@wordpress/core-data'; | ||
|
||
export function Edit() { | ||
const blockProps = useBlockProps(); | ||
const [ name, setName ] = useEntityProp( 'postType', 'product', 'name' ); | ||
|
||
return ( | ||
<div { ...blockProps }> | ||
<TextControl | ||
label={ interpolateComponents( { | ||
mixedString: __( 'Name {{required/}}', 'woocommerce' ), | ||
components: { | ||
required: ( | ||
<span className="woocommerce-product-form__optional-input"> | ||
{ __( '(required)', 'woocommerce' ) } | ||
</span> | ||
), | ||
}, | ||
} ) } | ||
name={ 'woocommerce-product-name' } | ||
placeholder={ __( 'e.g. 12 oz Coffee Mug', 'woocommerce' ) } | ||
onChange={ setName } | ||
value={ name || '' } | ||
/> | ||
</div> | ||
); | ||
} |
17 changes: 17 additions & 0 deletions
17
packages/js/product-editor/src/components/details-name-block/index.ts
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,17 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { initBlock } from '../../utils'; | ||
import metadata from './block.json'; | ||
import { Edit } from './edit'; | ||
|
||
const { name } = metadata; | ||
|
||
export { metadata, name }; | ||
|
||
export const settings = { | ||
example: {}, | ||
edit: Edit, | ||
}; | ||
|
||
export const init = () => initBlock( { name, metadata, settings } ); |
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
5 changes: 4 additions & 1 deletion
5
packages/js/product-editor/src/components/editor/init-blocks.ts
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 |
---|---|---|
@@ -1,5 +1,8 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { init as initName } from '../details-name-block'; | ||
|
||
export const initBlocks = () => {}; | ||
export const initBlocks = () => { | ||
initName(); | ||
}; |
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,26 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { BlockConfiguration, registerBlockType } from '@wordpress/blocks'; | ||
|
||
interface BlockRepresentation { | ||
name: string; | ||
metadata: BlockConfiguration; | ||
settings: Partial< BlockConfiguration >; | ||
} | ||
|
||
/** | ||
* Function to register an individual block. | ||
* | ||
* @param {Object} block The block to be registered. | ||
* | ||
* @return {?WPBlockType} The block, if it has been successfully registered; | ||
* otherwise `undefined`. | ||
*/ | ||
export const initBlock = ( block: BlockRepresentation ) => { | ||
if ( ! block ) { | ||
return; | ||
} | ||
const { metadata, settings, name } = block; | ||
return registerBlockType( { name, ...metadata }, settings ); | ||
}; |
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 |
---|---|---|
@@ -1,6 +1,11 @@ | ||
{ | ||
"extends": "../tsconfig-cjs", | ||
"include": [ | ||
"**/*", | ||
"src/**/*.json" | ||
], | ||
"compilerOptions": { | ||
"outDir": "build" | ||
"outDir": "build", | ||
"resolveJsonModule": true, | ||
} | ||
} |
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 |
---|---|---|
@@ -1,10 +1,15 @@ | ||
{ | ||
"extends": "../tsconfig", | ||
"include": [ | ||
"**/*", | ||
"src/**/*.json" | ||
], | ||
"compilerOptions": { | ||
"rootDir": "src", | ||
"outDir": "build-module", | ||
"declaration": true, | ||
"declarationMap": true, | ||
"declarationDir": "./build-types" | ||
"declarationDir": "./build-types", | ||
"resolveJsonModule": true, | ||
} | ||
} |
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
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,4 @@ | ||
Significance: minor | ||
Type: update | ||
|
||
Update template of product type to include product name block. |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to tweak TS configuration to support importing JSON files, as there are benefits to using the standard
block.json
file to provide metadata.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1