-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Add content schema to pattern editing view #59977
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Size Change: +191 B (0%) Total Size: 1.72 MB
ℹ️ View Unchanged
|
const allClientIds = useSelect( | ||
( select ) => | ||
unlock( select( blockEditorStore ) ).getClientIdsWithDescendants(), | ||
[] | ||
); |
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 think getClientIdsWithDescendants
is a public selector, so unlocking it is unnecessary.
You can also use a filter inside the mapSelect
if you just return clientId strings. While it's against general policy to avoid filter/map/etc
iteration inside selectors. I think it's a useful "trick". Here's a similar example for the locked block.
Note to self: it might be helpful to include comments for similar "tricks" explaining why this usage is okay.
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 think getClientIdsWithDescendants is a public selector, so unlocking it is unnecessary.
Thanks, not sure why I did that 😄
You can also use a filter inside the mapSelect if you just return clientId strings. While it's against general policy to avoid filter/map/etc iteration inside selectors. I think it's a useful "trick". Here's a similar example for the locked block.
Interesting. Could you explain more about how that works without causing a performance hit?
In my testing it seems like it would cause a performance problem because useSelect
runs so regularly even when it's returning the same value.
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.
That's true; the mapSelect
will run whenever the store updates. To be honest, I've not measured performance hits for similar patterns. Though it should be fine for simple filter operations.
I trust to your judgment here :)
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.
LGTM 👍. I agree there might be chances where we can add some descriptive text or CTA though.
Could we rename the sidebar from "Content" to "Overrides" or something specific to patterns? Right now, having it fully mimic the content only editing experience is throwing me a bit and having the UI be a bit more specific to this experience might help. |
I'd be fine with using the 'Overrides" label instead of Content for now. |
5c5d54a
to
c0c23fd
Compare
I've been testing this, I like how it feels. One unrelated thing that could be worth adding when we're in the pattern editor, is an "info" message on the modal to rename a block for blocks. |
@youknowriad Yep, I think that's being covered by a separate issue (#59813), and @kevin940726 has worked on some options. |
Sorry folks, I forgot to add co-authors to the commit message. |
* Add new quick navigation component for pattern schema * Implement panel and fix minor issues * Rename to pattern content, and avoid showing panel when there are no blocks * Don't try to unlock what's already unlocked, just turn the handle. * Rename content panel title from 'Content' to 'Overrides' * Rename component to `OverridesPanel`
What?
Closes #59815
Adds a new 'content' panel when editing patterns. When a user names a block to declare it as overridable, that block will now display in the panel.
Questions:
How?
ContentPanel
component in thepatterns
package, with the various UI piecesPatternContentPanel
component in theeditor
package, which determines when the panel should be shown (whether awp_block
is being edited)isOverridableBlock
function to the patterns package, which acts as the source of truth for whether a block has overrides (which is important as this will likely be changing with Use metadata.name only as the hint for pattern overrides)Testing Instructions
Screenshots or screencast
Kapture.2024-03-19.at.12.46.29.mp4