-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Patterns: fix error with react list key with new custom patterns list in inserter #51877
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
Changes from all commits
b5ab3ff
1ff9a39
8d73990
5695beb
87a8812
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 |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { useMemo } from '@wordpress/element'; | ||
| import { parse } from '@wordpress/blocks'; | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import useBlockTypesState from '../hooks/use-block-types-state'; | ||
|
|
||
| export default function useUnsyncedPatterns( | ||
| rootClientId, | ||
| onInsert, | ||
| withBlocks | ||
| ) { | ||
| const [ unsyncedPatterns ] = useBlockTypesState( | ||
|
Contributor
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. Isn't it a bit weird, to have
Contributor
Author
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 makes sense, but is a reasonable refactor, so have done it as a separate PR here. |
||
| rootClientId, | ||
| onInsert, | ||
| 'unsynced' | ||
| ); | ||
| const filteredUnsyncedPatterns = useMemo( () => { | ||
| return unsyncedPatterns | ||
| .filter( | ||
| ( { category: unsyncedPatternCategory } ) => | ||
| unsyncedPatternCategory === 'reusable' | ||
| ) | ||
| .map( ( syncedPattern ) => ( { | ||
| ...syncedPattern, | ||
| blocks: withBlocks | ||
| ? parse( syncedPattern.content, { | ||
| __unstableSkipMigrationLogs: true, | ||
| } ) | ||
| : undefined, | ||
| } ) ); | ||
| }, [ unsyncedPatterns, withBlocks ] ); | ||
| return filteredUnsyncedPatterns; | ||
| } | ||
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 component is
BlockPatternsListis supposed to render patterns and patterns are expected to have unique names, so I think a better fix would be on the "caller" of this component, in the place where we transform "reusable blocks" to "patterns".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 guessing that means
useUnsyncedPatternsThere 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 included this change in this alternative PR