-
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
Update BlockPreview component to accept multiple Blocks to preview #16033
Conversation
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.
Right now that component expects name, attributes and innerBlocks prop to render the preview. I think if we want to expose it, it would be better to allow passing blocks
as an array instead of these granular props. What do you think?
It definitely sounds like a nicer API. Do you think we should update all current usages to use |
I'd opt for this. It seems straightforward? |
Also, I think we might want to expose This might require some adjustements to classnames and things like that. |
Let's keep this in sync with #16113 cc @jasmussen |
I did some investigation during the weekend and I'm currently thinking between:
The smaller size is used in "Styles" panel for example and the full size can be seen inside the block switcher or in block inserter for reusable blocks I'm personally leaning towards the latter |
@marekhrabe I've found the two-component modal pretty confusing. I'd lean towards number 2 also. |
I also liked the approach when doing some prototypes locally, it was just a bit more work than expected as those two components do very different things and all places they are used from have to be updated. With the rate #16113 is getting worked on and introducing a lot of changes, I think it might be wise to wait with this PR for that one to be merged. Otherwise, we will be doing some duplicate work about scaling etc… |
1e075b8
to
4d43dad
Compare
I'm working separately on the unification of With @getdave and @retrofox, we plan to spend some more time on various issues around block previews. To be able to ship gradual updates to these components, I would suggest to keep this PR only about the move from Let's finish the support for |
Not sure why this was introduced.
The `innerBlocks` of the `block` being cloned can be `undefined`. Therefore, by attempting to map these we trigger an error. Fixed to introduce existence check before attempting to manipulate innerBlocks.
initalAttributes is already an object so no need to spread into an object.
8b77521
to
d04cf21
Compare
I've done a rebase against the master branch (clean, no conflicts) so I can start integrating with #16801. |
97c05cb
to
75f9bb0
Compare
I have fixed the issue around I think this is now ready for a review. cc: @youknowriad you were suspicious about it and totally right! |
Suggest we filter this out if previews along with any other Block inserters. |
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.
LGTM 👍Thanks for the updates.
I agree that the inserter on the left should be hidden on previews. for me it shows similarly (color) in both master and this branch.
…16033) * export BlockPreview * Update to accept multiple Blocks * Update reusable Blocks preview to use the new single blocks prop * Remove unecessary clone of Blocks Not sure why this was introduced. * Remove export. This is being handled in another PR See #16801 * Simplify casting to array via lodash * Utilise cloneBlocks to safely merge attributes on blocks prop * Spread reusable block initial attrs correctly * Fix cloneBlock fn to check for innerBlocks before attempting to map The `innerBlocks` of the `block` being cloned can be `undefined`. Therefore, by attempting to map these we trigger an error. Fixed to introduce existence check before attempting to manipulate innerBlocks. * Simplify modifying passed block attrs via cloneBlock * Removes unecessary spread operation initalAttributes is already an object so no need to spread into an object. * block-preview: ensuring to cast BlockEditorProvider value prop as an Array * don't call cloneBlock on a non-block object * bring back the old behavior of cloneBlock
…16033) * export BlockPreview * Update to accept multiple Blocks * Update reusable Blocks preview to use the new single blocks prop * Remove unecessary clone of Blocks Not sure why this was introduced. * Remove export. This is being handled in another PR See #16801 * Simplify casting to array via lodash * Utilise cloneBlocks to safely merge attributes on blocks prop * Spread reusable block initial attrs correctly * Fix cloneBlock fn to check for innerBlocks before attempting to map The `innerBlocks` of the `block` being cloned can be `undefined`. Therefore, by attempting to map these we trigger an error. Fixed to introduce existence check before attempting to manipulate innerBlocks. * Simplify modifying passed block attrs via cloneBlock * Removes unecessary spread operation initalAttributes is already an object so no need to spread into an object. * block-preview: ensuring to cast BlockEditorProvider value prop as an Array * don't call cloneBlock on a non-block object * bring back the old behavior of cloneBlock
Description
BlockPreview
currently only accepts a single Block. This PR updates this to allow it to (optionally) accept an array of blocks. It also simplifies the API by requiring a Block object rather than expecting Block properties as individual args.Note: the Reusable Blocks previews are not currently working due to this unrelated bug #16808
How has this been tested?
Firstly confirm existing behaviour has been preserved with the change in API. To do this, manually test all instances where
BlockPreview
is used and ensure all function as permaster
branch:To test multiple Blocks being rendered you can:
(Applying the diff is necessary to make this PR's under-the-hood changes visible)
BlockPreviewContent
below the standard Block Style previews.Places to check for previews
Types of changes
New feature (non-breaking change which adds functionality)
To Demo
Show multiple blocks being previewed.