Skip to content

Commit

Permalink
Product Collection: Make sure all variations are taken into account w…
Browse files Browse the repository at this point in the history
…hen choosing collection (#43273)

* Make sure all variations are taken into account when choosing collection

* Add changelog
  • Loading branch information
kmanijak committed Jan 8, 2024
1 parent aab950e commit 8d4f1ce
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
/**
* External dependencies
*/
import { select } from '@wordpress/data';
import {
// @ts-expect-error Type definition is missing
store as blocksStore,
type BlockVariation,
registerBlockVariation,
BlockAttributes,
Expand Down Expand Up @@ -49,7 +52,15 @@ export const getCollectionByName = ( collectionName?: CollectionName ) => {
return null;
}

return collections.find( ( { name } ) => name === collectionName );
// @ts-expect-error Type definitions are missing
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/wordpress__blocks/store/selectors.d.ts
const variations = select( blocksStore ).getBlockVariations(
blockJson.name
);

// @ts-expect-error Type definitions are missing
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/wordpress__blocks/store/selectors.d.ts
return variations.find( ( { name } ) => name === collectionName );
};

export default registerCollections;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: enhancement

Make sure all variations of Product Collection are taken into account when choosing collection by name

0 comments on commit 8d4f1ce

Please sign in to comment.