Skip to content

Commit

Permalink
DataViews: Fix nested buttons and placeholder text in list layout (#5…
Browse files Browse the repository at this point in the history
…8304)

* DataViews: Fix nested buttons and placeholder text in list layout

* Minor refactoring
  • Loading branch information
t-hamano authored Jan 29, 2024
1 parent 44df307 commit 8cbcc98
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 30 deletions.
42 changes: 24 additions & 18 deletions packages/edit-site/src/components/page-pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,31 +161,37 @@ function FeaturedImage( { item, viewType } ) {
canvas: 'edit',
} );
const hasMedia = !! item.featured_media;
const size =
viewType === LAYOUT_GRID
? [ 'large', 'full', 'medium', 'thumbnail' ]
: [ 'thumbnail', 'medium', 'large', 'full' ];

const media = hasMedia ? (
<Media
className="edit-site-page-pages__featured-image"
id={ item.featured_media }
size={ size }
/>
) : null;

return (
<span
className={ {
'edit-site-page-pages__media-wrapper':
viewType === LAYOUT_TABLE,
} }
>
<button
className="page-pages-preview-field__button"
type="button"
onClick={ onClick }
aria-label={ item.title?.rendered || __( '(no title)' ) }
>
{ hasMedia && (
<Media
className="edit-site-page-pages__featured-image"
id={ item.featured_media }
size={
viewType === LAYOUT_GRID
? [ 'large', 'full', 'medium', 'thumbnail' ]
: [ 'thumbnail', 'medium', 'large', 'full' ]
}
/>
) }
</button>
{ viewType === LAYOUT_LIST && media }
{ viewType !== LAYOUT_LIST && (
<button
className="page-pages-preview-field__button"
type="button"
onClick={ onClick }
aria-label={ item.title?.rendered || __( '(no title)' ) }
>
{ media }
</button>
) }
</span>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ function Preview( { item, viewType } ) {
postType: item.type,
canvas: 'edit',
} );

const isEmpty = ! blocks?.length;
// Wrap everything in a block editor provider to ensure 'styles' that are needed
// for the previews are synced between the site editor store and the block editor store.
Expand All @@ -165,18 +166,23 @@ function Preview( { item, viewType } ) {
className={ `page-templates-preview-field is-viewtype-${ viewType }` }
style={ { backgroundColor } }
>
<button
className="page-templates-preview-field__button"
type="button"
onClick={ onClick }
aria-label={ item.title?.rendered || item.title }
>
{ isEmpty &&
( item.type === TEMPLATE_POST_TYPE
? __( 'Empty template' )
: __( 'Empty template part' ) ) }
{ ! isEmpty && <BlockPreview blocks={ blocks } /> }
</button>
{ viewType === LAYOUT_LIST && ! isEmpty && (
<BlockPreview blocks={ blocks } />
) }
{ viewType !== LAYOUT_LIST && (
<button
className="page-templates-preview-field__button"
type="button"
onClick={ onClick }
aria-label={ item.title?.rendered || item.title }
>
{ isEmpty &&
( item.type === TEMPLATE_POST_TYPE
? __( 'Empty template' )
: __( 'Empty template part' ) ) }
{ ! isEmpty && <BlockPreview blocks={ blocks } /> }
</button>
) }
</div>
</ExperimentalBlockEditorProvider>
);
Expand Down

1 comment on commit 8cbcc98

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected in 8cbcc98.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7696899071
📝 Reported issues:

Please sign in to comment.