Skip to content

Forms: Rating block - #44094

Merged
dhasilva merged 27 commits into
trunkfrom
add/forms-rating-block
Jul 3, 2025
Merged

dhasilva merged 27 commits into
trunkfrom
add/forms-rating-block

Conversation

@lezama

@lezama lezama commented Jun 25, 2025 •

Copy link
Copy Markdown
Contributor

This pull request introduces a new "Rating" field block for Jetpack Forms, allowing site owners to collect ratings via stars, hearts, smiley, or emoji icons.

Added rating field registration and associated render callbacks in PHP.
Implemented front-end assets including JavaScript interactivity, SCSS styles, icons, and block editor components.
Updated webpack config, block options, and child block registration to include the new rating field.

Fixes #40890

Design: p1HpG7-wTL-p2

Proposed changes:

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:

  • Go to '..'

@github-actions

github-actions Bot commented Jun 25, 2025 •

Copy link
Copy Markdown
Contributor

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 WoA dev 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, select your plugin (Jetpack), and enable the add/forms-rating-block branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack add/forms-rating-block

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] Form Form block (also see Form package label) [Feature] Forms [Package] Forms labels Jun 25, 2025
@github-actions

github-actions Bot commented Jun 25, 2025 •

Copy link
Copy Markdown
Contributor

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.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add a "[Type]" label (Bug, Enhancement, Janitorial, Task).
  • ✅ 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 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!

@jp-launch-control

jp-launch-control Bot commented Jun 25, 2025 •

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 4 files.

File Coverage Δ% Δ Uncovered
projects/packages/forms/src/contact-form/class-contact-form-field.php 601/1025 (58.63%) -3.96% 66 💔
projects/packages/forms/src/blocks/contact-form/class-contact-form-block.php 282/393 (71.76%) -4.33% 23 💔
projects/packages/forms/src/contact-form/class-contact-form-plugin.php 423/1179 (35.88%) 0.00% 7 💔
projects/packages/forms/src/contact-form/class-contact-form.php 581/1010 (57.52%) 0.04% 0 💚

7 files are newly checked for coverage. Only the first 5 are listed here.

File Coverage
projects/packages/forms/src/blocks/field-rating/edit.js 0/6 (0.00%) 💔
projects/packages/forms/src/blocks/field-rating/index.js 0/2 (0.00%) 💔
projects/packages/forms/src/blocks/field-rating/save.js 0/2 (0.00%) 💔
projects/packages/forms/src/blocks/input-rating/edit.js 0/16 (0.00%) 💔
projects/packages/forms/src/blocks/input-rating/index.js 0/3 (0.00%) 💔

Full summary · PHP report · JS report

Coverage check overridden by I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage. .

@lezama
lezama requested a review from Copilot June 26, 2025 14:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request introduces a new "Rating" field block for Jetpack Forms, allowing site owners to collect ratings via stars, hearts, smiley, or emoji icons.

  • Added rating field registration and associated render callbacks in PHP.
  • Implemented front-end assets including JavaScript interactivity, SCSS styles, icons, and block editor components.
  • Updated webpack config, block options, and child block registration to include the new rating field.

Reviewed Changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
projects/packages/forms/tools/webpack.config.blocks.js Updated to enqueue styling for the new rating field.
projects/packages/forms/src/modules/field-rating/view.js Imports interactivity for the rating field.
projects/packages/forms/src/contact-form/class-contact-form-plugin.php Added callback to render the rating field.
projects/packages/forms/src/contact-form/class-contact-form-field.php Extended field rendering to include a new case for rating fields with supporting functions.
projects/packages/forms/src/blocks/options/index.js Included the rating field in the parent block list.
projects/packages/forms/src/blocks/field-rating/* Added full block implementation (edit, save, interactivity, icons, style) for the rating field.
projects/packages/forms/src/blocks/contact-form/class-contact-form-block.php & child-blocks.js Registered the new rating field block and updated child blocks accordingly.
projects/packages/forms/changelog/add-rating-field Added changelog entry for the new field.

@lezama
lezama force-pushed the add/forms-rating-block branch from fa3fc7d to 08f6a34 Compare June 27, 2025 18:09
@lezama lezama added [Status] Needs Review This PR is ready for review. and removed [Status] In Progress labels Jun 27, 2025
@github-actions github-actions Bot added [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. and removed [Status] Needs Review This PR is ready for review. labels Jun 27, 2025
@ilonagl

ilonagl commented Jun 30, 2025

Copy link
Copy Markdown
Contributor
Screenshot 2025-06-30 at 18 38 57 Is this the latest? I wonder if there is a way to test the front-end. Thanks!

@CGastrell
CGastrell force-pushed the add/forms-rating-block branch from be24efa to 20cf614 Compare July 1, 2025 13:57
@dhasilva
dhasilva force-pushed the add/forms-rating-block branch from 504bb0a to ab1e833 Compare July 2, 2025 22:46
@dhasilva dhasilva added [Status] Needs Review This PR is ready for review. I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage. [Type] Feature and removed [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. labels Jul 2, 2025
@ilonagl

ilonagl commented Jul 3, 2025

Copy link
Copy Markdown
Contributor

cc @ederrengifo

@edanzer

edanzer commented Jul 3, 2025

Copy link
Copy Markdown
Contributor

Just tested this. Looking good! I can add the block, change the max number of stars and starting value, and update star colors and sizes.

There are a couple minor questions about the style controls on the side bar, which reference text and typography even though they apply to star icons. Also I wonder about borders - should we be able add/remove or adjust color/size?

I believe those could be handled in follow ups though. My preference would be to merge this as soon as it is in a solid state (and it seems there or close now). Then we can handle other things, individually, as follow ups.

rating-block

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this stars.js file is only imported in the input-rating/edit.js block? If so, should we move this file to that folder instead?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Makes sense

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm wondering a bit about this approach to loading our stars. It seems like an unusual approach, and requires a network request. I think there are also GDPR considerations (Do google fonts violate GDPR?) Not sure what the best alternative is - possibly using svgs? But that may change the architecture of the block markup and behavior.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good question! I'm completely unaware of GDPR issues with Google Fonts, but shouldn't that fall on their lap? This can't be the only place we use Gfonts

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not a big deal, but for all other lines where we invoke render_rating_field(), all the arguments are included in a single line.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Single liners are prone to hide issues due to overflowing the IDE. While our codebase is filled with these type of aberrations, the new linters automatically parse calls into multiple lines when the line length is exceeded. We didn't do this, it was done by the linter and I'd just let that take over little by little :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There's a lot of complex css logic here, and it seems like it could be brittle. I'm having a hard time following it, and it may be needed, but just seems un-ideal.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Some comments there could help, but agree it's not the best

lezama added 3 commits July 3, 2025 13:41
Introduces a new 'Rating (stars)' field block for forms, allowing visitors to select a rating.
enejb and others added 22 commits July 3, 2025 13:41
@CGastrell
CGastrell force-pushed the add/forms-rating-block branch from 092df41 to ede1c8c Compare July 3, 2025 16:41
@dhasilva
dhasilva merged commit e64ceca into trunk Jul 3, 2025
@dhasilva
dhasilva deleted the add/forms-rating-block branch July 3, 2025 22:21
@github-actions github-actions Bot removed the [Status] Needs Review This PR is ready for review. label Jul 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Form Form block (also see Form package label) [Feature] Forms I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage. [Package] Forms

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Forms: star rating

8 participants