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
List Custom Fields for New Product Editor #45360
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
16a6280
Create woocommerce/product-custom-fields block
mdperez86 b652a1c
Register woocommerce/product-custom-fields block
mdperez86 41f6e29
Add product-custom-fields block to the simple product template
mdperez86 f93be66
Create useCustomFields hook
mdperez86 62e7f48
Create empty state
mdperez86 bf0ed6f
Create CustomFields component
mdperez86 a638a52
Add custom fields table
mdperez86 916cf39
Add custom field remove button
mdperez86 d4e9bf6
Hide the custom fields table base on the toggle value
mdperez86 c19520b
Remove non list features
mdperez86 215e217
Add changelog files
mdperez86 90cd051
Fix linter errors
mdperez86 a4cd9a0
Fix empty state styles
mdperez86 08bf59d
Fix php linter error
mdperez86 869834b
Remove context from the woocommerce/product-custom-fields-toggle-fiel…
mdperez86 f1969c4
Change url for the Read more about custom fields
mdperez86 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 | ||
|
||
Create woocommerce/product-custom-fields 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
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
16 changes: 11 additions & 5 deletions
16
packages/js/product-editor/src/blocks/product-fields/custom-fields-toggle/editor.scss
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,9 +1,15 @@ | ||
.wp-block-woocommerce-product-custom-fields-toggle-field { | ||
display: flex; | ||
gap: $grid-unit; | ||
align-items: center; | ||
&__content { | ||
display: flex; | ||
gap: $grid-unit; | ||
align-items: center; | ||
|
||
.components-spinner { | ||
margin: 0; | ||
.components-spinner { | ||
margin: 0; | ||
} | ||
} | ||
|
||
&__inner-blocks { | ||
margin-top: $grid-unit-60; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
packages/js/product-editor/src/blocks/product-fields/custom-fields/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,27 @@ | ||
{ | ||
"$schema": "https://schemas.wp.org/trunk/block.json", | ||
"apiVersion": 2, | ||
"name": "woocommerce/product-custom-fields", | ||
"title": "Product custom fields control", | ||
"category": "woocommerce", | ||
"description": "The product custom fields.", | ||
"keywords": [ "products", "custom", "fields" ], | ||
"textdomain": "default", | ||
"attributes": { | ||
"name": { | ||
"type": "string", | ||
"__experimentalRole": "content" | ||
} | ||
}, | ||
"supports": { | ||
"align": false, | ||
"html": false, | ||
"multiple": true, | ||
"reusable": true, | ||
"inserter": false, | ||
"lock": false, | ||
"__experimentalToolbar": false | ||
}, | ||
"usesContext": [ "postType" ], | ||
"editorStyle": "file:./editor.css" | ||
} |
24 changes: 24 additions & 0 deletions
24
packages/js/product-editor/src/blocks/product-fields/custom-fields/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,24 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { createElement } from '@wordpress/element'; | ||
import { useWooBlockProps } from '@woocommerce/block-templates'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { CustomFields } from '../../../components/custom-fields'; | ||
import { ProductEditorBlockEditProps } from '../../../types'; | ||
import { CustomFieldsBlockAttributes } from './types'; | ||
|
||
export function Edit( { | ||
attributes, | ||
}: ProductEditorBlockEditProps< CustomFieldsBlockAttributes > ) { | ||
const blockProps = useWooBlockProps( attributes ); | ||
|
||
return ( | ||
<div { ...blockProps }> | ||
<CustomFields /> | ||
</div> | ||
); | ||
} |
2 changes: 2 additions & 0 deletions
2
packages/js/product-editor/src/blocks/product-fields/custom-fields/editor.scss
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,2 @@ | ||
.wp-block-woocommerce-product-custom-fields-field { | ||
} |
23 changes: 23 additions & 0 deletions
23
packages/js/product-editor/src/blocks/product-fields/custom-fields/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,23 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import blockConfiguration from './block.json'; | ||
import { Edit } from './edit'; | ||
import { registerProductEditorBlockType } from '../../../utils'; | ||
|
||
const { name, ...metadata } = blockConfiguration; | ||
|
||
export { metadata, name }; | ||
|
||
export const settings = { | ||
example: {}, | ||
edit: Edit, | ||
}; | ||
|
||
export function init() { | ||
return registerProductEditorBlockType( { | ||
name, | ||
metadata: metadata as never, | ||
settings: settings as never, | ||
} ); | ||
} |
8 changes: 8 additions & 0 deletions
8
packages/js/product-editor/src/blocks/product-fields/custom-fields/types.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,8 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { BlockAttributes } from '@wordpress/blocks'; | ||
|
||
export interface CustomFieldsBlockAttributes extends BlockAttributes { | ||
label: string; | ||
} |
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
55 changes: 55 additions & 0 deletions
55
packages/js/product-editor/src/components/custom-fields/custom-fields.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,55 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { createElement } from '@wordpress/element'; | ||
import { __ } from '@wordpress/i18n'; | ||
import classNames from 'classnames'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { useCustomFields } from '../../hooks/use-custom-fields'; | ||
import { EmptyState } from './empty-state'; | ||
import type { CustomFieldsProps } from './types'; | ||
|
||
export function CustomFields( { className, ...props }: CustomFieldsProps ) { | ||
const { customFields } = useCustomFields(); | ||
|
||
if ( customFields.length === 0 ) { | ||
return <EmptyState />; | ||
} | ||
|
||
return ( | ||
<table | ||
{ ...props } | ||
className={ classNames( | ||
'woocommerce-product-custom-fields__table', | ||
className | ||
) } | ||
> | ||
<thead> | ||
<tr className="woocommerce-product-custom-fields__table-row"> | ||
<th>{ __( 'Name', 'woocommerce' ) }</th> | ||
<th>{ __( 'Value', 'woocommerce' ) }</th> | ||
<th>{ __( 'Actions', 'woocommerce' ) }</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{ customFields.map( ( customField ) => ( | ||
<tr | ||
className="woocommerce-product-custom-fields__table-row" | ||
key={ customField.id ?? customField.key } | ||
> | ||
<td className="woocommerce-product-custom-fields__table-datacell"> | ||
{ customField.key } | ||
</td> | ||
<td className="woocommerce-product-custom-fields__table-datacell"> | ||
{ customField.value } | ||
</td> | ||
<td className="woocommerce-product-custom-fields__table-datacell"></td> | ||
</tr> | ||
) ) } | ||
</tbody> | ||
</table> | ||
); | ||
} |
54 changes: 54 additions & 0 deletions
54
packages/js/product-editor/src/components/custom-fields/empty-state/empty-state.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,54 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { createElement } from '@wordpress/element'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
|
||
export function EmptyState( | ||
props: React.DetailedHTMLProps< | ||
React.HTMLAttributes< HTMLDivElement >, | ||
HTMLDivElement | ||
> | ||
) { | ||
return ( | ||
<div | ||
{ ...props } | ||
role="none" | ||
className="woocommerce-product-custom-fields__empty-state" | ||
> | ||
<div className="woocommerce-product-custom-fields__empty-state-row"> | ||
<div>{ __( 'Custom field 1', 'woocommerce' ) }</div> | ||
<div> | ||
<div className="woocommerce-product-custom-fields__empty-state-name" /> | ||
</div> | ||
<div> | ||
<div className="woocommerce-product-custom-fields__empty-state-actions" /> | ||
</div> | ||
</div> | ||
|
||
<div className="woocommerce-product-custom-fields__empty-state-row"> | ||
<div>{ __( 'Custom field 2', 'woocommerce' ) }</div> | ||
<div> | ||
<div className="woocommerce-product-custom-fields__empty-state-name" /> | ||
</div> | ||
<div> | ||
<div className="woocommerce-product-custom-fields__empty-state-actions" /> | ||
</div> | ||
</div> | ||
|
||
<div className="woocommerce-product-custom-fields__empty-state-row"> | ||
<div>{ __( 'Custom field 3', 'woocommerce' ) }</div> | ||
<div> | ||
<div className="woocommerce-product-custom-fields__empty-state-name" /> | ||
</div> | ||
<div> | ||
<div className="woocommerce-product-custom-fields__empty-state-actions" /> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} |
1 change: 1 addition & 0 deletions
1
packages/js/product-editor/src/components/custom-fields/empty-state/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 @@ | ||
export * from './empty-state'; |
58 changes: 58 additions & 0 deletions
58
packages/js/product-editor/src/components/custom-fields/empty-state/style.scss
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,58 @@ | ||
.woocommerce-product-custom-fields__empty-state { | ||
@mixin skeleton { | ||
background-color: $gray-200; | ||
border-radius: $grid-unit-05; | ||
width: $grid-unit-30; | ||
height: $grid-unit; | ||
} | ||
|
||
border: 1px dashed $gray-400; | ||
padding: 0 $grid-unit-30; | ||
border-radius: 2px; | ||
|
||
&-row { | ||
display: grid; | ||
grid-template-columns: 1.5fr 1fr 0.5fr; | ||
height: $grid-unit-80; | ||
align-items: center; | ||
border-top: 1px solid $gray-100; | ||
|
||
&:first-child { | ||
border-top: none; | ||
|
||
.woocommerce-product-custom-fields__empty-state-name { | ||
width: 140px; | ||
} | ||
} | ||
|
||
&:nth-child(2) { | ||
opacity: 0.7; | ||
|
||
.woocommerce-product-custom-fields__empty-state-name { | ||
width: 75px; | ||
} | ||
} | ||
|
||
&:nth-child(3) { | ||
opacity: 0.5; | ||
|
||
.woocommerce-product-custom-fields__empty-state-name { | ||
width: 114px; | ||
} | ||
} | ||
|
||
:last-child { | ||
display: flex; | ||
justify-content: flex-end; | ||
} | ||
} | ||
|
||
&-name { | ||
@include skeleton(); | ||
} | ||
|
||
&-actions { | ||
@include skeleton(); | ||
width: $grid-unit-60; | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
packages/js/product-editor/src/components/custom-fields/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,2 @@ | ||
export * from './custom-fields'; | ||
export * from './types'; |
Oops, something went wrong.
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.
I think that we can remove this.