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

WIP: Install a block from inserter #16524

Closed
wants to merge 136 commits into from

Conversation

ck-lee
Copy link
Contributor

@ck-lee ck-lee commented Jul 11, 2019

Description

Extend the inserter to show available blocks for download and silently install the block when the block is inserted into the editor

This PR is still a WIP. Can you help guide me with the implementation and avoiding any pitfalls? I'm new to the block editor.

Screenshots

Types of changes

  • Extend inserter to fetch a list of suggestBlocks similar to reusableBlocks
  • The list of suggestBlocks is currently served from a mock API. It is not built yet.
  • Extend the filter to show suggestBlocks if there are no results found.
  • When "Add" button is clicked, download the block assets from plugin.svn. Then, load and insert the block into the editor without installing it.
  • ...

Relevant Links

[design] Main thread
https://make.wordpress.org/design/2019/04/26/block-library-installing-blocks-from-within-gutenberg/

[design] Figma
https://www.figma.com/file/QKhoOKXkBN2mHacqvrtdNuI6/Gutenberg-Block-Library%3A-Installation

[design] Mockup feedback
https://make.wordpress.org/design/2019/06/07/block-library-mockups-prototype

[dev] Block Directory Proposal
https://make.wordpress.org/meta/2019/03/08/the-block-directory-and-a-new-type-of-plugin/

[dev] Block Registration
https://github.com/WordPress/gutenberg/blob/master/docs/rfc/block-registration.md

[dev] Block Registration - assets JSON structure
#13693 (comment)

GitHub Block Directory issues
https://github.com/WordPress/block-directory/issues

GitHub Block Directory project
https://github.com/WordPress/block-directory/projects/1

@youknowriad youknowriad added Needs Accessibility Feedback Need input from accessibility Needs Design Feedback Needs general design feedback. [Feature] Inserter The main way to insert blocks using the + button in the editing interface [Feature] Block Directory Related to the Block Directory, a repository of block plugins labels Jul 11, 2019
Copy link
Contributor

@tellthemachines tellthemachines left a comment

Choose a reason for hiding this comment

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

The experiments settings bit looks good!

One question: should installing blocks also be enabled from the inserters on the Widgets screen and the Widget Blocks section in the Customizer? These inserters are still experimental (you need to enable the "Widgets" experiment for them to work) but they work exactly the same as the inserter on the main editor page, so it might make sense for them to include this functionality.

@ck-lee
Copy link
Contributor Author

ck-lee commented Aug 25, 2019

Some minor issues:

  1. Not sure why, but on Windows, NVDA announces "No blocks found in your library" and on Mac, VO announces "0 results found" instead. I don't think this is a big deal but thought I should bring it up nevertheless.
  2. On Windows, it'd be great if the number of reviews could be announced with a more descriptive label like on the Mac ("Zero total ratings"). I would also try to avoid announcing "Left parent. Zero. Right parent.".

Thank you, @enriquesanchez. Good to know that there are no major a18y issues. I will have a look at these minor ones and see if I can improve them.

@ck-lee
Copy link
Contributor Author

ck-lee commented Aug 25, 2019

should installing blocks also be enabled from the inserters on the Widgets screen and the Widget Blocks section in the Customizer?
@tellthemachines, Thank you for letting me know about the inserters in Widgets screen. I think the feature should be included too. I will look into that.

I hope that it is as as simple as including the block-directory package and fill/slot in the edit-widgets module.

@ck-lee
Copy link
Contributor Author

ck-lee commented Aug 28, 2019

This PR has now been split to 4 PRs in preparation for further review and merging:

Add block directory search settings (#17182)
Add an extension slot for inserter menu. (#17183)
Implement REST controller for block directory features. (#17243)
Implement new block-directory package (#17244)

onClick();
} }
>
{ __( 'Add' ) }
Copy link
Contributor

Choose a reason for hiding this comment

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

For screenreader users, the add button gives no context of the what the user is adding.

@@ -134,6 +139,17 @@ class EditorProvider extends Component {
if ( this.props.settings !== prevProps.settings ) {
this.props.updateEditorSettings( this.props.settings );
}
if ( ! isEqual( this.props.downloadableBlocksToUninstall, prevProps.downloadableBlocksToUninstall ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't quite understand what this code is for—would be good to add a comment.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, so the blocks get uninstalled if they're unused. I think that's how it's supposed to work.

I think this functionality would be best moved to the edit-post package, in a component. It'd be similar to how AutosaveMonitor is a component.

Copy link
Member

Choose a reason for hiding this comment

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

Cross-linking a related discussion fo reference: #17576 (comment)

This functionality was removed in #17576. It should be added back once we agree on a new approach.

this.props.downloadableBlocksToUninstall.forEach( ( blockType ) => {
this.props.uninstallBlock( blockType, noop, () => {
this.props.createWarningNotice(
__( 'Block previews can\'t uninstall.' ), {
Copy link
Contributor

Choose a reason for hiding this comment

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

This text seems like it'll need some improvement.

const createdBlock = onSelect( item );

const onInstallBlockError = () => {
createErrorNotice(
Copy link
Contributor

Choose a reason for hiding this comment

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

Inline notices within the inserter popover would provide a better experience, I think. Currently the message is hidden behind the inserter.

Copy link
Member

Choose a reason for hiding this comment

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

Let's fix this in a follow-up PR.

packages/block-directory/src/store/index.js Show resolved Hide resolved
);
register_rest_route(
$this->namespace,
'/' . $this->rest_base . '/uninstall',
Copy link
Member

Choose a reason for hiding this comment

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

It doesn't feel very "restful" to use different URLs for the create and delete actions. Could "installation" be a resource? e.g. so POST /installations creates and DELETE /installations/:id deletes?

Copy link
Member

Choose a reason for hiding this comment

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

Let's do this in a follow-up PR.

<Icon icon="chart-line"></Icon>{ sprintf( _n( '%d active installation', '%d active installations', activeInstalls ), activeInstalls ) }
</div>
<div className="block-directory-downloadable-block-info__column">
<Icon icon="update"></Icon><span aria-label={ sprintf( __( 'Updated %s' ), humanizedUpdated ) }>{ humanizedUpdated }</span>
Copy link
Member

Choose a reason for hiding this comment

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

It wasn't clear to me at first that this icon meant 'last updated'. Could we add title text? Relatedly, do these icons need alt text?

<div className="block-directory-downloadable-block-header__row">
{
icon.match( /\.(jpeg|jpg|gif|png)/ ) !== null ?
<img src={ icon } alt="block icon" /> :
Copy link
Member

Choose a reason for hiding this comment

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

Is there something more descriptive than "block icon" that we can use? Maybe the block's title? Regardless, this string needs to be localised.

{ sprintf( __( 'Authored by %s' ), author ) }
</span>
<span className="block-directory-downloadable-block-author-info__content">
{ sprintf( _n( 'This author has %d block, with an average rating of %d.', 'This author has %d blocks, with an average rating of %d.', authorBlockCount, authorBlockRating ), authorBlockCount, authorBlockRating ) }
Copy link
Member

Choose a reason for hiding this comment

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

Does an average rating of 0 imply that the author has no ratings? If so, should we exclude the second part of this sentence when the average rating is 0? It sounds al little awkward otherwise:

This author has 1 block, with an average rating of 0.

Copy link
Member

Choose a reason for hiding this comment

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

Let's think about this in a follow-up PR.

Copy link
Contributor

@jasmussen jasmussen left a comment

Choose a reason for hiding this comment

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

This is very impressive work, very very solid. I can't wait for this feature to land, it's breathtaking.

I left a few tiny comments to use variables here and there, but the CSS overall is well written, well structured and superb as is.

The only thing I think probably should be fixed before shipping is this one: https://github.com/WordPress/gutenberg/pull/16524/files#r324309944 — but I did leave a couple of suggestions for how to fix that.

@noisysocks
Copy link
Member

Closing in favour of #17431.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Block Directory Related to the Block Directory, a repository of block plugins [Feature] Inserter The main way to insert blocks using the + button in the editing interface First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository Needs Accessibility Feedback Need input from accessibility Needs Design Feedback Needs general design feedback. REST API Interaction Related to REST API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants