-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Add a "reinstall" button when a block type is not found #22631
Conversation
Size Change: +524 B (0%) Total Size: 1.17 MB
ℹ️ View Unchanged
|
I like this idea and I can see it becoming useful in a number of different "missing blocks" use cases. |
if ( name !== 'core/missing' ) { | ||
return settings; | ||
} | ||
settings.edit = missingInstallView; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's fine as a temporary approach. However, it could be very hard to maintain in the long run as you would have to keep the implementation in sync with changes applied to the Missing block.
Have you considered using an approach where you could parameterize action items in some way? It could be also done through filters but on the more granular level or through SlotFill approach.
This seems like a pretty valuable feature. I suspect the missing block notice may have been overlooked in the 5.5 design updates. Currently, it looks like this: Perhaps we can fix up the padding and button styling in this or a follow up PR to bring it closer to the block placeholders: I did modify the copy slightly:
I wasn't able to get the button to appear locally. I tried with Layout Grid and Gutenslider (which I will not be installing again). Hamze has closed the Blissful Buttons plugin so I tested with Layout Grid. I would like to see what happens when I click the install button. Is there an installing/activating state? Is it so fast it just magically works? |
22be2a0
to
1b15476
Compare
I've updated the code here to use a filter on the Missing edit view, so that it can fall back to the core missing component when blocks are not found or the block directory is not allowed. The initial view uses the default missing message, once the block directory returns a block it should load in the "Install [block name]" button. When clicked, it flips to a loading button while the plugin installs One thing that still needs work is that the attributes aren't carried over, for example in the above screenshots I've added a "Custom heading label", but when the Table of Contents block installs, it wipes out that content & is like a new block. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks good.
Can we get the button to left align with the paragraph content and add the same amount of padding/margin under the button?
/* translators: %s: block name */ | ||
__( | ||
'Your site doesn’t include support for the "%s" block. You can try reinstalling the block, convert its content to a Custom HTML block, or remove it entirely.' | ||
), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this copy since it clarifies the 3 actions that i can take. However, we only show 2 of them below. I was expecting to see the remove action next to the "Keep as HTML" link.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const hasContent = !! originalUndelimitedContent; | ||
const hasHTMLBlock = getBlockType( 'core/html' ); | ||
const hasPermission = useSelect( ( select ) => | ||
select( 'core/block-directory' ).hasInstallBlocksPermission() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This call delays the "Re-install" button's rendering. It's a bit jarring. Since the block directory uses "plugin install" permissions, is there a better way to get the permissions without having to do it async?
If not, maybe we should assume that the user can and let the endpoint manage it.
Related: https://github.com/WordPress/gutenberg/pull/16524/files#r315493053
<Button | ||
onClick={ () => | ||
installBlockType( block ).then( ( success ) => { | ||
if ( success ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that the block I was testing with errored out because of an issue with its JS. The UI just stares back at you doing nothing.
You can test with Boxer Block
.
index.js:94 Uncaught (in promise) TypeError: Cannot read property 'name' of undefined at Object.replaceBlock (index.js:94) at use-dispatch-with-map.js:68 at convertToBlock (index.js:44) at install-button.js:36
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More specifically, it installed properly but errored on injection.
@@ -0,0 +1,57 @@ | |||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I expected this file to only have one button, not sure if you named it this with the intention of it being included into core, where it probably would be only 1 button.
@StevenDufresne Something went weird in your review, it looks like GitHub let you review the old version of this PR. I think the current iteration fixes your other points. |
I think i may have had added a comment to a review a while ago but never submitted the review. GitHub must hold on to those, and on my end, it looks like they have been submitted but they actually haven't. |
I updated the styles to match the mockup and other patterns (like the block placeholder state). In doing so, I noticed a couple things that were confusing to me. Here's a quick screencap of me disabling a block in order to view the warning: You'll notice a few things. Once I clicked the button to reinstall Layout Grid, I got a new layout grid essentially. If I then refresh the page, I get my old content back along with the "newer version of this document" warning at the top. Do you know why my original content inside Layout Grid wasn't immediately restored? The other really minor bug is that the buttons change once the warning figures out there is a block it can install. Is there any way we can prevent that button change flash? I'm open to ideas. This is what I'm talking about: |
… the block placeholder state * Removed font size declaration - was inconsistent with other patterns particularly because of the use of `em` units for padding * changed padding on the warning and changed margin on the warning message * changed the side the padding was on for warning buttons
a289d1e
to
2413b8c
Compare
It shows the current missing block view while we're searching the block directory for this block. We don't know if the block exists in the directory (or if it's some custom block), and we don't know the human-friendly name, until the API result comes back. We could add a spinner, or prevent showing any buttons while the search is running, use different copy? I'm not sure what would be best.
Figured it out! It looks like nested blocks weren't being correctly updated, but they should be now. |
I think something like that could work. Let's shelve that for a future PR. This one looks good to go from a design standpoint. |
@@ -3,8 +3,7 @@ | |||
display: flex; | |||
flex-wrap: wrap; | |||
font-family: $default-font; | |||
font-size: $default-font-size; | |||
padding: ($grid-unit-10 - $border-width - $border-width) $grid-unit-15; | |||
padding: 1em; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having padding set as an em
unit could lead to some odd outcomes should the block be broken inside of a parent block. It will inherit its font size. May be better to use rem
units.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is an open PR to switch to em units and the block Placeholder state already uses em units. That's the reason for the change. Might as well be consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the heads up....
I wonder if that PR is considering third party blocks. This may get interesting. 🍿
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That PR looks like it was halting for further testing. That said, this will still be more consistent with the placeholder state for other blocks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minus my comment about using em
units. This works as expected and is good to go.
As @MichaelArestad has mentioned, we will want to address the UI change when we find a block directory block in the future.
I'm late to the party, but have you considered using the existing |
Wouldn't I thought about a Slot/Fill approach, but that would probably look a lot like this filter, since I'd want to fall through to |
If I'm understanding the issue, the requirements are:
-- |
Yes to all your questions. :) I see the use case for allowing falling back to
This does seem worth looking at. |
Correct.
This is actually exactly what I did in the first pass of the PR, which @gziolo pointed out would be hard to keep in sync with any core |
Description
If editing a post with a missing block, this PR adds the ability to reinstall it. It uses the Block Directory work to search for a block with the same name, and if found, gives you the option to reinstall the block. Once installed, the broken block is converted back into the original.
Fixes #24759
How has this been tested?
Only in-browser testing. I had a post with some missing blocks, one of which can be found on the block directory. You can copy this into the code editor to try it out (will install the Blissful Buttons plugin)
Screenshots
When first loaded, it searches for the block on wp.org. If no matching blocks are found, it only shows the Keep as HTML button (bottom). If it finds a block, it shows both Reinstall and Keep as HTML (top).
Types of changes
New feature (non-breaking change which adds functionality)
Checklist: