-
Notifications
You must be signed in to change notification settings - Fork 383
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
Use React-based component for Stylesheets box on Validated URL screen #6442
base: develop
Are you sure you want to change the base?
Conversation
8a7b20a
to
a7b5c64
Compare
* @param WP_REST_Request $request Full details about the request. | ||
* @return true|WP_Error True if the request has permission; WP_Error object otherwise. | ||
*/ | ||
public function get_item_permissions_check( $request ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
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.
I was thinking if we could reuse and rename the create_item_permissions_check()
method instead of adding a new checker just for the READABLE
method. Right now, they are the same.
*/ | ||
public function get_validated_url( $request ) { | ||
$post_id = (int) $request['id']; | ||
$validated_url = new ValidatedUrlDataProvider( $post_id ); |
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.
I wasn't sure if it's the best practice to instantiate a Provider
inside a method like here. Other providers are passed to the controller's __construtor
. Or else, maybe the ValidatedUrlDataProvider
shouldn't be a Provider
in the first place?
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.
Any use of new
for something that is not a newable object (i.e. value objects, factories, ...) is not best practice, as we're switching the code over to make use of an injector across the board.
As for your question about the nature of the provider in general, I think the modeling seems to be off.
Best practice would be to have the provider be injected via the constructor, and then have a method that accepts the post ID for which it should provide.
So, following from the name, I'd expect a ValidatedUrlDataProvider
to provide a ValidatedUrlData
object:
$validated_url_data = $this->validated_url_data_provider->for( $post_id );
In your current design the provider is the data it provides, as it receives the post ID already in its constructor. For multiple post IDs, you'd then need not multiple data objects, but multiple provider objects.
Hope this helps.
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.
Your feedback is very helpful, thanks @schlessera!
I've addressed the modelling problem in 5944bbc. According to your suggestion, there's a new ValidatedUrlData
object that's returned by the provider.
The ValidatedUrlData
object is a wrapper for the underlying WP_Post
object. I'm wondering what would be the best model that would cover a potential data layer change from WP_Post
to something else in the future.
$data = [ | ||
'id' => $validated_url->get_id(), | ||
'url' => $validated_url->get_url(), | ||
'date' => $validated_url->get_date(), | ||
'author' => $validated_url->get_author(), | ||
'stylesheets' => $validated_url->get_stylesheets(), | ||
]; |
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.
It's intentional that there's no single implicit $validated_url->get_data()
call. The reasoning is that the REST controller is the place where the response data should be defined explicitly.
20c73be
to
0d765cd
Compare
Codecov Report
@@ Coverage Diff @@
## develop #6442 +/- ##
=============================================
+ Coverage 75.52% 76.04% +0.51%
- Complexity 5987 5999 +12
=============================================
Files 190 266 +76
Lines 18037 19242 +1205
=============================================
+ Hits 13623 14633 +1010
- Misses 4414 4609 +195
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Plugin builds for 26525f8 are ready 🛎️!
|
84fcf86
to
0403e29
Compare
The PR is now rebased onto |
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.
Some minor things I just noticed...
@@ -15,6 +15,7 @@ | |||
'admin.paired_browsing' => \AmpProject\AmpWP\Admin\PairedBrowsing::class, | |||
'admin.plugin_row_meta' => \AmpProject\AmpWP\Admin\PluginRowMeta::class, | |||
'admin.polyfills' => \AmpProject\AmpWP\Admin\Polyfills::class, | |||
'admin.rest_preloader' => \AmpProject\AmpWP\Admin\RESTPreloader::class, |
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 is missing the second service that was added:
'validated_url_rest_controller' => \AmpProject\AmpWP\Validation\ValidatedUrlRESTController::class,
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.
Good catch. I've added it back in 26525f8.
Co-authored-by: Alain Schlesser <[email protected]>
Summary
This PR replaces the server-side rendered "Stylesheet" meta box on the Validated URL screen with a React-based component fed via the REST API.
Tasks list (subject to change):
GET /wp-json/amp/v1/validated-urls/:id/
, that returns the validation data stored in aamp_validated_url
post type. See REST endpoints for AMP validation errors and validated URLs #5552. The response data structure consists of the following fields:id
url
date
author
stylesheets
environment
amp_validated_url
custom post type in theValidatedUrlDataProvider
class.Fixes #6441
Checklist