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

Block warning: add ellipsis menu and convert to classic block #7741

Merged
merged 7 commits into from
Aug 28, 2018

Conversation

johngodley
Copy link
Contributor

@johngodley johngodley commented Jul 6, 2018

Description

Add the ability for a block warning message to show a list of additional actions that are hidden behind a dropdown ellipsis menu. This will be used to expand the options available to a user when an invalid block is detected.

The 'convert to blocks' option is copied into this menu, along with a new 'convert to classic block' option. This matches the mockup in #7604. More options will be added in future PRs

another_post___ wordpress_latest _wordpress

How has this been tested?

Extra unit tests have been added to verify when the ellipsis menu appears.

npm run test warning

Types of changes

A non-breaking new feature is added to an existing component. The Warning component is used by:

  • BlockInvalidWarning
  • BlockCrashWarning

To test BlockInvalidWarning:

  • Create a paragraph
  • Edit as HTML and remove the trailing </p> to trigger the block validation message
  • Verify that the invalid block message is displayed with a new ellipsis menu:
    another_post___ wordpress_latest _wordpress
  • Verify that reducing the page width causes the primary buttons to move onto the next line, but the ellipsis menu remains on the right:
    another_post___ wordpress_latest wordpress_and_gutenberg update_block-warning-options__origin_update_block-warning-options__7169_commits
  • Verify that clicking 'convert to block' from the ellipsis menu performs the same action as the 'convert to block' button
  • Verify that clicking 'convert to classic block' converts it to a classic block

To test BlockCrashWarning:

  • From a developer console type wp.blocks.registerBlockType( 'myplugin/mr-crashy', { title: 'Mr. Crashy', category: 'common', icon: 'warning', edit() { throw new Error(); }, save() { return ''; } } );
  • Add Mr Crashy block to a post
  • Verify that the crash message is displayed without changes:
    another_post___ wordpress_latest _wordpress

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.

@johngodley johngodley added [Feature] Blocks Overall functionality of blocks [Status] In Progress Tracking issues with work in progress labels Jul 6, 2018
@jasmussen
Copy link
Contributor

Very nice work, I pushed some polish:

screen shot 2018-07-06 at 13 31 31

I also removed the styles for the contents of the navibable menu. Can I kindly ask you to take a look at the more menu and perhaps steal a bit from there? We have some components for menuy groups, menu labels and even menu items. If we reuse those, we get the visual styles, as well as their accessibility for free.

@johngodley johngodley force-pushed the update/block-warning-options branch 4 times, most recently from dc17ec8 to cae4b87 Compare July 10, 2018 15:05
@johngodley johngodley changed the title WIP - Update/block warning options Block warning: add ellipsis menu and convert to classic block Jul 11, 2018
@johngodley johngodley changed the title Block warning: add ellipsis menu and convert to classic block WIP Block warning: add ellipsis menu and convert to classic block Jul 17, 2018
@johngodley johngodley force-pushed the update/block-warning-options branch from 0d92752 to 2008867 Compare July 24, 2018 08:44
@johngodley
Copy link
Contributor Author

The overall style was moved into another PR, and the code here updated to use the 'more menu' as mentioned by Joen. I've added a slight CSS tweak to better vertically align the ellipsis button

@johngodley johngodley changed the title WIP Block warning: add ellipsis menu and convert to classic block Block warning: add ellipsis menu and convert to classic block Jul 24, 2018
@johngodley johngodley removed the [Status] In Progress Tracking issues with work in progress label Jul 24, 2018
@johngodley johngodley force-pushed the update/block-warning-options branch 3 times, most recently from 97682ed to e60a13f Compare July 29, 2018 11:42
@jasmussen
Copy link
Contributor

Very cool, what's the status of this? Does it need a wider Gutenberg review? Do you need anything from me to ship this?

Adds an ellipsis dropdown menu so additional actions can be added outside of the primary buttons

Note this just adds the capability for additional actions, but doesn’t actually include any
Makes use of the new ellipsis menu to present the sa,e convert to blocks option along with a convert to classic block
The menu is slightly vertically off-centred when on full screen desktop. This moves it a bit while still looking ok on mobile
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.

Looking good, just left some small notes.

@@ -30,6 +30,10 @@ function BlockInvalidWarning( { convertToHTML, convertToBlocks } ) {
</Button>
),
] }
hiddenActions={ [
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this be secondaryActions (to match the "primaryActions" prop)?

{ hiddenActions && (
<div className="editor-warning__hidden">
<Dropdown
className="edit-post-more-menu"
Copy link
Contributor

Choose a reason for hiding this comment

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

The edit-post-* className seems useless right? (they don't follow our guidelines neither)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's the same class used in https://github.com/WordPress/gutenberg/blob/master/edit-post/components/header/more-menu/index.js, making the ellipsis vertical rather than horizontal. I can file a separate issue if that also needs changing to match the guidelines?

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 think we should rely on classnames styled in other components. We should aim to reuse components instead of classnames instead.

So two options:

  • I'm fine duplicating the styles (if not too much) and using the right classnames here editor-warning__*
  • Creating a generic component with these styles but in that case, this component should be meaningful. Maybe it could be a prop of Dropdown instead?

@johngodley
Copy link
Contributor Author

@youknowriad thanks for looking. All good points.

For the purpose of this PR I've copied the appropriate styles to this component - it's pretty minimal.

While looking at the CSS I noticed the original component has what appears to be dead CSS as well as problems on mobile (that only affect the other component).

I'll investigate that separately and if it makes sense, refactor with this component while fixing any problems.

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.

LGTM 👍 Nice work

@johngodley johngodley merged commit df3d366 into master Aug 28, 2018
@johngodley johngodley deleted the update/block-warning-options branch August 28, 2018 14:40
@aduth
Copy link
Member

aduth commented Aug 29, 2018

This shouldn't have been merged.

  • It broke backwards-compatibility with the Warning actions prop by renaming it to primaryActions. This should have been deprecated, with support for actions kept for two versions, documented in docs/deprecated.md and noted in packages/editor/CHANGELOG.md
  • Related to the previous point, I assume it broke both ErrorBoundary and the "validate multiple use" hook, both of which render Warning with the now-non-existant actions prop

@youknowriad
Copy link
Contributor

Good catch @aduth I missed that :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Blocks Overall functionality of blocks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants