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

Gutenpack: Add/contact form to the gutenberg editor #10537

Merged
merged 31 commits into from
Nov 19, 2018

Conversation

enejb
Copy link
Member

@enejb enejb commented Nov 5, 2018

Fixes #9784

Simplifies the work done by @georgestephanis in #10256

By removing the js code since it should be automatically be included as part of the jetpack blocks.
Now found here Automattic/wp-calypso#27996

Changes proposed in this Pull Request:

Todo:

[ ] Rendering on the front-end (waiting on externals) -
WordPress/gutenberg#11334

Testing instructions:

  1. Connect Jetpack
  2. Visit the editor. Add the new contact form.
  3. Does it work as expected?

Proposed changelog entry for your changes:

Add the contact form to the Gutenberg editor.

@enejb enejb requested a review from a team November 5, 2018 14:32
@matticbot
Copy link
Contributor

Caution: This PR has changes that must be merged to WordPress.com
Please review this diff before merging: D20308-code. (newly created revision)

@jetpackbot
Copy link

jetpackbot commented Nov 5, 2018

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: November 26, 2018.
Scheduled code freeze: November 19, 2018

Generated by 🚫 dangerJS

@jeherve jeherve added [Feature] Contact Form [Status] In Progress [Focus] Blocks Issues related to the block editor, aka Gutenberg, and its extensions developed in Jetpack labels Nov 5, 2018
@jeherve jeherve added this to the 6.8 milestone Nov 5, 2018
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.

Not sure if this is ready for review yet, but I had a small question.

@@ -232,6 +232,97 @@ function __construct() {
*/
wp_register_style( 'grunion.css', GRUNION_PLUGIN_URL . 'css/grunion.css', array(), JETPACK__VERSION );
wp_style_add_data( 'grunion.css', 'rtl', 'replace' );

if ( function_exists( 'register_block_type' ) ) {
Copy link
Member

Choose a reason for hiding this comment

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

Should we use Jetpack_Gutenberg::is_gutenberg_available here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes good call. The plan is to convert things to jetpack_register_block calls which do that check as well.

@jeherve jeherve mentioned this pull request Nov 9, 2018
22 tasks
lezama
lezama previously approved these changes Nov 10, 2018
@lezama lezama added [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. and removed [Status] In Progress labels Nov 12, 2018
@jeherve jeherve modified the milestones: 6.8, 6.7.1 Nov 12, 2018
@enejb enejb force-pushed the add/contact-form-gutenblock-sdk branch from aca0004 to 2bd59a1 Compare November 12, 2018 18:15
@matticbot
Copy link
Contributor

Caution: This PR has changes that must be merged to WordPress.com
Please review this diff before merging: D20308-code. (updated diff)

@lezama lezama requested a review from a team November 12, 2018 19:42
@lezama lezama mentioned this pull request Nov 12, 2018
5 tasks
@georgestephanis georgestephanis added the [Tests] Needs Tests Some Unit Tests would be really useful to include with this PR. label Nov 12, 2018
@enejb
Copy link
Member Author

enejb commented Nov 12, 2018

@georgestephanis Can you elaborate a bit more about the tests that you want to see?

@enejb enejb modified the milestones: 6.7.1, 6.8 Nov 12, 2018
@georgestephanis
Copy link
Member

Given post_content that it renders properly, primarily.

@enejb
Copy link
Member Author

enejb commented Nov 13, 2018

Also Fixes Automattic/wp-calypso#28521

@matticbot
Copy link
Contributor

Caution: This PR has changes that must be merged to WordPress.com
Please review this diff before merging: D20308-code. (updated diff)

@georgestephanis
Copy link
Member

the failing tests seem to be coming from

Argument 1 passed to iterator_to_array() must implement interface Traversable, instance of DOMNodeList given, called in /tmp/wordpress-master/src/wp-content/plugins/jetpack/tests/php/modules/contact-form/test_class.grunion-contact-form.php on line 690 and defined

@matticbot
Copy link
Contributor

D20923-code. (newly created revision)

enejb and others added 4 commits November 15, 2018 22:04
ensure we are exposing the contact form's sub-blocks in block availability data.

the sub blocks will not be in blocks-manifest.json, so we'll need to ensure we
are also including blocks that have been registered internally within jetpack
@roccotripaldi roccotripaldi force-pushed the add/contact-form-gutenblock-sdk branch from 93c213f to 30deca4 Compare November 16, 2018 03:40
@enejb enejb removed the [Tests] Needs Tests Some Unit Tests would be really useful to include with this PR. label Nov 16, 2018
lezama
lezama previously approved these changes Nov 16, 2018
Copy link
Member

@georgestephanis georgestephanis left a comment

Choose a reason for hiding this comment

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

Apart from some very minor stuff, very happy to clear this.

Thanks for the unit tests, refactoring how we're building the html into more manageable chunks, and the new assertions! It looks super cool!

wrapper.appendChild(menu);
<?php endif; ?>
menu.style.display = 'block';
var menu = document.getElementById( 'feedback-export' ),
Copy link
Member

Choose a reason for hiding this comment

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

This and subsequent lines probably shouldn't be indented with spaces?

@@ -2016,6 +2125,10 @@ static function get_compiled_form( $feedback_id, $form ) {
return $compiled_form;
}

static function remove_empty( $single_value ) {
Copy link
Member

Choose a reason for hiding this comment

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

Probably could use docblock to explain, but I assume this is here so that we can leave null false 0 and such that evaluate falsey in the array instead of stripping them out with the '' ?

}
if ( is_array( $val ) ) {
$val = array_filter( $val, array( __CLASS__, 'remove_empty' ) );
$att_strs[] = esc_html( $att ) . '=\'' . implode( ',', array_map( 'esc_html', $val ) ) . '\'';
Copy link
Member

Choose a reason for hiding this comment

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

It's kinda awkward to do '\'' all the time -- any reason to not just do "'" to avoid the escaping?

@enejb enejb dismissed stale reviews from georgestephanis and lezama via 53876cf November 16, 2018 23:26
@georgestephanis georgestephanis merged commit ccda7b6 into master Nov 19, 2018
@enejb enejb deleted the add/contact-form-gutenblock-sdk branch November 19, 2018 15:42
@jeherve jeherve removed [Status] Needs Changelog [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. labels Nov 20, 2018
jeherve pushed a commit that referenced this pull request Nov 20, 2018
* Add the gutenberg contact form gutenberg blocks

* Gutenpack: Add contact form block

* Update form block to use contact-form

* Add do_blocks call to the contact render form

* Add register_contact_form_blocks block method

* Provide default labels

* Updates to fix tests

the default value of a lable should be null of the type is not set

* Minor fixes

* Use the jetpack_register_block call to register the contact form blocks

Make sure we load them before we load the gutenberg blocks

* Bug fix: Only display selections when the option has a value.

* Added tests that show what the form doesn't recieve a lavel that we defaul to the default label.

* Add tests that shows that we remove empty options when we pass an string containing the empty options

* Minor bug fix. Add closing div to the phone field.

* Add support for class added in gutenberg

* Refactored field Render method so that it is easier to follow.

More DRY field render method

* Minor fixes

* Add unitests for output.

* Unit Test fixes so that they work with older version of PHP

* Fix: Add more liberal url validaton

This removed the validation error when a user doesn't add a http:// or https:// infront of the url.

* Improved pattern for the url.

* Revert "Improved pattern for the url."

This reverts commit 105fcca.

* Revert "Fix: Add more liberal url validaton"

This reverts commit 0f1a632.

* Add support for the defaultValue block attribute

* Gutenberg: Conact form

ensure we are exposing the contact form's sub-blocks in block availability data.

the sub blocks will not be in blocks-manifest.json, so we'll need to ensure we
are also including blocks that have been registered internally within jetpack

* Fix the tests again :P

* Fixes indentation of the js code

* Remove comment

* Add php doc block for remove_empty

* Fixes ugly quotes.

* Fix the tests since we are expecting the double quotes now.

* With escaped quotes
@jeherve
Copy link
Member

jeherve commented Nov 20, 2018

Cherry-picked to branch-6.8 in ea44f76

@ockham
Copy link
Contributor

ockham commented Nov 23, 2018

It looks like the Fusion-generated counterpart patch (D20308-code) was never merged to WP.com, which is now causing trouble for a PR of mine that seeks to modify class.jetpack-gutenberg.php. Could someone who authored, reviewed, or merged this PR please take care of that? 😁

@ockham
Copy link
Contributor

ockham commented Nov 23, 2018

Oh, looks like D20308-code doesn't contain the changes that this PR made to class.jetpack-gutenberg.php (possibly because at the time it was merged, that file wasn't on Fusion's list yet). Maybe I can manually re-trigger patch creation...

@ockham
Copy link
Contributor

ockham commented Nov 23, 2018

Fixed, thanks to @enejb's D21287-code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Contact Form [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.

10 participants