-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -755,6 +755,22 @@ const withResetControlledBlocks = ( reducer ) => ( state, action ) => { | |
return reducer( state, action ); | ||
}; | ||
|
||
/** | ||
* Adds the selected pattern category to the outer block. | ||
* | ||
* @param {Object} action Dispatched action. | ||
* @param {Object} action.meta The meta object from the action. | ||
* @param {Array} action.blocks The array of blocks to insert. | ||
* | ||
* @return {Array} The blocks array. | ||
*/ | ||
function addSelectedPatternCategoryToOuterBlock( { meta, blocks } ) { | ||
if ( meta?.category && blocks.length === 1 ) { | ||
blocks[ 0 ].attributes.metadata.categories = [ meta.category.name ]; | ||
} | ||
return blocks; | ||
} | ||
|
||
/** | ||
* Reducer returning the blocks state. | ||
* | ||
|
@@ -847,7 +863,12 @@ export const blocks = pipe( | |
case 'RECEIVE_BLOCKS': | ||
case 'INSERT_BLOCKS': { | ||
const newState = new Map( state ); | ||
getFlattenedBlockAttributes( action.blocks ).forEach( | ||
|
||
// Adds the selected pattern category to the outer block. | ||
const newBlocks = | ||
addSelectedPatternCategoryToOuterBlock( action ); | ||
Comment on lines
+868
to
+869
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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. |
||
|
||
getFlattenedBlockAttributes( newBlocks ).forEach( | ||
( [ key, value ] ) => { | ||
newState.set( key, 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.
I'm wondering if
category
is too generic for the metadata. It's more about the "pattern category at point of insertion".