Skip to content
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

Merged
merged 9 commits into from
Sep 7, 2023

Conversation

TimBroddin
Copy link
Contributor

@TimBroddin TimBroddin commented Aug 24, 2023

Closes Automattic/wp-calypso#80904

Proposed changes:

  • This adds the newsletter categories as pills in the editor.
CleanShot 2023-08-24 at 16 23 51@2x

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

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.

  1. Checkout this PR and run the command below for WPCOM or build it and run it though JT
  2. Mark some categories as newsletter categories: POST /wpcom/v2/sites/<siteid>/newsletter-categories/<categoryid>
  3. Create a new post/page & add the subscribe block
  4. The newsletter categories should be above the input field

@TimBroddin TimBroddin requested a review from a team August 24, 2023 14:25
@TimBroddin TimBroddin self-assigned this Aug 24, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Aug 24, 2023

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WordPress.com Simple site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta > Jetpack and enable the add/subscription-block-add-newsletter-categories branch.

  • To test on Simple, run the following command on your sandbox:

    bin/jetpack-downloader test jetpack add/subscription-block-add-newsletter-categories
    

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions github-actions bot added [Block] Subscriptions [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ labels Aug 24, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Aug 24, 2023

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ⚠️ All commits were linted before commit.
  • ✅ Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

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.
Then, add the "[Status] Needs Team Review" label and ask someone from your team review the code. Once reviewed, it can then be merged.
If you need an extra review from someone familiar with the codebase, you can update the labels from "[Status] Needs Team Review" to "[Status] Needs Review", and in that case Jetpack Approvers will do a final review of your PR.


Jetpack plugin:

  • Next scheduled release: September 19, 2023.
  • Scheduled code freeze: September 11, 2023.

const fetchData = async () => {
try {
const newsLetterCategories = await apiFetch( {
url: `https://public-api.wordpress.com/wpcom/v2/sites/${ blogId }/newsletter-categories`,
Copy link
Member

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:

## 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.

Copy link
Contributor Author

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.

Copy link
Member

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).

Copy link
Contributor Author

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.

Copy link
Member

@jeherve jeherve left a 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

@github-actions github-actions bot added [Tests] Includes Tests [Block] AI Assistant [Block] Paywall [Boost Feature] Optimizations [Feature] Extra Sidebar Widgets [Feature] Masterbar WordPress.com Toolbar and Dashboard customizations [Feature] Memberships [Feature] Photon aka "Image CDN". Feature developed in the Image CDN package and shipped in multiple plugins [Feature] Subscriptions All subscription-related things such as paid and unpaid, user management, and newsletter settings. [Feature] Tiled Gallery A different way to display image galleries on your site, in different organizations and shapes. [Feature] WPCOM API [Focus] Compatibility Ensuring our products play well with third-parties [JS Package] AI Client [JS Package] Analytics [JS Package] Base Styles [JS Package] Babel Plugin Replace Textdomain [JS Package] Boost Score Api [JS Package] Components labels Aug 29, 2023
@TimBroddin
Copy link
Contributor Author

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.
@jeherve jeherve added [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! and removed [Status] Needs Team Review labels Aug 30, 2023
- Renamed --border-radius to --subscribe-block-border-radius
- Removed check of WPCOM
Copy link
Contributor

@phcp phcp left a 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.

@phcp phcp added [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. and removed [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! labels Aug 31, 2023
@phcp phcp requested a review from jeherve August 31, 2023 14:27
@TimBroddin
Copy link
Contributor Author

Hey @jeherve

The changes you asked for were made, could you rereview? 🙏

Copy link
Member

@jeherve jeherve left a 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. 👍

@jeherve jeherve added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. labels Sep 7, 2023
@TimBroddin TimBroddin enabled auto-merge (squash) September 7, 2023 12:47
@TimBroddin TimBroddin merged commit 4f5da6a into trunk Sep 7, 2023
52 of 53 checks passed
@TimBroddin TimBroddin deleted the add/subscription-block-add-newsletter-categories branch September 7, 2023 13:02
@github-actions github-actions bot added this to the jetpack/12.6 milestone Sep 7, 2023
@github-actions github-actions bot removed the [Status] Ready to Merge Go ahead, you can push that green button! label Sep 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Actions GitHub actions used to automate some of the work around releases and repository management [Block] Subscriptions [Feature] Subscriptions All subscription-related things such as paid and unpaid, user management, and newsletter settings. [Feature] WPCOM API [Package] Blocks [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Tests] Includes Tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Newsletter Categories: Render non-interactive newsletter category pills in the editor
3 participants