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

Add Block Transform to transform Embed blocks into Paragraph blocks. #17413

Merged
merged 16 commits into from
May 11, 2020
Merged

Add Block Transform to transform Embed blocks into Paragraph blocks. #17413

merged 16 commits into from
May 11, 2020

Conversation

desaiuditd
Copy link
Member

Description

Fixes #15102 by providing a block transform to transform Embeds into Paragraphs.

Ref: #15102 (comment)

How has this been tested?

Pasting a URL into the Paragraph block automatically converts into an Embed blocks. After that, now, I'm able to transform the same Embed block into a Paragraph block. Performing an Undo action brings the Embed block back.

While working on this, I found a bug that none of the transformations of core/embed block were applied to core-embed/common/* and core-embed/others/* blocks. So I've fixed that as well.

Screenshots

Types of changes

While converting the Embed into Paragraph, if the caption is present, then I'm using that as the text for the link in the Paragraph. That seemed like a sensible behaviour without the data loss for the user. Happy to defer on someone who's more close to this.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.

} );
},
} ],
},
Copy link
Member Author

@desaiuditd desaiuditd Sep 12, 2019

Choose a reason for hiding this comment

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

Not sure if this is a breaking change or not. Simply changed the schema of JSON to make it consistent with other transforms.

Same for Speaker Deck block.

transforms: {
from: concat( get( transforms, 'from', [] ), get( embedSettings, 'transforms.from', [] ) ).filter( Boolean ),
to: concat( get( transforms, 'to', [] ), get( embedSettings, 'transforms.to', [] ) ).filter( Boolean ),
},
Copy link
Member Author

@desaiuditd desaiuditd Sep 12, 2019

Choose a reason for hiding this comment

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

Basically, apply combined transformations of core/embed as well as other core-embed/common/*

Same for core-embed/other/*

@gziolo gziolo added [Block] Embed Affects the Embed Block [Type] Enhancement A suggestion for improvement. labels Nov 20, 2019
…cks-into-paragraph-block

# Conflicts:
#	packages/e2e-tests/specs/__snapshots__/block-transforms.test.js.snap
@paaljoachim
Copy link
Contributor

paaljoachim commented Apr 2, 2020

Hey @desaiuditd

Here is even more information: #21029

Are you able to continue working on these things?

…cks-into-paragraph-block

# Conflicts:
#	packages/block-library/src/embed/core-embeds.js
#	packages/block-library/src/embed/index.js
#	packages/e2e-tests/fixtures/block-transforms.js
@desaiuditd
Copy link
Member Author

This is good for review again.

@paaljoachim
Copy link
Contributor

paaljoachim commented Apr 5, 2020

Hey Udit.

I tested the PR here:
http://gutenberg.run/17413

I then pasted the following links:
https://make.wordpress.org/
https://make.wordpress.org/core/
https://make.wordpress.org/test/2020/03/11/gutenberg-usability-testing-for-january-2020/

All three links brought up a following type of Embed placeholder box:
Screen Shot 2020-04-05 at 11 55 55

I clicked to embed but none of them could be embedded.
I clicked to preview the frontend and noticed that all are text links.


Option 1:
Here is my suggestion on how to simplify the process for a user adding a link.

The user pastes inn a link and it automatically shows up as a text link.
As all links can show up as text links.

But some links that can also be embedded. For these special links there can be an option to transform the text link into an embed through for instance the Transform area.

The transform area.
Screen Shot 2020-04-05 at 12 12 53

The embed option will only show up where a transform to an embed can happen.

EDIT:
Option 2.
Pasting a link when it is not embeddable automatically adds it as a text link.
Pasting a link when it is embeddable opens a placeholder box to where the user can choose to embed or choose to paste it as a text link. (There also needs to be a simple way to revert to either text or embed link.)

I will ping Miguel, so we can discuss it further here.
@mcsf

@desaiuditd
Copy link
Member Author

All three links brought up a following type of Embed placeholder box:

I tried this on preview server as well. But I also noticed these oembed api request failures.

image

That could be the reason why Gutenberg failed to convert them into embeds on paste.

@desaiuditd
Copy link
Member Author

desaiuditd commented Apr 5, 2020

The user pastes inn a link and it automatically shows up as a text link.
As all links can show up as text links.

But some links that can also be embedded. For these special links there can be an option to transform the text link into an embed through for instance the Transform area.

This changes the current default behaviour, which @mcsf mentioned. Some would consider this a breaking change.

It always tries to embed, but this process may fail depending on the source site.

So can we let the current behaviour be as is? And when the process may fail, user has two options to revert. Either transform to paragraph block or click Convert to link button.

@mapk mapk added the Needs Design Feedback Needs general design feedback. label Apr 14, 2020
@desaiuditd
Copy link
Member Author

I've one question for Option 1 that @paaljoachim has suggested.

The user pastes inn a link and it automatically shows up as a text link.
As all links can show up as text links.

But some links that can also be embedded. For these special links there can be an option to transform the text link into an embed through for instance the Transform area.

how can I check which embed transformation to allow? E.g., if I paste a WordPress Make URL, it’s not probably right to show Youtube embed in the transformation popup, right?

Check this Gif. I got this far. But not sure how to enable only valid embeds out of all. It’s even erroring out for any mismatched embed.

2020-04-17 22 20 17

@mcsf Do you have any thoughts on this?

Meanwhile, I will try and see if I can get Option 2 working.

@desaiuditd
Copy link
Member Author

desaiuditd commented Apr 18, 2020

it's better to leave it as is, and avoid abstractions like _mergeTransforms.

@mcsf I was trying to follow DRY because it was same logic for commonEmbeds and otherEmbeds embeds. Also, couple of embeds like Speaker Deck and Crowdsignal were coming with their own transforms. So they needed to be merged with the default transforms. Hence, _mergeTransforms, to retain embed specific transforms as well as the default one.

The core feature to expect from this PR is the ability to convert an embed into a block of text that links to the URL in question.

@mcsf Do you think, I should raise another PR to add smart handling of Embeds as per what Paal is suggesting? That way, this PR can just be about adding new block transform which converts embed into a paragraph with link to the embed url.

@paaljoachim
Copy link
Contributor

I think I am just confusing myself here..... I might be running around in circles... sorry about that.
Bottom line is the initial post here: #21029
and @mapk 's response.

I am happy to see that @mcsf Miguel is giving some feedback so we get the concept/development on the right course. Thank you Miguel.

@paaljoachim
Copy link
Contributor

So the process should be:
Link -> Can it embed? -> If yes -> Add a placeholder asking if the user wants to embed or convert to text link.
Link -> Can it embed? -> If no -> Automatically add a text link.

@mcsf @desaiuditd @mapk

@desaiuditd
Copy link
Member Author

So the process should be:
Link -> Can it embed? -> If yes -> Add a placeholder asking if the user wants to embed or convert to text link.
Link -> Can it embed? -> If no -> Automatically add a text link.

@mcsf @desaiuditd @mapk

Cool. Let me raise another PR to fix this (#21029), so we can have some separation of concern. This PR can fix #15102 in isolation.

@paaljoachim
Copy link
Contributor

paaljoachim commented Apr 24, 2020

I wrote the following in the core editor slack channel a few hours ago and will add it here as well.

So from my understanding of this PR. It takes a part various embeds. Then @desaiuditd will create a follow up PR where embeds are put together even better again. We are looking at all pasted links that embed such as a video etc to work as normal. But pasting a WP post content which normally just adds an embed will instead give the user a placeholder option to either embed the link or to show it as a text link. If someone can check out the PR and let us know if this is the correct approach that would be great. Thanks for any feedback and thoughts shared.

@mcsf
Copy link
Contributor

mcsf commented Apr 27, 2020

@desaiuditd:

@mcsf I was trying to follow DRY because it was same logic for commonEmbeds and otherEmbeds embeds. Also, couple of embeds like Speaker Deck and Crowdsignal were coming with their own transforms. So they needed to be merged with the default transforms. Hence, _mergeTransforms, to retain embed specific transforms as well as the default one.

Right, the custom transforms for Speaker Deck and Crowdsignal are broken, but are also unnecessary, since — in my testing — the editor corrects the embed type based on the provided patterns anyway. I think we should just remove them, but that belongs in a separate PR.

I appreciate the concern for DRY, although it's a constant tug between DRY and the visual and immediate clarity that sometimes an inline transformation can best provide.

In this case, we don't need to touch any of it, so I recommend reverting.

The core feature to expect from this PR is the ability to convert an embed into a block of text that links to the URL in question.

@mcsf Do you think, I should raise another PR to add smart handling of Embeds as per what Paal is suggesting? That way, this PR can just be about adding new block transform which converts embed into a paragraph with link to the embed url.

Yes, it's best to keep things focused. I personally am not convinced about smart handling of embeds, at least in the way it was it presented, but it can be put up for discussion.

Thanks for coming back to this PR, for making these changes and for keeping things organised!

@desaiuditd
Copy link
Member Author

@mcsf This is good for review again. I have made the requested changes.

@desaiuditd desaiuditd requested a review from mcsf May 10, 2020 05:25
Copy link
Contributor

@mcsf mcsf left a comment

Choose a reason for hiding this comment

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

Thanks for this fix!

@mcsf mcsf merged commit 48aba1e into WordPress:master May 11, 2020
@github-actions github-actions bot added this to the Gutenberg 8.1 milestone May 11, 2020
@desaiuditd desaiuditd deleted the add/block-transform-to-transform-embed-blocks-into-paragraph-block branch May 11, 2020 13:14
@paaljoachim
Copy link
Contributor

paaljoachim commented May 11, 2020

NB! @mcsf
This PR should not be included into 8.1 which is to be released today.
The PR tears a part embeds and we need the PR that rebuilds embeds to be merged at the same time, so that we do not break Youtube and other embeds.

Bottom line is that adding the test links I have further above in this PR, and a few Youtube URLs none of these can be embedded.

Screen Shot 2020-05-11 at 15 23 38


Another example.
Here is one of my dev sites where I added:
https://www.youtube.com/watch?time_continue=4756&v=lSkmtb-OvDk&feature=emb_logo

(The embed)
Screen Shot 2020-05-11 at 15 26 21

(Clicking pencil. This is what I see.)
Screen Shot 2020-05-11 at 15 26 26

Going to Gutenberg.run and testing this PR.
Here is the result of adding this URL: https://www.youtube.com/watch?time_continue=4756&v=lSkmtb-OvDk&feature=emb_logo

Screen Shot 2020-05-11 at 15 28 06

@mcsf
Copy link
Contributor

mcsf commented May 11, 2020

I'm not experiencing any regressions so far. I've compared 81d4f4c (PR head) with the base branch at 601ee4b, and I've tested again with the commit to master at 48aba1e.

You may be experiencing this for being stuck with a stale build in gutenberg.run, something which should be fixed soon (Slack link).

@paaljoachim
Copy link
Contributor

paaljoachim commented May 11, 2020

Retesting again in gutenberg.run.
I just retested again (in Chrome), and I am getting the same result.

I retested using Firefox, and received the same result.

Screen Shot 2020-05-11 at 15 52 28

@desaiuditd
Copy link
Member Author

@paaljoachim This PR was never meant to fix the smart auto embedding which you suggested earlier. This PR only allows user to convert an existing embed block into a paragraph block. So it only fixes #15102 in isolation.

The approach you suggested is still being discussed at #21029.

@paaljoachim
Copy link
Contributor

Hey @desaiuditd

My concern during the test at gutenberg.run was that one is not able to embed even the Youtube embeds that I tested with.

So from what you are saying (hopefully) the above would be an error.
One should be able to embed. Then take any embed and convert it into a paragraph block.
Is this correct?

transform: ( { url, caption } ) => {
const link = <a href={ url }>{ caption || url }</a>;
return createBlock( 'core/paragraph', {
content: renderToString( link ),
Copy link
Member

Choose a reason for hiding this comment

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

Why not write the html as a string?

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 mind the added peace of mind of running this through the element serialiser. Do you have drawbacks in mind?

@jorgefilipecosta
Copy link
Member

The PR seems to work well in my tests. I am also able to reproduce the issue @paaljoachim referred but only on gutenberg.run. @aduth verified gutenberg.run has an issue in requests to the endpoint /wp-json/oembed/1.0/proxy?url=.

@mcsf
Copy link
Contributor

mcsf commented May 11, 2020

Thanks for debugging that! Seems we can move on with the release.

@paaljoachim
Copy link
Contributor

paaljoachim commented May 12, 2020

Testing with 8.1.0-rc.1

This PR adds a transform an Embed to Paragraph option.
Here is an example.

Using an URL that automatically made an embed.
https://make.wordpress.org/core/2020/05/12/editor-chat-agenda-13-may-2020/

The embed:
Screen Shot 2020-05-12 at 16 07 44

Transform to Paragraph Block:
Screen Shot 2020-05-12 at 16 07 51

Transformed Embed block which has now turned into a Paragraph Block:
Screen Shot 2020-05-12 at 16 07 56

@paaljoachim
Copy link
Contributor

paaljoachim commented May 12, 2020

Great job @desaiuditd !
Thank you very much for tackling this PR!
And a huge thank you to @mcsf !

@jorgefilipecosta
I do believe it would be beneficial to backport the embed PR to a WP 5.4.2 at a later time.
As it would create an important option for anyone in how they want a link to appear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Embed Affects the Embed Block Needs Design Feedback Needs general design feedback. [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Option to use text link instead of auto embed.
7 participants