Skip to content

Adding Gutenberg support to Publicize - #9934

Closed
c-shultz wants to merge 48 commits into
masterfrom
add/publicize-gutenberg
Closed

c-shultz wants to merge 48 commits into
masterfrom
add/publicize-gutenberg

Conversation

@c-shultz

@c-shultz c-shultz commented Jul 18, 2018 •

Copy link
Copy Markdown

This Pull Request contains the changes from #9144 but on a branch local to this repo.

==== Original description follows ===

Fixes #9039 (No Publicize form in Gutenberg)
Dependencies:

Changes proposed in this Pull Request:

Summary

Bringing Jetpack's Publicize feature to the Gutenberg editor! ---
image

Without this PR, Publicize invisibly shares all new Gutenberg posts to all connected social accounts.

Front-End Design Note

The design is based heavily on @MichaelArestad's post-publish design concept. The desired long-term direction for Publicize is to incorporate it in the post-publish panel (after the user publishes the post), but on this PR, as a first iteration, it is being placed in the pre-publish panel.

Architecture Notes

This PR touches a lot of files and there's several early commits that were taking the design in a different direction. In an effort to make review easier, I'll try to distill the list changes into the most important new content and describe how that's hooked into existing content:

  • This PR implements the Publicize form as React-based UI, with components implemented in newly created modules\publicize\assets\gutenberg_client directory
  • Publicize form is hooked into Gutenberg via Slot-Fill
  • Newly created jetpack\modules\publicize\class-jetpack-publicize-gutenberg.php does the setup for the new UI.
    • Registers new UI JS to be loaded with Gutenberg editor
    • Registers REST field on the post endpoint to pass in Publicize title and connections form options when saving post:
      image
    • Registers new Ajax endpoint wp_ajax_get_publicize_connections to expose connection list so client can refresh connections
  • Depends on try/publicize-decouple-ui (PR Decouple Publicize connection list access from UI scripts #9466) to expose connection data access methods

Testing instructions:

  1. Checkout this branch and merge dependended on branch:
    git checkout add/gutenberg-publicize && git merge try/publicize-decouple-ui --no-commit
  2. Checkout Gutenberg PR #5795 and build to enable pre-publish extensibility
  3. Activate Gutenberg and Jetpack
  4. Create new post
  5. Click "Publish" to get Publicize form in pre-publish sidebar
  6. Try stuff:
    • Add connections
    • Open settings
    • Edit message
    • Check/uncheck connections
    • Refresh connections
    • Publish post
    • Check social accounts for post and message
    • Try changing previously published/shared post to draft and re-sharing (Publicize should be disabled)
    • Try Publicize in classic editor to make sure nothing changed

c-shultz added 30 commits July 12, 2018 16:04
Extends Publicize module to add a REST endpoint where a post can be published
without triggering social sharing with Publicize. This is accomplished by
marking the post with a meta key ("_NO_PUBLICIZE") which is used to later filter
out post so it's not publicized. This commit adds back-end PHP to expose
endpoint along with a new JavaScript file that exposes this functionality in a
function call.
Corrects meta key name stored to PUBLICIZE_BLOCK_META_KEY.
publicize/posts/<post_id>/publish-wo-publicize endpoint being replaced with
publicize/posts/<post_id>/flag-no-publicize endpoint. The new endpoint removes
the publish action and simply flags a post so that it will not be later publicized.
This removes the need to replace the Gutenberg publish endpoint, and will simply
need to be called JUST before Gutenberg publish instead.
Normal conventions appear to be lower case for WordPress meta key names.
_NO_PUBLICIZE becomes _no_publicize. Simple as that.
To support asynchronous (publish a post and then possibly later publicizing it),
a custom REST endpoint is being created from the Publicize module that submits a
publicize request to the WPCOM REST API.
Makes a trivial whitespace/punctuation change to a function header Docblock to
make phpcs happy.
…g posts

Experimental Gutenberg editor update in c-shultz:try/publicize-integration
provides X-WP-Source='Gutenberg' HTTP header to differentiate posts. This
vastly simplifies the task of detecting if post came from Gutenberg.
Removing publicize/posts/<post_id>/flag-no-publicize because there's
no longer a need for it with this approach.
Hooking into Gutenberg newly created post-publish sidebar slot to display simple form for sharing a post after it is published. The JavaScript/HTML for the form is just a rough prototype to prove that the hook functions. Currently, the button does not trigger a post to be shared. That will have to come later.
This is a significant iteration on the client-side of Publicize for Gutenberg.
This modularizes the UI into several React components to eventually allow the
user to view/edit sharing message text, view/edit connection list,
and view sharing results. The UX is currently very rough: no loading
indication is yet provided, and results are not yet available, but
the basic foundation is there.
This moves the Gutenberg extensiblity to Gutenberg's pre-publish flow. File/class names
are updated accordingly. This change ports over the classic editor's Publicize form
into React components. Basic Publicize functionality is now available (title edit
and connection selection). Additional styling is still required and dynamic
connection creation is not yet supported.
Removes current list of connections from Publicize panel title bar. This functionality
was a carry over from classic editor, but did not display well in Gutenberg UI.

props @eliorivero
Porting over another classic editor Publicize feature to Gutenberg:
social connections are now tested on page load via an AJAX request.
Any failed tests will result in a display to the user that allows them
to click to refresh the connection before publishing.
Adding list of services which is displayed instead of sharing
form for when user does not have any services connected. Separates
out higher level PublicizePanel from notification and form components
to keep things somewhat modular.
Previously, publicize title/connections were passed from the editor
to the backend via $_POST (for Gutenberg and classic editor). This
allowed the back-end handling to be the same for both Gutenberg and
classic editor Publicize. A recent Gutenberg PR (#5971) changed
the api request format so that post data was passed in HTTP payload
instead of $_POST. Which broke the Publicize form in Gutenberg.
This commit registers a new 'publicize' REST field
for the 'post' endpoint. The update callback for the 'publicize'
field handles the Publicize logic directly instead of relying on
legacy $_POST processing that classic editor uses. The state handling
for PublicizeForm component is totally revamped in support of this
change. As part of the data handling improvement, the form state
is now stored only in editor only. withState and withDispatch are
utilized to prevent state data duplication within PublicizeForm component.

props @youknowriad
Gutenberg client .jsx files previously failed numerous
eslint checks. This change enables eslint for modules/**/*.jsx
and subsequently fixes the JS to pass all linting checks. There
should be no functional differences after making this change.
Creates new 'wp_ajax_get_publicize_connections'
Ajax endpoint to allow connections to be refreshed
by the client. Adds "refresh" button in UI
to trigger the refresh manually, and also adds
"settings" button to pop-up a window and open the
settings page. Closing this pop-up will trigger an
automatic connection list refresh.
Publicize request processing was on a register_rest_field callback.
This callback occurred right after a post is published, which is
too late because Publicize actions occur when post is published.
This resulted in missed Publicize settings if a post was not
lucky enough to be saved just before it was published.
This change moves the 'publicize' request field processing to
a 'rest_pre_insert_post' filter hook, which occurs right
before a post is saved/published.
Fixing an indentation error in Publicize_UI::get_filtered_connection_data().
Adding some missing DocBlocks and cleaning up some minor ESLint issues.
Connection request Ajax endpoint didn't have the current $post
in context, so it couldn't properly check if the post was already
shared. This caused the Publicize form on the front end to not
be disabled after a post was already published. This commit
adds the post id to the 'wp_admin_get_publicize_connections'
Ajax endpoint to remedy this issue.
Deleting some PHP commented out lines that were accidentally left
in the code.
Adds test coverage for Jetpack_Publicize_Gutenberg::process_publicize_from_rest()
which is the callback that processes the 'publicize' field when it is added
to the 'post' endpoint by the Publicize front-end in Gutenberg.
 - Changes 'Settings' link text to 'Connect another service' and moves to below connection list.
 - Adds sharing sub-title.
 - Moves character count to below message text area.
 - Adds styling to textarea.

props @MichaelArestad
Adds 'modules' directory to linting path so ESLint
will run checks against any .jsx in 'modules'
…enberg.

 - Adds service icon to connection list.
 - Modifies connection text so it shows only connection username.
 - Add '+' icon to connection add link.
 - Adds styling to truncate long connection names.
 - Improves spacing/layout.

props @MichaelArestad
Makes Publicize form values (connection enable/disable, title) persistent
so that closing and then opening the pre-publish panel does not clear out
all user entries.
Sets maximum character limit in Publicize message to 256.
Also makes character limit count down instead of up and
highlights the count message if it reaches zero.
Adds a little padding around the 'characters remaining' count
to give it a little space and make it vertically
centered in gray footer bar.
Adding simple Readme to explain how Publicize flags
posts to be shared not shared by WP.com.
Expose helper method done_sharing_post as a public method
to support direct unit testing (and planned rework).
Adding test coverage for:
 - done_sharing_post: testing flagged and published posts
 - get_services_connected: testing service list
 - get_filtered_connection_data: testing simple connection data with no filtering
@oskosk oskosk added [Feature] Publicize Now Jetpack Social, auto-sharing [Status] Needs Review This PR is ready for review. [Pri] Normal [Focus] Blocks Issues related to the block editor, aka Gutenberg, and its extensions developed in Jetpack labels Jul 18, 2018
@oskosk oskosk added this to the 6.4 milestone Jul 18, 2018
@brbrr

brbrr commented Jul 24, 2018 •

Copy link
Copy Markdown
Contributor

@c-shultz please rebase your PR and make sure the tests are passing in CI

@brbrr brbrr added [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. and removed [Status] Needs Review This PR is ready for review. labels Jul 24, 2018
@c-shultz

Copy link
Copy Markdown
Author

@brbrr, I don't have the extra time to support this PR right now, as I'm focused on efforts on my new team.

@c-shultz c-shultz removed the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Jul 24, 2018
tyxla added a commit to Automattic/wp-calypso that referenced this pull request Jul 31, 2018
This PR adds the Jetpack Publicize extension to the set of Gutenberg extensions, based on the previous work done by @c-shultz in: Automattic/jetpack#9934.

Co-authored-by: Chris Shultz <cs.shultz@gmail.com>
@brbrr brbrr modified the milestones: 6.4, 6.5 Jul 31, 2018
@brbrr

brbrr commented Jul 31, 2018

Copy link
Copy Markdown
Contributor

Since our plan is to build JS (and maybe CSS) within Calypso env - we shouldn't merge this PR as is. JS/CSS part already merged here: Automattic/wp-calypso#26389, the remaining part is to ship PHP code for this block.

Moving this PR into next release.

@jeherve

jeherve commented Oct 15, 2018

Copy link
Copy Markdown
Member

@simison Should this remain opened now that the work moved to Automattic/wp-calypso#26389 ?

@simison simison added the DO NOT MERGE don't merge it! label Oct 15, 2018
@simison

simison commented Oct 15, 2018

Copy link
Copy Markdown
Member

Yeah, I think this can be closed. There might be something that we'd still want to port but it'll remain here safe if we need to.

This PR as is won't be merged anyway so no point keeping it open.

cc @tyxla

@simison simison closed this Oct 15, 2018
@kraftbj
kraftbj deleted the add/publicize-gutenberg branch October 17, 2018 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

DO NOT MERGE don't merge it! Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Feature] Publicize Now Jetpack Social, auto-sharing [Focus] Blocks Issues related to the block editor, aka Gutenberg, and its extensions developed in Jetpack [Pri] Normal Touches WP.com Files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Publicize: Gutenberg integration missing

9 participants