-
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
Pattern Shuffling: Only use the category that the user selected to shuffle patterns #60088
Conversation
Size Change: -1.28 kB (0%) Total Size: 1.75 MB
ℹ️ View Unchanged
|
79690d9
to
25a33bd
Compare
@@ -772,7 +799,8 @@ export const blocks = pipe( | |||
withBlockReset, | |||
withPersistentBlockChange, | |||
withIgnoredBlockChange, | |||
withResetControlledBlocks | |||
withResetControlledBlocks, | |||
withPatternCategory |
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.
It seems like this is running before the attributes
function below, so the below function is overwriting the attribute changes we're making.
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.
How can it be fixed? Since this causes this PR to no do what it says on the tin :)
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 means we can't use a separate reducer, so I built it into the attributes reducer.
It's not 100% ideal to cycle among "featured" patterns, if inserted with the "featured" category. Should we omit that from being selected as a shuffle-able category as well? |
25a33bd
to
f1b4426
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'm still seeing the shuffling reference each category, not just the inserted-with category:
shuf.mp4
Rebased as well. |
f1b4426
to
9849ddb
Compare
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. |
*/ | ||
function addSelectedPatternCategoryToOuterBlock( { meta, blocks } ) { | ||
if ( meta?.category && blocks.length === 1 ) { | ||
blocks[ 0 ].attributes.metadata.categories = [ meta.category.name ]; |
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'm wondering if category
is too generic for the metadata. It's more about the "pattern category at point of insertion".
const newBlocks = | ||
addSelectedPatternCategoryToOuterBlock( action ); |
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.
This feels like it should be called conditionally.
Also it's feeling a little bit like a side effect in a reducer.
Are "Patterns" a concept in the block editor outside of the WordPress context? If not then should we be adding this to the block editor store?
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.
The original approach used a different reducer before this one, to try to keep the concerns separate. However this one addresses actions.block directly, so any changes we make to the blocks before this point are overridden by this one.
Closing in favour of #61557 |
What?
This uses the category the user selected as the basis for pattern shuffling - so if a pattern has more than one category, we only use the one that the user selected the category from instead of all the categories that the pattern is in.
Why?
It can be confusing when a category is in multiple categories, so this helps to keep the shuffling contained to the one category the user selected.
How?
We pass the category name into the reducer and add it to the block metadata.
Testing Instructions
team
category, not theabout
category.Screenshots or screencast