-
Notifications
You must be signed in to change notification settings - Fork 799
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
Decouple Publicize connection list access from UI scripts #9466
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just made a really quick look for small fish. It reads well with some minor nitpicks. Not approving since I don't have a chance right now to actually test it.
* data directly as array so it can be retrieved for static HTML generation | ||
* or JSON consumption. | ||
* | ||
* @since 5.9.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick, probably should be 6.2 now.
public function get_filtered_connection_data( $post_id = null ) { | ||
$connection_list = array(); | ||
|
||
$post = get_post( $post_id ); // Defaults to current post if $post_id is null. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need a null
check in case there is no current post?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. Very good point. I need to work out what needs to happen in this case.
I'm just thinking out loud here: Post ID is used to disable the connection checkbox if the post has already been shared to some or all connections. A null post ID may come in to play with a new post. In that case, I think we should just leave all connection checkboxes enabled, since the new post clearly hasn't been shared yet.
I'm going to do some testing around this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was indeed an issue. Just pushed in a fix with associated test cases. Thanks!
// those connections, don't let them change it | ||
$cmeta = $this->get_connection_meta( $connection ); | ||
$hidden_checkbox = false; | ||
if ( !$done && ( 0 == $cmeta['connection_data']['user_id'] && !current_user_can( $this->GLOBAL_CAP ) ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick, coding standards (need space)
* far as Publicize is concerned. Jetpack uses this approach. All published posts in Jetpack | ||
* have Publicize disabled. | ||
* | ||
* @since 5.9.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bump needed.
* | ||
* @return bool True if post has already been shared by Publicize, false otherwise. | ||
*/ | ||
function done_sharing_post( $post_id = null ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick, braces needed on the function declaration line
function done_sharing_post( $post_id = null ) | ||
{ | ||
global $publicize_ui; | ||
$post = get_post( $post_id ); // Defaults to current post if $post_id is null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another null check?
* Retrieves current available publicize service connections | ||
* with associated labels and URLs. | ||
* | ||
* @since 5.9.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bump
/** | ||
* Current test user id produced by factory method. | ||
* | ||
* @since 5.9.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
few more bumps in this file
8f9b81d
to
0d64022
Compare
This PR needs a rebase :) |
We'll have to punt this one for the next release maybe |
@c-shultz could you create a version of this branch but on this same repo instead of being a branch on a fork ? |
Sure. I should be able to take care of that today! |
Connection data access is intermingled with HTML generation. This moves connection data access out of ui.php and into publicize-jetpack.php to decouple it from the UI. This is a cleaner design and allows the data to be accessed for other purposes.
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
Adding unit tests for three existing filters in Publicize: - 'wpas_submit_post?' - 'publicize_checkbox_global_default' - 'publicize_checkbox_default' These filters were previously difficult to test since they were being applied within HTML generation code. Now that HTML generation is separated from the connection retrieving/filtering, it is a good time to add unit tests.
A previous iteration had method 'get_filtered_connection_data' in Publicize_UI, so the test and other references were calling it from there. This updates those references now that the method has been moved into Publicize class.
'disabled' parameter value was from 'get_filtered_connection_data' return was an HTML string an an early iteration but is now a boolean. This commit updates the associated test case to check new data format.
HTML indenting was incorrect in Publicize_UI::get_metabox_form_connected(). This commit fixes the whitespace.
Updated Publicize form generation to use new boolean parameter value to correctly disable checkboxes when required.
Cleaning up some minor issues identified by phpcs in get_filtered_connection_data. This function is legacy code that has been moved over, so it continues to have code style issues. More major refactoring would be necessary to fix the rest...
Cleaning up low-hanging fruit on coding styles, including: - whitespace - comments - yoda conditions
Modifies Publicize_UI::get_filtered_connection_data() to gracefully handle the case where there is no current post and the post_id parameter is unset. This condition is now handled by not disabling any of the connection checkboxes. Previously, this case would cause a PHP error. Also adding test cases to exercise this case. props @kraftbj
Reining in some especially long lines in Publicize_UI::get_filtered_connection_data(). No functional changes intended.
d66b561
to
2d53c34
Compare
@oskosk, I rebased the forked branch and then merged it onto a fresh branch in this repo: https://github.com/Automattic/jetpack/compare/update/publicize-decouple-ui |
@oskosk do we need a new PR for this? |
Thank you for creating a separate branch, I'm going to close this in favor of the new one: #9955 |
Fixes #9039 (along with PR #9144)
Note: These changes are standalone but they are a dependency of #9144. They were originally contained in #9144, but are being pulled out for for clarity/organization because that PR was getting too large and complex.
Changes proposed in this Pull Request:
This PR separates the Publicize connection list processing from the HTML generation for the UI form.
Before this PR:
The method
Publicize_UI::get_metabox_form_connected()
inui.php
retrieved and filtered the connection list and then also generated the HTML form.After this PR:
This PR leaves the HTML generation in
Publicize_UI::get_metabox_form_connected()
but moves the connection gathering/filtering to new methodPublicize::get_filtered_connection_data()
inpublicize-jetpack.php
.Why this is needed:
PR #9144 needs to access the connection list so it can be JSON encoded and utilized in new React-based frontend for Gutenberg. Splitting the connection list retrieval to a separate method allows code reuse between the classic editor HTML generation and the Gutenberg front-end to gather.
The final diff view of these changes looks a little muddled, but the first commit pretty effectively shows the basics of what's being moved where in this PR.
This PR should not affect the Classic Editor in any way.
Unit tests have been added to test connection data fields and to test the three potentially affected filters:
'wpas_submit_post?'
'publicize_checkbox_global_default'
'publicize_checkbox_default'
Testing instructions:
Checkout and test Publicize in Classic Editor to confirm there are no functional changes.
See #9144 for additional testing instructions.
props to @ehg for the design suggestions!