Skip to content

Conversation

@miguelpeixe
Copy link
Member

@miguelpeixe miguelpeixe commented Dec 11, 2024

Implements an editor plugin for distributing a post.

image

My original intention was to strictly leverage editPost() and savePost() dispatches to update the distribution post meta and let our short-circuit hook handle validation. This did not work well for error handling, as there was no straightforward way to pass the error message to the editor. Because of that, I switched to an API endpoint.

Selecting connections and distributing

newspack sa ngrok io_wp-admin_post php_post=328 action=edit

newspack sa ngrok io_wp-admin_post php_post=328 action=edit (1)

newspack sa ngrok io_wp-admin_post php_post=328 action=edit (2)

newspack sa ngrok io_wp-admin_post php_post=328 action=edit

newspack sa ngrok io_wp-admin_post php_post=328 action=edit (3)

Updating connections

newspack sa ngrok io_wp-admin_post php_post=326 action=edit

newspack sa ngrok io_wp-admin_post php_post=326 action=edit (1)

newspack sa ngrok io_wp-admin_post php_post=326 action=edit

newspack sa ngrok io_wp-admin_post php_post=326 action=edit (3)

Error message

newspack sa ngrok io_wp-admin_post php_post=327 action=edit

Distributing an unsaved post

To prevent distributing an outdated version of the post, if the post has unsaved changes we'll enforce a post save before distributing:

newspack sa ngrok io_wp-admin_post php_post=352 action=edit

A lot of nodes

newspack sa ngrok io_wp-admin_post php_post=352 action=edit (1)

Testing

This PR also inaugurates javascript assets to the plugin. Before anything, make sure to run npm ci && npm run build

  1. Make sure you have a network setup with a hub and 2 nodes and define( 'NEWPACK_NETWORK_CONTENT_DISTRIBUTION', true ); on all instances config
  2. Draft a new post in the hub and click the globe icon as referenced in the first image above
  3. Confirm the nodes are available for distribution
  4. Make changes to the post and confirm the button changes from "Distribute" to "Save & Distribute"
  5. Save the post and confirm the button is back to "Distribute"
  6. Select one node and click "Distribute"
  7. Confirm you get the pending state as in the image above and the snackbar notice on success
  8. Confirm the selected node is now checked and disabled
  9. Click "Select all" and confirm the other node gets selected
  10. Click Distribute and confirm you get the same successful result
  11. Confirm on the nodes that the post is distributed
  12. Edit the post in one of the nodes and confirm the editor plugin (globe icon) is not available

Multiple nodes

  1. Replace line 57 of src/content-distribution/distribute/index.js with:
	const sites = [];
	for( let i = 0; i < 100; i++ ) {
		sites.push( `https://node${ i + 1}.local` );
	}
  1. Edit a post and confirm the plugin sidebar renders with a scrollbar

Error handling

  1. Add the following to line 78 of includes/content-distribution/class-outgoing-post.php:
return new WP_Error( 'test_error', 'This is my error message. Try distributing again.' );
  1. Attempt to distribute a post via the editor and confirm you get the error notice.

miguelpeixe and others added 12 commits December 9, 2024 08:52
* feat: content distribution class

* feat: insert linked post

* refactor: use site url instead of ID

* chore: lint

* feat: return errors on post insert

* chore: lint

* feat: support webhooks request priority

* feat: unlink functionality and unit tests

* chore: lint

* feat: introduce 'linked_post_inserted' hook and listener

* chore: lint

* fix: listener hook name

* fix: typo

* chore: better docblocks

* chore: remove redundant code

* test: persist post hash

* test: remove unnecessary assertion

* refactor: distribute_post() to use handle_post_updated() method

* refactor: post hash is now network post id

* chore: update comment
The old classname "Linked_Post" was still used instead of
"Incoming_Post" causing sync to fail.

## How to test
Probably eyeballing is enough
Base automatically changed from epic/content-distribution to trunk December 12, 2024 13:00
@miguelpeixe miguelpeixe changed the base branch from trunk to feat/content-distribution-control-meta December 13, 2024 19:21
@miguelpeixe
Copy link
Member Author

We have talked about this before and concluded that we do want this! That removes some complexity on status handling... and also it's how Distributor does it

Sounds good! How about messaging? We just leave the button disabled or do we add something extra?

@miguelpeixe
Copy link
Member Author

Added the non-publish post restriction in 0f7f73d

@miguelpeixe
Copy link
Member Author

We have talked about this before and concluded that we do want this! That removes some complexity on status handling... and also it's how Distributor does it

Sounds good! How about messaging? We just leave the button disabled or do we add something extra?

Or maybe we do a "Publish & Distribute" in this case, instead of disabling it 🤔

@thomasguillot
Copy link
Contributor

thomasguillot commented Dec 18, 2024

Or maybe we do a "Publish & Distribute" in this case, instead of disabling it

Too dangerous. A publisher might find useful the "pre-publish checks" sidebar and add tags etc...

@thomasguillot
Copy link
Contributor

thomasguillot commented Dec 18, 2024

Sounds good! How about messaging? We just leave the button disabled or do we add something extra?

I'd change the description to something like: "This [post_type_singularname] has not been published yet. Please publish the [post_type_singularname] before distributing it to any connections."

@leogermani
Copy link
Contributor

I'd change the description to something like: "This [post_type_singularname] has not been published yet. Please publish the [post_type_singularname] before distributing it to any connections."

Ah, I meant to comment on that. "Connections" is a Distributor plugin concept. Not sure if we need/want to use that here... they are "sites in the network"... or just "sites"

@miguelpeixe
Copy link
Member Author

"Network site(s)" is a common occurrence. Maybe that?

@miguelpeixe
Copy link
Member Author

miguelpeixe commented Dec 18, 2024

Here's an example with the new paragraph using the proposed "network site" label:

image

Updated in 5f57b6a, let me know if I should tweak the "connection/network site" labeling.

cc @leogermani @thomasguillot

@leogermani
Copy link
Contributor

For the yellow notice saying that the post is distributed to other sites, I think it will break the UI if the list has too many sites (not that many actually)... Maybe just display the number of sites? Is it possible to add a "Manage" link that opens the sidebar panel?

@miguelpeixe
Copy link
Member Author

miguelpeixe commented Dec 18, 2024

For the yellow notice saying that the post is distributed to other sites, I think it will break the UI if the list has too many sites (not that many actually)... Maybe just display the number of sites?

Good call! Updated in 649cf97

image

Is it possible to add a "Manage" link that opens the sidebar panel?

Unfortunately, the notice only supports a string. We also have to give up on the icon for the linked post notice...

Copy link
Member

@naxoc naxoc left a comment

Choose a reason for hiding this comment

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

Tested again and it works great. I'm also much happier with wording and the before-published behaviour 👍

use Newspack_Network\Content_Distribution\Incoming_Post;
use Newspack_Network\Content_Distribution\Outgoing_Post;
use WP_Post;
use WP_Error;
Copy link
Member

Choose a reason for hiding this comment

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

This one is unused ;)

Copy link
Member Author

Choose a reason for hiding this comment

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

Whoops! Removed in 9a1516f

@miguelpeixe
Copy link
Member Author

Thank you @naxoc, @thomasguillot, and @leogermani for your reviews here! 🙇

@miguelpeixe miguelpeixe merged commit e10aef4 into trunk Dec 20, 2024
3 of 4 checks passed
@miguelpeixe miguelpeixe deleted the feat/distribute-ui branch December 20, 2024 14:45
@github-actions
Copy link

Hey @miguelpeixe, good job getting this PR merged! 🎉

Now, the needs-changelog label has been added to it.

Please check if this PR needs to be included in the "Upcoming Changes" and "Release Notes" doc. If it doesn't, simply remove the label.

If it does, please add an entry to our shared document, with screenshots and testing instructions if applicable, then remove the label.

Thank you! ❤️

matticbot pushed a commit that referenced this pull request Jan 10, 2025
# [2.4.0-alpha.1](v2.3.4...v2.4.0-alpha.1) (2025-01-10)

### Bug Fixes

* **content-distribution:** post insertion hook and additional meta for incoming post event ([#173](#173)) ([48df13c](48df13c))
* load text domain on init hook ([#171](#171)) ([01fb89c](01fb89c))

### Features

* content distribution - experimental ([#168](#168)) ([dc837d8](dc837d8))
* **content-distribution:** add CLI command for distribute post ([#159](#159)) ([7a43b86](7a43b86)), closes [#155](#155) [#156](#156) [#157](#157) [#160](#160) [#165](#165)
* **content-distribution:** canonical url ([#177](#177)) ([5ca60ce](5ca60ce))
* **content-distribution:** capability and admin page ([#176](#176)) ([5285285](5285285))
* **content-distribution:** control distribution meta and prevent multiple dispatches ([#170](#170)) ([e76a2dc](e76a2dc))
* **content-distribution:** editor plugin for distribution ([#167](#167)) ([e10aef4](e10aef4))
* **content-distribution:** handle status changes ([#166](#166)) ([4af5da1](4af5da1))
* **content-distribution:** log incoming post errors ([#182](#182)) ([74c9119](74c9119))
* **content-distribution:** posts column ([#178](#178)) ([8e07640](8e07640))
* **content-distribution:** reserved taxonomies ([#174](#174)) ([a2c54d2](a2c54d2))
* **content-distribution:** sync comment and ping statuses ([#179](#179)) ([90c5425](90c5425))
* **content-distribution:** sync post meta ([#163](#163)) ([353a3d8](353a3d8))
* **event-log:** collapse data ([#180](#180)) ([956219d](956219d))
* limit purchase of a network membership ([#169](#169)) ([deb2683](deb2683))
@matticbot
Copy link
Contributor

🎉 This PR is included in version 2.4.0-alpha.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

matticbot pushed a commit that referenced this pull request Jan 20, 2025
# [2.4.0](v2.3.4...v2.4.0) (2025-01-20)

### Bug Fixes

* **content-distribution:** post insertion hook and additional meta for incoming post event ([#173](#173)) ([48df13c](48df13c))
* load text domain on init hook ([#171](#171)) ([01fb89c](01fb89c))

### Features

* content distribution - experimental ([#168](#168)) ([dc837d8](dc837d8))
* **content-distribution:** add CLI command for distribute post ([#159](#159)) ([7a43b86](7a43b86)), closes [#155](#155) [#156](#156) [#157](#157) [#160](#160) [#165](#165)
* **content-distribution:** canonical url ([#177](#177)) ([5ca60ce](5ca60ce))
* **content-distribution:** capability and admin page ([#176](#176)) ([5285285](5285285))
* **content-distribution:** control distribution meta and prevent multiple dispatches ([#170](#170)) ([e76a2dc](e76a2dc))
* **content-distribution:** editor plugin for distribution ([#167](#167)) ([e10aef4](e10aef4))
* **content-distribution:** handle status changes ([#166](#166)) ([4af5da1](4af5da1))
* **content-distribution:** log incoming post errors ([#182](#182)) ([74c9119](74c9119))
* **content-distribution:** posts column ([#178](#178)) ([8e07640](8e07640))
* **content-distribution:** reserved taxonomies ([#174](#174)) ([a2c54d2](a2c54d2))
* **content-distribution:** sync comment and ping statuses ([#179](#179)) ([90c5425](90c5425))
* **content-distribution:** sync post meta ([#163](#163)) ([353a3d8](353a3d8))
* **event-log:** collapse data ([#180](#180)) ([956219d](956219d))
* limit purchase of a network membership ([#169](#169)) ([deb2683](deb2683))
@matticbot
Copy link
Contributor

🎉 This PR is included in version 2.4.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants