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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display reusable blocks in the inserter's 'Recent' tab #4768

merged 2 commits into from Feb 1, 2018


None yet
2 participants
Copy link

commented Jan 31, 2018

馃惗 What this is

Closes #4653.

screen shot 2018-01-31 at 11 01 22

Shows reusable blocks in the 'Recent' tab of the inserter.

馃 How this works

Before, our reducer would build out a state.preferences.recentlyUsedBlocks that looks like this:

recentlyUsedBlocks: [ 'core/paragraph', 'core/image' ],

This PR changes the shape of this data to look like this:

recentInserts: [
    { name: 'core/paragraph' },
    { name: 'core/image' },
    { name: 'core/block', ref: 123 }

It's then just a simple matter of patching selectors.getRecentInserterItems to look up reusable blocks by the ref that is stored.

I've renamed recentlyUsedBlocks to recentInserts so that we don't need to worry about parsing old data which is in a different shape. This means that, when a user upgrades to the next version of Gutenberg, the blocks that appear in their 'Recent' tab will be reset. I think this is an acceptable trade-off since this data isn't all that important and will be quickly re-populated.

馃搵 How to test

  1. Insert a regular block
  2. Insert a reusable block
  3. Open the inserter and see that both blocks appear in the 'Recent' tab
  4. Check that clicking on the block in the inserter inserts that block
Display reusable blocks in the inserter's 'Recent' tab
Record which reusable blocks are inserted in `state.preferences` so that
`selectors.getRecentInserterItems` can return reusable blocks in
addition to static blocks.
insert = { name:, ref: block.attributes.ref };
} else {
insert = { name: };

This comment has been minimized.

Copy link

youknowriad Jan 31, 2018


minor: maybe just my obsession for shorter code. This could be:

const insert = { name : };
if ( isReusableBlock( block ) ) {
  insert.ref = block.attributes.ref;

This comment has been minimized.

Copy link

noisysocks Feb 1, 2018

Author Member

Changed in 6d77903. All this newfangled syntax has made me forget that mutation is still a thing 馃槅

Copy link

left a comment

It works great in my testing, nice work 馃憤

@noisysocks noisysocks merged commit 14a6e40 into master Feb 1, 2018

2 checks passed

codecov/project 38.19% (+0.05%) compared to 49f05e5
continuous-integration/travis-ci/pr The Travis CI build passed

@noisysocks noisysocks deleted the add/reusable-blocks-to-recent-tab branch Feb 1, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can鈥檛 perform that action at this time.