diff --git a/packages/fields/README.md b/packages/fields/README.md index a2428084f4dec1..ac7a26e499374a 100644 --- a/packages/fields/README.md +++ b/packages/fields/README.md @@ -81,7 +81,7 @@ Undocumented declaration. ### pageTitleField -Undocumented declaration. +Title for the page entity. ### parentField @@ -93,7 +93,7 @@ This field is used to display the post password. ### patternTitleField -Undocumented declaration. +Title for the pattern entity. ### permanentlyDeletePost @@ -137,11 +137,11 @@ Undocumented declaration. ### templateTitleField -Undocumented declaration. +Title for the template entity. ### titleField -Undocumented declaration. +Title for the any entity with a `title` property. For patterns, pages or templates you should use the respective field because there are some differences in the rendering, labels, etc. ### trashPost diff --git a/packages/fields/src/fields/page-title/index.ts b/packages/fields/src/fields/page-title/index.ts index 533eb8f591dc07..8bbf051f2b5839 100644 --- a/packages/fields/src/fields/page-title/index.ts +++ b/packages/fields/src/fields/page-title/index.ts @@ -22,4 +22,7 @@ const pageTitleField: Field< BasePost > = { enableGlobalSearch: true, }; +/** + * Title for the page entity. + */ export default pageTitleField; diff --git a/packages/fields/src/fields/page-title/style.scss b/packages/fields/src/fields/page-title/style.scss index 5ccb2ccaf9bf35..e22c2c1b1187e7 100644 --- a/packages/fields/src/fields/page-title/style.scss +++ b/packages/fields/src/fields/page-title/style.scss @@ -1,4 +1,4 @@ -.fields-title-field__badge { +.fields-field-page-title__badge { background: $gray-100; color: $gray-800; padding: 0 $grid-unit-05; diff --git a/packages/fields/src/fields/page-title/view.tsx b/packages/fields/src/fields/page-title/view.tsx index ea517feaf00377..383f7976c9cccc 100644 --- a/packages/fields/src/fields/page-title/view.tsx +++ b/packages/fields/src/fields/page-title/view.tsx @@ -25,9 +25,9 @@ export default function PageTitleView( { item }: { item: CommonPost } ) { }; }, [] ); return ( - + { [ frontPageId, postsPageId ].includes( item.id as number ) && ( - + { item.id === frontPageId ? __( 'Homepage' ) : __( 'Posts Page' ) } diff --git a/packages/fields/src/fields/pattern-title/index.ts b/packages/fields/src/fields/pattern-title/index.ts index ba8e4e2cab590d..a3e54eea6f28d1 100644 --- a/packages/fields/src/fields/pattern-title/index.ts +++ b/packages/fields/src/fields/pattern-title/index.ts @@ -22,4 +22,7 @@ const patternTitleField: Field< Pattern > = { enableGlobalSearch: true, }; +/** + * Title for the pattern entity. + */ export default patternTitleField; diff --git a/packages/fields/src/fields/pattern-title/style.scss b/packages/fields/src/fields/pattern-title/style.scss index e5d37160d28ff7..5f1e19ca694454 100644 --- a/packages/fields/src/fields/pattern-title/style.scss +++ b/packages/fields/src/fields/pattern-title/style.scss @@ -1,3 +1,3 @@ -.fields-pattern-title-field span:first-child { +.fields-field-pattern-title span:first-child { flex: 1; } diff --git a/packages/fields/src/fields/pattern-title/view.tsx b/packages/fields/src/fields/pattern-title/view.tsx index 4a8f074e8cbe95..6ffd622e02d7ec 100644 --- a/packages/fields/src/fields/pattern-title/view.tsx +++ b/packages/fields/src/fields/pattern-title/view.tsx @@ -18,17 +18,13 @@ export const { PATTERN_TYPES } = unlock( patternPrivateApis ); export default function PatternTitleView( { item }: { item: CommonPost } ) { return ( - + { item.type === PATTERN_TYPES.theme && ( - + ) } diff --git a/packages/fields/src/fields/template-title/index.ts b/packages/fields/src/fields/template-title/index.ts index 1854c64b49985f..738082b6ebb210 100644 --- a/packages/fields/src/fields/template-title/index.ts +++ b/packages/fields/src/fields/template-title/index.ts @@ -9,16 +9,20 @@ import { __ } from '@wordpress/i18n'; */ import type { Template } from '../../types'; import { getItemTitle } from '../../actions/utils'; -import TitleView from '../title/view'; +import PageTitleView from './view'; const templateTitleField: Field< Template > = { type: 'text', label: __( 'Template' ), + placeholder: __( 'No title' ), id: 'title', getValue: ( { item } ) => getItemTitle( item ), - render: TitleView, + render: PageTitleView, enableHiding: false, enableGlobalSearch: true, }; +/** + * Title for the template entity. + */ export default templateTitleField; diff --git a/packages/fields/src/fields/template-title/view.tsx b/packages/fields/src/fields/template-title/view.tsx new file mode 100644 index 00000000000000..140d4438022f0d --- /dev/null +++ b/packages/fields/src/fields/template-title/view.tsx @@ -0,0 +1,11 @@ +/** + * Internal dependencies + */ +import type { Template } from '../../types'; +import { BaseTitleView } from '../title/view'; + +export default function PageTitleView( { item }: { item: Template } ) { + return ( + + ); +} diff --git a/packages/fields/src/fields/title/index.ts b/packages/fields/src/fields/title/index.ts index 5295f507dce6a0..b4a2399526fdd9 100644 --- a/packages/fields/src/fields/title/index.ts +++ b/packages/fields/src/fields/title/index.ts @@ -22,4 +22,9 @@ const titleField: Field< CommonPost > = { enableGlobalSearch: true, }; +/** + * Title for the any entity with a `title` property. + * For patterns, pages or templates you should use the respective field + * because there are some differences in the rendering, labels, etc. + */ export default titleField; diff --git a/packages/fields/src/fields/title/style.scss b/packages/fields/src/fields/title/style.scss index 764637b190ff65..a8ac7169b36c80 100644 --- a/packages/fields/src/fields/title/style.scss +++ b/packages/fields/src/fields/title/style.scss @@ -1,4 +1,4 @@ -.fields-title-field span:first-child { +.fields-field-title span:first-child { text-overflow: ellipsis; overflow: hidden; text-decoration: none; diff --git a/packages/fields/src/fields/title/view.tsx b/packages/fields/src/fields/title/view.tsx index 7bb60eda50fa8c..0462ccc6a7ec07 100644 --- a/packages/fields/src/fields/title/view.tsx +++ b/packages/fields/src/fields/title/view.tsx @@ -28,7 +28,7 @@ export function BaseTitleView( { const renderedTitle = getItemTitle( item ); return ( diff --git a/test/e2e/specs/site-editor/browser-history.spec.js b/test/e2e/specs/site-editor/browser-history.spec.js index b70674a7605ac3..d2ffc256759ea0 100644 --- a/test/e2e/specs/site-editor/browser-history.spec.js +++ b/test/e2e/specs/site-editor/browser-history.spec.js @@ -20,7 +20,7 @@ test.describe( 'Site editor browser history', () => { // Navigate to a single template await page.click( 'role=button[name="Templates"]' ); await page - .locator( '.fields-title-field', { hasText: 'Index' } ) + .locator( '.fields-field-title', { hasText: 'Index' } ) .click(); await expect( page ).toHaveURL( '/wp-admin/site-editor.php?p=%2Fwp_template%2Femptytheme%2F%2Findex&canvas=edit' diff --git a/test/e2e/specs/site-editor/new-templates-list.spec.js b/test/e2e/specs/site-editor/new-templates-list.spec.js index cca8847a2333c5..d08684b3f4efe5 100644 --- a/test/e2e/specs/site-editor/new-templates-list.spec.js +++ b/test/e2e/specs/site-editor/new-templates-list.spec.js @@ -27,7 +27,7 @@ test.describe( 'Templates', () => { page.locator( '[aria-label="Templates"]' ) ).toBeVisible(); - const firstTitle = page.locator( '.fields-title-field' ).first(); + const firstTitle = page.locator( '.fields-field-title' ).first(); // Descending by title. await page.getByRole( 'button', { name: 'View options' } ).click(); @@ -48,7 +48,7 @@ test.describe( 'Templates', () => { await admin.visitSiteEditor( { postType: 'wp_template' } ); // Global search. await page.getByRole( 'searchbox', { name: 'Search' } ).fill( 'tag' ); - const titles = page.locator( '.fields-title-field' ); + const titles = page.locator( '.fields-field-title' ); await expect( titles ).toHaveCount( 1 ); await expect( titles.first() ).toHaveText( 'Tag Archives' ); await page diff --git a/test/e2e/specs/site-editor/template-registration.spec.js b/test/e2e/specs/site-editor/template-registration.spec.js index 91eabb72801bb4..a3a9a0b6813b55 100644 --- a/test/e2e/specs/site-editor/template-registration.spec.js +++ b/test/e2e/specs/site-editor/template-registration.spec.js @@ -320,7 +320,7 @@ test.describe( 'Block template registration', () => { .getByText( `"Author: Admin" reset.` ); await page.getByPlaceholder( 'Search' ).fill( 'Author: admin' ); await page - .locator( '.fields-title-field', { hasText: 'Author: Admin' } ) + .locator( '.fields-field-title', { hasText: 'Author: Admin' } ) .click(); const actions = page.getByLabel( 'Actions' ); await actions.first().click();