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

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

Merged
merged 2 commits into from
Feb 1, 2018

Conversation

noisysocks
Copy link
Member

@noisysocks noisysocks 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

Record which reusable blocks are inserted in `state.preferences` so that
`selectors.getRecentInserterItems` can return reusable blocks in
addition to static blocks.
@noisysocks noisysocks added [Type] Enhancement A suggestion for improvement. [Feature] Inserter The main way to insert blocks using the + button in the editing interface [Feature] Synced Patterns Related to synced patterns (formerly reusable blocks) labels Jan 31, 2018
insert = { name: block.name, ref: block.attributes.ref };
} else {
insert = { name: block.name };
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works great in my testing, nice work 👍

@noisysocks noisysocks merged commit 14a6e40 into master Feb 1, 2018
@noisysocks noisysocks deleted the add/reusable-blocks-to-recent-tab branch February 1, 2018 00:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Inserter The main way to insert blocks using the + button in the editing interface [Feature] Synced Patterns Related to synced patterns (formerly reusable blocks) [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants