Skip to content
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

Patterns: revert usePatternsState to return an array instead of object #54582

Merged
merged 1 commit into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function PatternList( {
const [ destinationRootClientId, onInsertBlocks ] = useInsertionPoint( {
shouldFocusBlock: true,
} );
const { patterns: allPatterns, onClickPattern } = usePatternsState(
const [ patterns, , onClickPattern ] = usePatternsState(
onInsertBlocks,
destinationRootClientId
);
Expand All @@ -88,7 +88,7 @@ function PatternList( {
);

const filteredBlockPatterns = useMemo( () => {
const filteredPatterns = allPatterns.filter( ( pattern ) => {
const filteredPatterns = patterns.filter( ( pattern ) => {
if (
isPatternFiltered(
pattern,
Expand Down Expand Up @@ -127,7 +127,7 @@ function PatternList( {
}, [
searchValue,
patternSourceFilter,
allPatterns,
patterns,
selectedCategory,
registeredPatternCategories,
patternSyncFilter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,20 @@ export function isPatternFiltered( pattern, sourceFilter, syncFilter ) {
}

export function usePatternsCategories( rootClientId, sourceFilter = 'all' ) {
const { patterns: allPatterns, allCategories } = usePatternsState(
const [ patterns, allCategories ] = usePatternsState(
undefined,
rootClientId
);

const filteredPatterns = useMemo(
() =>
sourceFilter === 'all'
? allPatterns
: allPatterns.filter(
? patterns
: patterns.filter(
( pattern ) =>
! isPatternFiltered( pattern, sourceFilter )
),
[ sourceFilter, allPatterns ]
[ sourceFilter, patterns ]
);

const hasRegisteredCategory = useCallback(
Expand Down Expand Up @@ -192,7 +192,7 @@ export function BlockPatternsCategoryPanel( {
showTitlesAsTooltip,
patternFilter,
} ) {
const { patterns: allPatterns, onClickPattern } = usePatternsState(
const [ allPatterns, , onClickPattern ] = usePatternsState(
onInsert,
rootClientId
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const usePatternsState = ( onInsert, rootClientId ) => {
[ createSuccessNotice, onInsert ]
);

return { patterns, allCategories, onClickPattern };
return [ patterns, allCategories, onClickPattern ];
};

export default usePatternsState;
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default function QuickInserter( {
onInsertBlocks
);

const { patterns } = usePatternsState(
const [ patterns ] = usePatternsState(
onInsertBlocks,
destinationRootClientId
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function InserterSearchResults( {
blockTypeCollections,
onSelectBlockType,
] = useBlockTypesState( destinationRootClientId, onInsertBlocks );
const { patterns, onClickPattern } = usePatternsState(
const [ patterns, , onClickPattern ] = usePatternsState(
onInsertBlocks,
destinationRootClientId
);
Expand Down
Loading