-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Patterns: Fix missing custom patterns in patterns explorer (#51889)
* Add custom patterns to pattern explorer * show custom patterns in the patterns explorer dialog * remove changes from 51877 * Fix up use of async lists * remove a bit of code duplication by adding a new hook * add 51877 fix back to make testing easier
- Loading branch information
1 parent
8d73990
commit 5695beb
Showing
3 changed files
with
68 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
packages/block-editor/src/components/inserter/hooks/use-unsynced-patterns.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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( | ||
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; | ||
} |