-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
DataViews: Fix table view cell wrapper and BlockPreviews #58062
Conversation
Size Change: +17 B (0%) Total Size: 1.7 MB
ℹ️ View Unchanged
|
@@ -185,6 +185,10 @@ | |||
min-height: $grid-unit-40; | |||
display: flex; | |||
align-items: center; | |||
|
|||
> * { |
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.
@jameskoster I gave it a try to be able to render block previews with this, but I'm not 100% sure if it's the right solution.
In general the previews issue stems from useResizeObserver, where it seems it can determine a width if we have just the display:flex
. I'm not sure if @ciampo has any thoughts on this about whether it's something that should be handled by the hook.
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.
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.
Subject to Marco's feedback we can probably add a fixed height to the previews in table layout so they are consistent.
It already looks like we crop template previews to a max-height in the table view, so we could easily lower that number — although that means that if a template preview image is shorter than that image, that row will take less space.
If instead we want to enforce a fixed height, we could adopt the same technique employed for the Grid layout (basically the object-fit: cover
behavior).
In any case, this could be discussed / applied in a separate PR, since the goal of this PR is to fix the markup and make sure that the preview image appears correctly.
It would also be nice to apply the theme background color to the container to avoid these awkward gray spaces in grid layout
I hacked around and managed to achieve that with this code
diff --git a/packages/dataviews/src/view-grid.js b/packages/dataviews/src/view-grid.js
index c8cc3516e1..16d39dac3a 100644
--- a/packages/dataviews/src/view-grid.js
+++ b/packages/dataviews/src/view-grid.js
@@ -1,6 +1,7 @@
/**
* WordPress dependencies
*/
+import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
import {
__experimentalGrid as Grid,
__experimentalHStack as HStack,
@@ -13,6 +14,9 @@ import { useAsyncList } from '@wordpress/compose';
* Internal dependencies
*/
import ItemActions from './item-actions';
+import { unlock } from './lock-unlock';
+
+const { useGlobalStyle } = unlock( blockEditorPrivateApis );
export default function ViewGrid( {
data,
@@ -22,6 +26,8 @@ export default function ViewGrid( {
getItemId,
deferredRendering,
} ) {
+ const [ backgroundColor ] = useGlobalStyle( 'color.background' );
+
const mediaField = fields.find(
( field ) => field.id === view.layout.mediaField
);
@@ -50,7 +56,10 @@ export default function ViewGrid( {
key={ getItemId( item ) }
className="dataviews-view-grid__card"
>
- <div className="dataviews-view-grid__media">
+ <div
+ className="dataviews-view-grid__media"
+ style={ { backgroundColor } }
+ >
{ mediaField?.render( { item } ) }
</div>
<HStack
Although we should probably expose an API and apply a background color only when we are certain that the media that we are previewing would actually match that background color (like when managing templates).
This is also something that we should probably experiment with in a separate PR.
Finally, I wanted to flag that, when I pick the Grid layout and reload the page, the template preview images didn't load. In order to have them load correctly, I had to switch to the Table layout, and enable the preview field.
Flaky tests detected in af67ba2. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7622882064
|
df418f6
to
af67ba2
Compare
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 say we merge this PR as-is, as it includes some fixes. The rest can be addressed in follow-ups, as discussed in the inline comments
@@ -185,6 +185,10 @@ | |||
min-height: $grid-unit-40; | |||
display: flex; | |||
align-items: center; | |||
|
|||
> * { |
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.
Subject to Marco's feedback we can probably add a fixed height to the previews in table layout so they are consistent.
It already looks like we crop template previews to a max-height in the table view, so we could easily lower that number — although that means that if a template preview image is shorter than that image, that row will take less space.
If instead we want to enforce a fixed height, we could adopt the same technique employed for the Grid layout (basically the object-fit: cover
behavior).
In any case, this could be discussed / applied in a separate PR, since the goal of this PR is to fix the markup and make sure that the preview image appears correctly.
It would also be nice to apply the theme background color to the container to avoid these awkward gray spaces in grid layout
I hacked around and managed to achieve that with this code
diff --git a/packages/dataviews/src/view-grid.js b/packages/dataviews/src/view-grid.js
index c8cc3516e1..16d39dac3a 100644
--- a/packages/dataviews/src/view-grid.js
+++ b/packages/dataviews/src/view-grid.js
@@ -1,6 +1,7 @@
/**
* WordPress dependencies
*/
+import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
import {
__experimentalGrid as Grid,
__experimentalHStack as HStack,
@@ -13,6 +14,9 @@ import { useAsyncList } from '@wordpress/compose';
* Internal dependencies
*/
import ItemActions from './item-actions';
+import { unlock } from './lock-unlock';
+
+const { useGlobalStyle } = unlock( blockEditorPrivateApis );
export default function ViewGrid( {
data,
@@ -22,6 +26,8 @@ export default function ViewGrid( {
getItemId,
deferredRendering,
} ) {
+ const [ backgroundColor ] = useGlobalStyle( 'color.background' );
+
const mediaField = fields.find(
( field ) => field.id === view.layout.mediaField
);
@@ -50,7 +56,10 @@ export default function ViewGrid( {
key={ getItemId( item ) }
className="dataviews-view-grid__card"
>
- <div className="dataviews-view-grid__media">
+ <div
+ className="dataviews-view-grid__media"
+ style={ { backgroundColor } }
+ >
{ mediaField?.render( { item } ) }
</div>
<HStack
Although we should probably expose an API and apply a background color only when we are certain that the media that we are previewing would actually match that background color (like when managing templates).
This is also something that we should probably experiment with in a separate PR.
Finally, I wanted to flag that, when I pick the Grid layout and reload the page, the template preview images didn't load. In order to have them load correctly, I had to switch to the Table layout, and enable the preview field.
…zy-hydration * origin/trunk: (47 commits) Interactivity API: Break up long hydration task in interactivity init (#58227) Add supports.interactivity to Query block (#58316) Font Library: Make notices more consistent (#58180) Fix Global styles text settings bleeding into placeholder component (#58303) Fix the position and size of the Options menu, (#57515) DataViews: Fix safari grid row height issue (#58302) Try a fix (#58282) Navigation Submenu Block: Make block name affect list view (#58296) Apply custom scroll style to fixed header block toolbar (#57444) Add support for transform and letter spacing controls in Global Styles > Typography > Elements (#58142) DataViews: Fix table view cell wrapper and BlockPreviews (#58062) Workflows: Add 'Technical Prototype' to the type-related labels list (#58163) Block Editor: Optimize the 'useBlockDisplayTitle' hook (#58250) Remove noahtallen from .wp-env codeowners (#58283) Global styles revisions: fix is-selected rules from affecting other areas of the editor (#58228) Try: Disable text selection for post content placeholder block. (#58169) Remove `template-only` mode from editor and edit-post packages (#57700) Refactored download/upload logic to support font faces with multiple src assets (#58216) Components: Expand theming support in COLORS (#58097) Implementing new UX for invoking rich text Link UI (#57986) ...
* DataViews: Fix table view cell wrapper and BlockPreviews * try preserving flex
I just cherry-picked this PR to the release/17.6 branch to get it included in the next release: 4ab5e88 |
* DataViews: Fix table view cell wrapper and BlockPreviews * try preserving flex
What?
Follow up of: #57804
It was missed that we cannot have an inline element(span) as a wrapper because it creates invalid html.
Also, the addition of styling this as
display:flex
too, make the previews not render because of the width calculation. In this PR I'm removing this, but would love @jameskoster confirmation that doesn't affect something else..Testing instructions
preview
field and observe it's rendered properly.