-
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
Block Quick Inserter: Prioritize showing patterns instead of blocks. #38709
Block Quick Inserter: Prioritize showing patterns instead of blocks. #38709
Conversation
Size Change: +762 B (0%) Total Size: 1.15 MB
ℹ️ View Unchanged
|
This is very cool, thanks for taking a stab! Here's a GIF showing the root level sibling inserter defaulting to patterns: Already here this feels excellent. Of note, I appreciate that you can still search for a block if that's what you want: One of the concerns discussed in 36697 is whether it feels confusing when the inserter shows two filtered views depending on where you click. But in testing this in practice, it feels reasonably intuitive, enough that we might want to land it so we can benefit patterns more. We should probably not close 36697 with this PR, though, as it might be worth it to still explore the exploded view proposed, which is a larger effort. |
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.
Works as advertised.
About the feeling of using this, I'm not sure whether it's good or bad :) I guess time will tell.
maxBlockTypes={ SHOWN_BLOCK_TYPES } | ||
isDraggable={ false } | ||
__experimentalPrioritizePatterns={ prioritizePatterns } |
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 this one is an internal component so there's no need for "experimental"
__experimentalPrioritizePatterns && | ||
filteredBlockPatterns.length > 2 | ||
) { | ||
maxBlockTypesToShow = 0; |
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.
Nit: For both filteredPatterns and filteredBlocks, we could bail early if the max is 0 (for perf reasons but really not sure whether it has any impact)
@@ -98,6 +98,8 @@ export const getSettings = createSelector( | |||
hasFixedToolbar: isFeatureActive( state, 'fixedToolbar' ), | |||
__experimentalSetIsInserterOpened: setIsInserterOpen, | |||
__experimentalReusableBlocks: getReusableBlocks( state ), | |||
__experimentalPrioritizePatternsOnQuickInserterRoot: |
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.
Nit: I'd be filter for this to be stable preferPatternsOnRoot
or something but I'm ok if you think we should start experimental.
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 used the name you suggested "preferPatternsOnRoot" but kept the setting as experimental. We are not yet confident about the future of this change we may in the future have a more general flag that changes more things.
I agree with this, it was always showing footer patterns for me which is not great. |
prioritizePatterns: | ||
settings.__experimentalPrioritizePatternsOnQuickInserterRoot && | ||
! rootClientId && | ||
index > 0 && |
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.
What about these positions? If I create a new empty template I should see patterns in the inserter, no? Same goes for the last index if it's top level.
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.
Hi @ntsekouras,
The conditions are following what @mtias specified on the issue:
The top-level means it's a direct descendant of the document, between any root template parts or existing blocks
I added a condition to also show the behavior when the template is empty.
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.
Yes, we'll need to do some extra work on empty templates regardless.
Hi @jasmussen, @youknowriad, @ntsekouras thank you for the reviews. |
…e root of templates
dd63911
to
460be3c
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.
Thanks @jorgefilipecosta!
Personally I find it a bit difficult to follow parts of the flow with some reassigned values like maxBlockTypes
becomes maxBlockTypesToShow
etc.., but I'm not sure how we can avoid this easily, since we do want the filtered results to make some decisions..
Having said that, this works as described and we can give it a try and see the feedback!
const showPatterns = | ||
patterns.length && ( !! filterValue || prioritizePatterns ); | ||
const showSearch = | ||
( showPatterns && patterns.length > SEARCH_THRESHOLD ) || |
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.
Edge case here in the case of prioritizing patterns where the SEARCH_THRESHOLD
is more than SHOWN_BLOCK_PATTERNS_WITH_PRIORITIZATION
, in combination of course with only a few allowed blocks. I think it will be a super rare use case if it ever occurs, but just noting.
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.
Hi @ntsekouras, I think here SHOWN_BLOCK_PATTERNS_WITH_PRIORITIZATION is not relevant, patterns.length contains the full number of patterns e.g: if we have 34 patterns and SHOWN_BLOCK_PATTERNS_WITH_PRIORITIZATION is 2 and SEARCH_THRESHOLD is 3 we are going to show search anyway as expected because we have 34 patterns.
Let me know if I am not understanding correctly the issue.
Thank you all for the reviews :) |
Hey @jorgefilipecosta @jasmussen and @youknowriad It would be great to take a similar approach to adding inner blocks to for instance the Query Loop block and other blocks where one can add inner blocks. (Would also be very helpful for WooCommerce.) (Paraphrashing/transfering the approach to block where one can add inner blocks.)
Making inner blocks easier to locate. |
Fixes: #36697
This PR follows the design proposed in #36697:
And prioritizes patterns on the quick inserter when all the following conditions match:
By default we have four patterns following the order the server provided them. We don't have any sorting mechanism like last used time, heuristics of the place of insertion, etc, the type of template, etc. As a follow-up, we need to have a mechanism for sorting patterns so what we show is more relevant.
We allow searching for patterns or blocks if we have 3 or more patterns to show we show only patterns if we have 2 or less patterns we show patterns and blocks (patterns being at the top). This allows the user to search for a paragraph block and insert it using the quick inserter if the user wants two (provided there are no 3 or more patterns containing "paragraph" in the name).
Testing
I verified the patterns are prioritized on the inserter on post editor and site editor when the condition are met.