-
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.
feat: Inserter displays block collections (#42405)
* feat: Inserter display block collections Collections of blocks regsitered via `registerBlockCollection` now appear at the end of the block inserter enabling additional organization of blocks. * test: Add test for createInserterSection utility * fix: Update reusable blocks list data structure The `BlockTypesList` now expects `sections` to support the `SectionList` used within it for displaying block collections. Prior to this change, an error was thrown. * test: Fix failure by expanding selector mock The `BlockTypesTab` now relies upon additional store selectors. The lack of mocks for these selectors caused test failures. * docs: Add changelog entry * refactor: Simplify and mirror web implementation The code contained redundant selectors against the store for the block type list. This change refactors the native inserter to match the web counterpart, utilizing the selector leveraged by the web. * refactor: Remove unnecessary object spread While verbose, passing explicit props is likely more orthodox and straightforward to interpret. * fix: Remove broken keyExtractor The key for this component's sections is now `key`, not `id`, which resulted in undefined key values returned here. However, the default `keyExtractor` already searches for `key` and then `id`, so this can be safely removed. * fix: Revert utilization of onSelect from useBlockTypesState The block created from within this callback appears to be in a format that is incompatible with the native editor at this time. Specifically, this appeared to break Embed block variants, e.g. Vimeo. A future improvement would be to investigate this further in hopes of aligning web and native. * chore: Add background to section headers Improve legibility of section headers whenever blocks scroll beneath the header. * chore: Display collection title to improve dark mode support Leverage merely an icon with text made dark mode support more challenging. Rendering text allows for easy swapping of color schemes. * fix: Set collection title text color * fix: Adjust horizontal spacing for collection header
- Loading branch information
Showing
9 changed files
with
195 additions
and
49 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
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
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
37 changes: 37 additions & 0 deletions
37
packages/block-editor/src/components/inserter/test/utils.native.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,37 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { createInserterSection } from '../utils'; | ||
|
||
describe( 'createInserterSection', () => { | ||
it( 'returns the expected object shape', () => { | ||
const key = 'mock-1'; | ||
const items = [ 1, 2, 3 ]; | ||
const metadata = { icon: 'icon-mock', title: 'Title Mock' }; | ||
|
||
expect( createInserterSection( { key, metadata, items } ) ).toEqual( | ||
expect.objectContaining( { | ||
metadata, | ||
data: [ { key, list: items } ], | ||
} ) | ||
); | ||
} ); | ||
|
||
it( 'return always includes metadata', () => { | ||
const key = 'mock-1'; | ||
const items = [ 1, 2, 3 ]; | ||
|
||
expect( createInserterSection( { key, items } ) ).toEqual( | ||
expect.objectContaining( { | ||
metadata: {}, | ||
data: [ { key, list: items } ], | ||
} ) | ||
); | ||
} ); | ||
|
||
it( 'requires a unique key', () => { | ||
expect( () => { | ||
createInserterSection( { items: [ 1, 2, 3 ] } ); | ||
} ).toThrow( 'A unique key for the section must be provided.' ); | ||
} ); | ||
} ); |
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