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

OpenTable: Accept more embed options #14639

Merged
merged 6 commits into from
Feb 18, 2020
Merged

Conversation

scruffian
Copy link
Member

Changes proposed in this Pull Request:

  • This broadens the scope of what kinds of embed the OpenTable block will accept
  • It will now take an embed code, a URL, or a list of selected restaurants.

Testing instructions:

  • Also test that these URLs work when pasted directly into the editor
  • Make sure that other types of embed still work.

Proposed changelog entry for your changes:

  • Accept URLs when embedding an OpenTable block

@scruffian scruffian added [Status] Needs Review To request a review from Crew. Label will be renamed soon. [Focus] Blocks Issues related to the block editor, aka Gutenberg, and its extensions developed in Jetpack [Block] OpenTable labels Feb 11, 2020
@scruffian scruffian requested a review from a team as a code owner February 11, 2020 15:17
@scruffian scruffian self-assigned this Feb 11, 2020
@matticbot
Copy link
Contributor

Caution: This PR has changes that must be merged to WordPress.com
Hello scruffian! These changes need to be synced to WordPress.com - If you 're an a11n, please commandeer, review, and approve D38705-code before merging this PR. Thank you!

@jetpackbot
Copy link

jetpackbot commented Feb 11, 2020

Thank you for the great PR description!

When this PR is ready for review, please apply the [Status] Needs Review label. If you are an a11n, please have someone from your team review the code if possible. The Jetpack team will also review this PR and merge it to be included in the next Jetpack release.

Scheduled Jetpack release: February 17, 2020.
Scheduled code freeze: February 10, 2020

Generated by 🚫 dangerJS against 211c300


let domain = searchParams.get( 'domain' );
if ( ! domain || domain.length === 0 ) {
domain = 'com';
Copy link
Member Author

Choose a reason for hiding this comment

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

We might be able to get this from the URL, but I don't think it matters.

@matticbot
Copy link
Contributor

scruffian, Your synced wpcom patch D38705-code has been updated.

@jeherve jeherve added this to the 8.3 milestone Feb 12, 2020
Copy link
Member

@jeherve jeherve left a comment

Choose a reason for hiding this comment

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

That cleans things up quite nicely.

I think we'd benefit from a test for getAttributesFromEmbedCode here, to avoid any regressions in the future, just like we've done for Calendly:
https://github.com/Automattic/jetpack/blob/2c3dbd93a0cc735df5593a147532cf5de02627ba/extensions/blocks/calendly/test/utils.js

@jeherve jeherve added [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! [Tests] Needs Tests Some Unit Tests would be really useful to include with this PR. and removed [Status] Needs Review To request a review from Crew. Label will be renamed soon. labels Feb 12, 2020
@matticbot
Copy link
Contributor

scruffian, Your synced wpcom patch D38705-code has been updated.

1 similar comment
@matticbot
Copy link
Contributor

scruffian, Your synced wpcom patch D38705-code has been updated.

@scruffian
Copy link
Member Author

I added unit tests for this function. In the process I realised that it wasn't actually working correctly - we weren't picking up the correct true/false values from the widget code. I have fixed this now, but to do so I had to change the iframe and newtab attributes from Booleans into strings.

The only issue I see with this is that users who have previously changed these settings to something other than the default will lose them if they edit a post with a block in. I'm not sure its worth adding code to account for this. What do you think?

@scruffian scruffian added [Status] Needs Review To request a review from Crew. Label will be renamed soon. [Status] In Progress and removed [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! [Status] Needs Review To request a review from Crew. Label will be renamed soon. labels Feb 13, 2020
@jeherve
Copy link
Member

jeherve commented Feb 13, 2020

I'm not sure its worth adding code to account for this. What do you think?

In the past we have. You can check the VideoPress for an example:
57ed23f

That's a lot for a small change, though. Could we make the type change before we get to the attributes instead?

@matticbot
Copy link
Contributor

scruffian, Your synced wpcom patch D38705-code has been updated.

1 similar comment
@matticbot
Copy link
Contributor

scruffian, Your synced wpcom patch D38705-code has been updated.

@scruffian scruffian added the [Status] Needs Review To request a review from Crew. Label will be renamed soon. label Feb 13, 2020
@scruffian
Copy link
Member Author

Based on some useful feedback from @pablinos I did this a different way; we are keeping the boolean attributes and just casting them in the validation helper.

@scruffian
Copy link
Member Author

I also added some tests for getValidatedAttributes

Copy link
Contributor

@pablinos pablinos left a comment

Choose a reason for hiding this comment

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

Looks good! Just a couple of comments about the regex and error handling. Testing this threw up another bug that I've tried to address in #14678

@@ -0,0 +1,80 @@
export const embedRegex = /< *script[^>]*src *= *["']?([^"']*)/i;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it likely that we'll get <. script as input? If we do want to strip whitespace, should we use \s?

Copy link
Member Author

Choose a reason for hiding this comment

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

Seems unlikely, but this is the REGEX we already had in there...

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh yes, so it is! Seems odd, but if it's working :)

restaurantId = searchParams.getAll( 'restref' );
}
if ( ! restaurantId || restaurantId.length === 0 ) {
return;
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this works, but should we add a negative test to make sure that we don't get any attributes with some other invalid URL/embed code? I think this is the point we would get to if someone was to paste in something silly like

<script
			  src="https://someotherservice.com/embed.js?params=4"
			  ></script>

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah we should probably, but I think that would be good for a different PR :)

Copy link
Member

@jeherve jeherve 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 nice. I wish we could support regular URLs as well, such as https://www.opentable.com/r/bistro-deryne-budapest?corrid=dae839dd-c3f2-42c1-8796-91668437dbf7 , but that's for another time I guess :)

Before we merge I only have one nitpick to save us some confusion later on.

extensions/shared/test/get-validated-attributes.js Outdated Show resolved Hide resolved
@jeherve jeherve added [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! and removed [Status] Needs Review To request a review from Crew. Label will be renamed soon. [Tests] Needs Tests Some Unit Tests would be really useful to include with this PR. labels Feb 14, 2020
@pablinos
Copy link
Contributor

I wish we could support regular URLs as well, such as https://www.opentable.com/r/bistro-deryne-budapest?corrid=dae839dd-c3f2-42c1-8796-91668437dbf7

Yeah, I don't think we've got a way of getting the restaurant ID from those URLs currently. although it is available in the HTML source of that page, so we could maybe do a request on the server and grab this vie an API endpoint.

@pablinos pablinos added [Status] Needs Review To request a review from Crew. Label will be renamed soon. and removed [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! labels Feb 17, 2020
Copy link
Member

@jeherve jeherve left a comment

Choose a reason for hiding this comment

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

This should be good to go now.

@jeherve jeherve added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Review To request a review from Crew. Label will be renamed soon. labels Feb 17, 2020
@scruffian scruffian merged commit b84c841 into master Feb 18, 2020
@scruffian scruffian deleted the update/opentable-embed-url branch February 18, 2020 13:07
@matticbot matticbot added [Status] Needs Changelog and removed [Status] Ready to Merge Go ahead, you can push that green button! labels Feb 18, 2020
@scruffian scruffian restored the update/opentable-embed-url branch February 18, 2020 13:15
@scruffian scruffian mentioned this pull request Feb 18, 2020
@scruffian scruffian deleted the update/opentable-embed-url branch February 18, 2020 13:48
@scruffian
Copy link
Member Author

r203007-wpcom

jeherve added a commit that referenced this pull request Feb 25, 2020
jeherve added a commit that referenced this pull request Feb 25, 2020
* 8.3 release: changelog

* Changelog: add #14516

* Changelog: add #14574

* Bring in changes from 8.2.1 and 8.2.2

* Update stable version

* Bring in 8.2.3 changes

* Changelog: add #14714

* Changelog: add #14639

* Changelog: add #14678

* Changelog: add #14673

* Changelog: add #14687

* Changelog: add #14704

* Changelog: add #14702

* Changelog: add #14541

* Changelog: add #14657

* Changelog: add #14622

* Changelog: add #14582

* Changelog: add #14638

* Changelog: add #14633

* Changelog: add #14571

* Changelog: add #14592

* Changelog: add #14539

* Changelog: add #14514

* Changelog: add #14643

* Changelog: add #14494

* Changelog: add #13739

* Changelog: add #14707

* Changelog: add #14736

* Changelog: add #14706

* Changelog: add #14730

* Changelog: add #14685

* Changelog: add #14727

* Changelog: add #14711

* Changelog: add #14742

* Changelog: add #14746

* Changelog: add #14725

* Changelog: add #13999

* Changelog: add #14740

* Changelog: add #14759

* Changelog: add #14703

* Changelog: add #14753

* Changelog: add #14754

* Changelog: add #14645

* Cahngelog: add #14599
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] OpenTable [Focus] Blocks Issues related to the block editor, aka Gutenberg, and its extensions developed in Jetpack Touches WP.com Files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants