-
Notifications
You must be signed in to change notification settings - Fork 798
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
Newsletter categories: Render non-interactive newsletter category pills in the editor #32666
Newsletter categories: Render non-interactive newsletter category pills in the editor #32666
Conversation
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available. Once your PR is ready for review, check one last time that all required checks (other than "Required review") appearing at the bottom of this PR are passing or skipped. Jetpack plugin:
|
projects/plugins/jetpack/extensions/blocks/subscriptions/view.scss
Outdated
Show resolved
Hide resolved
projects/plugins/jetpack/extensions/blocks/subscriptions/hooks/use-newsletter-categories.js
Outdated
Show resolved
Hide resolved
projects/plugins/jetpack/extensions/blocks/subscriptions/hooks/use-newsletter-categories.js
Outdated
Show resolved
Hide resolved
const fetchData = async () => { | ||
try { | ||
const newsLetterCategories = await apiFetch( { | ||
url: `https://public-api.wordpress.com/wpcom/v2/sites/${ blogId }/newsletter-categories`, |
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.
We've typically not queried public-api
directly in our blocks. Instead we query a local endpoint that in turn queries WordPress.com (or makes a direct request when we're on WordPress.com). The local endpoints live in projects/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/
.
There is some documentation about it here:
jetpack/projects/plugins/jetpack/extensions/README.md
Lines 262 to 271 in 695768a
## Developing API endpoints for blocks | |
Blocks may need to access information from the site or from WordPress.com, through endpoints. When developing an endpoint for a block in the Jetpack plugin, you can look at past endpoints in `projects/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints` for inspiration. | |
Find out more about developing endpoints in the following resources: | |
- Jetpack APIs Quick Reference Guide PCYsg-CB9-p2 | |
- How to write a REST API endpoint for Jetpack sites in WordPress.com PCYsg-liz-p2 | |
**Note**: if your feature is available in multiple plugins, consider adding the endpoints to a package that will be available to all the plugins that will need it. |
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.
Thanks for the pointers once again @jeherve .
I've made the needed API changes: 596bcef
I do have a question regarding defusion: When I test with the jetpack-downloader, I can see the endpoint file on my WP.COM Simple site. However, even after deleting the existing endpoint, I cannot get it to execute it using the WP.com console. Do files inside wpcom-endpoints
not get loaded on Simple Sites?
It's not a problem for now, since everything works. Just interested.
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 files inside wpcom-endpoints not get loaded on Simple Sites?
Yeah, it's a bit confusing. You'd need to do something like D110282-code (check the last file being added, or other files in that directory for some more examples).
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.
Thank you! It's much cleared now. I'll create a separate patch for WPCOM, removing the endpoint, after the Jetpack release happens on WPCOM.
projects/plugins/jetpack/extensions/blocks/subscriptions/view.scss
Outdated
Show resolved
Hide resolved
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.
Noting that you'll need to look at the failing js tests in extensions/blocks/subscriptions/test/edit.js
before we can merge this:
https://github.com/Automattic/jetpack/actions/runs/6010883027/job/16303218143?pr=32666
Fixed it! And somehow managed to bring in all the labels while doing a rebase 🫠 |
Added a new feature to the subscription block which displays newsletter categories. The added categories are styled and displayed above the subscription form. Also added a new hook to query newsletter categories from the backend. This feature enhances user experience by offering categorized subscribing options. The form width is reduced when categories are displayed for better aesthetics.
Added a new feature to the subscription block which displays newsletter categories. The added categories are styled and displayed above the subscription form. Also added a new hook to query newsletter categories from the backend. This feature enhances user experience by offering categorized subscribing options. The form width is reduced when categories are displayed for better aesthetics.
The changes introduced a new 'enabled' state to the useNewsletterCategories hook. This was done to allow better manipulation of the subscription blocks based on whether the newsletter category function is enabled by the user or not, hence improving user experience when interacting with subscription blocks.
This commit removes the additional two lines of spacing at the beginning of the view.scss file within the subscriptions block. This was done to clean the code and make it adhering to the standard coding practices, which enhances the readability and maintainability.
… client-side fetch This commit introduces a new REST API endpoint for retrieving the newsletter categories. The new endpoint will enable a more seamless and effective integration of these categories in the client-side. Moreover, modifications were also made to the 'trait-wpcom-rest-api-proxy-request-trait.php' file. Now the body for Client::wpcom_json_api_request_as_user is checked if not null. This was done to prevent an error when the body is null. Lastly, the fetch request at 'use-newsletter-categories.js' has been updated to use the new /newsletter-categories endpoint within the local server environment instead of making a direct request to the public API.
In the subscriptions module, a mock function was added in the test/edit.js file. This was done to simulate the behavior of the actual 'useNewsletterCategories' function in the unit tests. This will facilitate the testing process by controlling its response and help in improving the code coverage.
0c52208
to
fc89c1f
Compare
...lib/core-api/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-newsletter-categories-list.php
Outdated
Show resolved
Hide resolved
...lib/core-api/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-newsletter-categories-list.php
Outdated
Show resolved
Hide resolved
...lib/core-api/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-newsletter-categories-list.php
Outdated
Show resolved
Hide resolved
projects/plugins/jetpack/extensions/blocks/subscriptions/view.scss
Outdated
Show resolved
Hide resolved
projects/plugins/jetpack/extensions/blocks/subscriptions/view.scss
Outdated
Show resolved
Hide resolved
projects/plugins/jetpack/extensions/blocks/subscriptions/view.scss
Outdated
Show resolved
Hide resolved
projects/plugins/jetpack/extensions/blocks/subscriptions/edit.js
Outdated
Show resolved
Hide resolved
- Renamed --border-radius to --subscribe-block-border-radius - Removed check of WPCOM
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 job @TimBroddin! Tested and it works as expected.
Hey @jeherve The changes you asked for were made, could you rereview? 🙏 |
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.
Looks good and tests well for me. 👍
…ck-add-newsletter-categories
Closes Automattic/wp-calypso#80904
Proposed changes:
Other information:
Jetpack product discussion
Does this pull request change what data or activity we track or use?
Testing instructions:
For completeness, please test this on WPCOM & Jetpack self hosted.
POST /wpcom/v2/sites/<siteid>/newsletter-categories/<categoryid>