Skip to content

Commit

Permalink
update classNames + description docs for title fields
Browse files Browse the repository at this point in the history
  • Loading branch information
ntsekouras committed Dec 4, 2024
1 parent 9f2e401 commit e69c504
Show file tree
Hide file tree
Showing 15 changed files with 44 additions and 22 deletions.
8 changes: 4 additions & 4 deletions packages/fields/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Undocumented declaration.

### pageTitleField

Undocumented declaration.
Title for the page entity.

### parentField

Expand All @@ -93,7 +93,7 @@ This field is used to display the post password.

### patternTitleField

Undocumented declaration.
Title for the pattern entity.

### permanentlyDeletePost

Expand Down Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions packages/fields/src/fields/page-title/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@ const pageTitleField: Field< BasePost > = {
enableGlobalSearch: true,
};

/**
* Title for the page entity.
*/
export default pageTitleField;
2 changes: 1 addition & 1 deletion packages/fields/src/fields/page-title/style.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.fields-title-field__badge {
.fields-field-page-title__badge {
background: $gray-100;
color: $gray-800;
padding: 0 $grid-unit-05;
Expand Down
4 changes: 2 additions & 2 deletions packages/fields/src/fields/page-title/view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ export default function PageTitleView( { item }: { item: CommonPost } ) {
};
}, [] );
return (
<BaseTitleView item={ item }>
<BaseTitleView item={ item } className="fields-field-page-title">
{ [ frontPageId, postsPageId ].includes( item.id as number ) && (
<span className="fields-title-field__badge">
<span className="fields-field-page-title__badge">
{ item.id === frontPageId
? __( 'Homepage' )
: __( 'Posts Page' ) }
Expand Down
3 changes: 3 additions & 0 deletions packages/fields/src/fields/pattern-title/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@ const patternTitleField: Field< Pattern > = {
enableGlobalSearch: true,
};

/**
* Title for the pattern entity.
*/
export default patternTitleField;
2 changes: 1 addition & 1 deletion packages/fields/src/fields/pattern-title/style.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.fields-pattern-title-field span:first-child {
.fields-field-pattern-title span:first-child {
flex: 1;
}
8 changes: 2 additions & 6 deletions packages/fields/src/fields/pattern-title/view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,13 @@ export const { PATTERN_TYPES } = unlock( patternPrivateApis );

export default function PatternTitleView( { item }: { item: CommonPost } ) {
return (
<BaseTitleView item={ item } className="fields-pattern-title-field">
<BaseTitleView item={ item } className="fields-field-pattern-title">
{ item.type === PATTERN_TYPES.theme && (
<Tooltip
placement="top"
text={ __( 'This pattern cannot be edited.' ) }
>
<Icon
className="fields-title-field__pattern-lock-icon"
icon={ lockSmall }
size={ 24 }
/>
<Icon icon={ lockSmall } size={ 24 } />
</Tooltip>
) }
</BaseTitleView>
Expand Down
8 changes: 6 additions & 2 deletions packages/fields/src/fields/template-title/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
11 changes: 11 additions & 0 deletions packages/fields/src/fields/template-title/view.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Internal dependencies
*/
import type { Template } from '../../types';
import { BaseTitleView } from '../title/view';

export default function PageTitleView( { item }: { item: Template } ) {
return (
<BaseTitleView item={ item } className="fields-field-template-title" />
);
}
5 changes: 5 additions & 0 deletions packages/fields/src/fields/title/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
2 changes: 1 addition & 1 deletion packages/fields/src/fields/title/style.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.fields-title-field span:first-child {
.fields-field-title span:first-child {
text-overflow: ellipsis;
overflow: hidden;
text-decoration: none;
Expand Down
2 changes: 1 addition & 1 deletion packages/fields/src/fields/title/view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function BaseTitleView( {
const renderedTitle = getItemTitle( item );
return (
<HStack
className={ clsx( 'fields-title-field', className ) }
className={ clsx( 'fields-field-title', className ) }
alignment="center"
justify="flex-start"
>
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/specs/site-editor/browser-history.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/specs/site-editor/new-templates-list.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/specs/site-editor/template-registration.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit e69c504

Please sign in to comment.