Skip to content
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

Quick Edit: add Template field #66591

Merged
merged 50 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
da0b766
Add DataFormProvider for fields
louwie17 Oct 4, 2024
538ef3e
Add dataform layout component and inline layout
louwie17 Oct 28, 2024
9cb2b26
Fix label in panel view
louwie17 Oct 28, 2024
c641723
Remove unneeded line
louwie17 Oct 28, 2024
a707275
Update `field` to FormField as well
louwie17 Oct 28, 2024
111e9f1
Merge branch 'update/dataform_combined_fields_api' of github.com:Word…
gigitux Oct 29, 2024
93b8e53
QuickEdit: implement Template field
gigitux Oct 30, 2024
9806534
Merge branch 'trunk' of github.com:WordPress/gutenberg into add/templ…
gigitux Oct 30, 2024
ca3b59b
improve style
gigitux Oct 30, 2024
61f9655
implement logic to reset to default template
gigitux Oct 30, 2024
5a623fb
ensure that setting object is defined
gigitux Oct 30, 2024
f9b1eef
Add DataFormProvider for fields
louwie17 Oct 4, 2024
db4cbd6
Add dataform layout component and inline layout
louwie17 Oct 28, 2024
2d7ee1b
Fix label in panel view
louwie17 Oct 28, 2024
2ba1ffb
Remove unneeded line
louwie17 Oct 28, 2024
4384814
Update `field` to FormField as well
louwie17 Oct 28, 2024
8e4b0ef
Remove combinedFields usage
louwie17 Oct 31, 2024
152c875
Remove old use of View
louwie17 Oct 31, 2024
7cfb87d
Add label and move field type check to 'getFieldDefinition'
louwie17 Oct 31, 2024
a3768d8
Create types of each view
louwie17 Oct 31, 2024
3e5a584
Add sticky example
louwie17 Oct 31, 2024
58150ef
Update combined fields story
louwie17 Oct 31, 2024
b523f7f
Merge branch 'update/dataform_combined_fields_api' of github.com:Word…
gigitux Oct 31, 2024
8698f0f
Add DataFormProvider for fields
louwie17 Oct 4, 2024
6a0598d
Add dataform layout component and inline layout
louwie17 Oct 28, 2024
bbae788
Fix label in panel view
louwie17 Oct 28, 2024
e17c228
Remove unneeded line
louwie17 Oct 28, 2024
05d7506
Update `field` to FormField as well
louwie17 Oct 28, 2024
15b0f11
Remove combinedFields usage
louwie17 Oct 31, 2024
a8d2462
Remove old use of View
louwie17 Oct 31, 2024
5967797
Add label and move field type check to 'getFieldDefinition'
louwie17 Oct 31, 2024
7eac0ab
Create types of each view
louwie17 Oct 31, 2024
a8f9e82
Add sticky example
louwie17 Oct 31, 2024
f9e86cb
Update combined fields story
louwie17 Oct 31, 2024
b05dbef
Fix change I missed during rebase
louwie17 Oct 31, 2024
8c15a9b
Remove old status_and_visibility field
louwie17 Nov 4, 2024
8ea852c
Rename fields to children for clarity
louwie17 Nov 4, 2024
0c67f64
Add children support to regular layout
louwie17 Nov 4, 2024
4cd314b
Replace inline with labelPosition
louwie17 Nov 5, 2024
ddf996a
Remove field type checking within dataform layouts
louwie17 Nov 5, 2024
f31a91c
Merge branch 'update/dataform_combined_fields_api' of github.com:Word…
gigitux Nov 6, 2024
9021f79
Merge branch 'trunk' of github.com:WordPress/gutenberg into add/templ…
gigitux Nov 25, 2024
d698e14
fix template field registration
gigitux Nov 25, 2024
69396c0
restore not necessary changes
gigitux Nov 25, 2024
7864b00
Merge branch 'trunk' of github.com:WordPress/gutenberg into add/templ…
gigitux Dec 2, 2024
704ebe5
wrap DataForm component
gigitux Dec 2, 2024
7cf2843
not use hook
gigitux Dec 2, 2024
cbb8bda
improve dependency
gigitux Dec 3, 2024
f891475
improve code style
gigitux Dec 3, 2024
32e1b31
add issue
gigitux Dec 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/base-styles/_z-index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ $z-layers: (
".editor-action-modal": 1000001,
".editor-post-template__swap-template-modal": 1000001,
".edit-site-template-panel__replace-template-modal": 1000001,
".fields-controls__template-modal": 1000001,

// Note: The ConfirmDialog component's z-index is being set to 1000001 in packages/components/src/confirm-dialog/styles.ts
// because it uses emotion and not sass. We need it to render on top its parent popover.
Expand Down
39 changes: 28 additions & 11 deletions packages/edit-site/src/components/post-edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import { privateApis as editorPrivateApis } from '@wordpress/editor';
*/
import Page from '../page';
import { unlock } from '../../lock-unlock';
import usePatternSettings from '../page-patterns/use-pattern-settings';
import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';

const { PostCardPanel, usePostFields } = unlock( editorPrivateApis );

Expand Down Expand Up @@ -85,6 +87,12 @@ function PostEditForm( { postType, postId } ) {
'slug',
'parent',
'comment_status',
{
label: __( 'Template' ),
labelPosition: 'side',
id: 'template',
layout: 'regular',
},
].filter(
( field ) =>
ids.length === 1 ||
Expand Down Expand Up @@ -139,17 +147,26 @@ function PostEditForm( { postType, postId } ) {
}

export function PostEdit( { postType, postId } ) {
const { ExperimentalBlockEditorProvider } = unlock(
blockEditorPrivateApis
);
const settings = usePatternSettings();
// Wrap everything in a block editor provider.
// This ensures 'styles' that are needed for the previews are synced
// from the site editor store to the block editor store.
return (
<Page
className={ clsx( 'edit-site-post-edit', {
'is-empty': ! postId,
} ) }
label={ __( 'Post Edit' ) }
>
{ postId && (
<PostEditForm postType={ postType } postId={ postId } />
) }
{ ! postId && <p>{ __( 'Select a page to edit' ) }</p> }
</Page>
<ExperimentalBlockEditorProvider settings={ settings }>
youknowriad marked this conversation as resolved.
Show resolved Hide resolved
<Page
className={ clsx( 'edit-site-post-edit', {
'is-empty': ! postId,
} ) }
label={ __( 'Post Edit' ) }
>
{ postId && (
<PostEditForm postType={ postType } postId={ postId } />
) }
{ ! postId && <p>{ __( 'Select a page to edit' ) }</p> }
</Page>
</ExperimentalBlockEditorProvider>
);
}
2 changes: 2 additions & 0 deletions packages/editor/src/dataviews/store/private-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
statusField,
authorField,
titleField,
templateField,
} from '@wordpress/fields';
import duplicateTemplatePart from '../actions/duplicate-template-part';

Expand Down Expand Up @@ -169,6 +170,7 @@ export const registerPostTypeSchema =
parentField,
commentStatusField,
passwordField,
templateField,
];

registry.batch( () => {
Expand Down
4 changes: 4 additions & 0 deletions packages/fields/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ Undocumented declaration.

Status field for BasePost.

### templateField

Undocumented declaration.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should aim to document every export. It's quite discouraging to look at docs that say "Undocumented declaration".


### titleField

Undocumented declaration.
Expand Down
1 change: 1 addition & 0 deletions packages/fields/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@babel/runtime": "7.25.7",
"@wordpress/api-fetch": "*",
"@wordpress/blob": "*",
"@wordpress/block-editor": "*",
"@wordpress/blocks": "*",
"@wordpress/components": "*",
"@wordpress/compose": "*",
Expand Down
4 changes: 3 additions & 1 deletion packages/fields/src/actions/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ export function isTemplateOrTemplatePart(
return p.type === TEMPLATE_POST_TYPE || p.type === TEMPLATE_PART_POST_TYPE;
}

export function getItemTitle( item: Post ) {
export function getItemTitle( item: {
title: string | { rendered: string } | { raw: string };
} ) {
if ( typeof item.title === 'string' ) {
return decodeEntities( item.title );
}
Expand Down
1 change: 1 addition & 0 deletions packages/fields/src/fields/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export { default as slugField } from './slug';
export { default as titleField } from './title';
export { default as orderField } from './order';
export { default as featuredImageField } from './featured-image';
export { default as templateField } from './template';
export { default as parentField } from './parent';
export { default as passwordField } from './password';
export { default as statusField } from './status';
Expand Down
22 changes: 22 additions & 0 deletions packages/fields/src/fields/template/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* WordPress dependencies
*/
import type { Field } from '@wordpress/dataviews';

/**
* Internal dependencies
*/
import { __ } from '@wordpress/i18n';
import type { BasePost } from '../../types';
import { TemplateEdit } from './template-edit';

const templateField: Field< BasePost > = {
id: 'template',
type: 'text',
label: __( 'Template' ),
getValue: ( { item } ) => item.template,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to provide a getValue function here given id is template.

Edit: TemplateEdit,
enableSorting: false,
};

export default templateField;
23 changes: 23 additions & 0 deletions packages/fields/src/fields/template/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.fields-controls__template-modal {
z-index: z-index(".fields-controls__template-modal");
}

.fields-controls__template-content .block-editor-block-patterns-list {
column-count: 2;
column-gap: $grid-unit-30;

// Small top padding required to avoid cutting off the visible outline when hovering items
padding-top: $border-width-focus-fallback;

@include break-medium() {
column-count: 3;
}

@include break-wide() {
column-count: 4;
}

.block-editor-block-patterns-list__list-item {
break-inside: avoid-column;
}
}
Loading
Loading