Skip to content

Forms: Add separate file dropzone block - #42973

Closed
edanzer wants to merge 6 commits into
trunkfrom
update/file-field-block
Closed

edanzer wants to merge 6 commits into
trunkfrom
update/file-field-block

Conversation

@edanzer

@edanzer edanzer commented Apr 8, 2025 •

Copy link
Copy Markdown
Contributor

Alternative on top of global styles refactor:

Proposed changes:

The new file upload block was done in a way that's compatible with the upcoming refactor to form fields (see here and here).

Summary:

  • For the file upload field, we had some markup divs for the dropzone, and we were outputting InnerBlocks inside of those divs. That means we could not include a future Label block in InnerBlocks as it would be in the drop zone.
  • The refactor creates a new Dropzone block and moves the dropzone markup there.
  • The file upload block now outputs a JetpackFieldLabel component + InnerBlocks with Dropzone.
  • When the big PRs above are merged, we can delete the JetpackFieldLabel component, and instead output both Label and Dropzone components within InnerBlocks.

NOTE: As the file field block is not yet released I did not worry about backward compatibility or deprecation or migration of blocks. So past file upload blocks you've inserted on test forms will likely no longer work.

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

There's a good discussion on Slack here: p1743497100111579-slack-C086RGTJT1D

There's a very good summary in the video call in that thread around the 41 minute mark.

Does this pull request change what data or activity we track or use?

No.

Testing instructions:

This is a refactor. The underlying blocks are different, but otherwise the block should behave the same way on the frontend and editor.

  • Add a page with a form block
  • Add a file upload block, and confirm it renders correctly in the editor and you can edit the content of the dropzone (which still load core image and paragraph blocks)
  • Save and test the frontend. Confirm file uploads still work as before.

@edanzer edanzer added [Status] In Progress Task [Pri] Normal [Block] Form Form block (also see Form package label) [Package] Forms [Feature] Forms Blocks Blocks designed to streamline user input and engagement, such as contact, newsletter sign-ups, etc. labels Apr 8, 2025
@edanzer
edanzer requested review from a team and aaronrobertshaw April 8, 2025 20:25
@edanzer edanzer self-assigned this Apr 8, 2025
@github-actions github-actions Bot added [Feature] Forms [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ labels Apr 8, 2025
@github-actions

github-actions Bot commented Apr 8, 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!


Jetpack plugin:

The Jetpack plugin has different release cadences depending on the platform:

  • WordPress.com Simple releases happen as soon as you deploy your changes after merging this PR (PCYsg-Jjm-p2).
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly:
    • Scheduled release: June 3, 2025
    • Code freeze: June 2, 2025

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@aaronrobertshaw We are still outputting a JetpackFieldLabel component just above as part of this block.

Given the new field structures in your PRs, I think we'd just (a) remove that JetpackFieldLabel component and (b) update the InnerBlocks to contain Label + Dropzone instead of just Dropzone. I would think we can just update this file after your work is merged, but before the file upload block is fully released/exposed to users.

If helpful, as a test, I could create a draft PR, branched off your work, that contains the file upload and dropzone blocks as they are in this PR, but with the change above for InnerBlocks, to confirm it works as expected?

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.

That sounds right to me.

A block can only have one set of inner blocks. Given we are moving to inner blocks for all fields, this file field will need to have a single set of inner blocks which as noted would be the Label + Dropzone blocks.

I would think we can just update this file after your work is merged, but before the file upload block is fully released/exposed to users.

This is the main point of friction between the concurrent work on inner blocks and the file field, making sure they are aligned here so that there is only a single roll out of the file field and it doesn't immediately require a deprecation to migrate inner blocks.

If helpful, as a test, I could create a draft PR, branched off your work

I think that would be great. It should help accelerate bringing things together.

Also, the inner blocks isn't "my" work, we all need to own it as in a couple of weeks I'll be AFK for a few months.

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.

One other note, if you're basing the proposed PR off #42889, that PR doesn't register the new inner blocks yet. That's done in #42890 mostly due to trying to draw a line such that the new blocks weren't exposed or used until ready.

That might change soon though if we do want to develop with the new blocks such as with the file field.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I can move this file out of it's own folder since it is just one file now. Convention in this package would just be to rename this file jetpack-field-file.js and put it directly under components/

I partly wanted to keep it to ensure a cleaner diff for comparison for now.

@aaronrobertshaw aaronrobertshaw Apr 9, 2025 •

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.

Ideally, this package would follow general WordPress and core conventions with each block in its own dedicated folder.

This is something that we are actually moving towards via #42889 & #42890

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That definitely works for me. I'll keep it in its own folder.

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.

Sounds like a plan 👍

I think it makes more sense if the file field is updated to use complete inner blocks i.e. the Label block too. Then all blocks using the inner blocks structure will have their own folder as per #42890.

@aaronrobertshaw aaronrobertshaw 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.

Thanks for the work here @edanzer, it's a great start 👍

The more I looked at the changes here the more it seems like the best approach would be to create the PR using the new inner blocks you proposed earlier.

A few other random thoughts:

  • The label doesn't render in the frontend but that also seems to be a problem on trunk. Either way, I'd expect that needs fixing.
  • Saving a post with the file field block in it and reloading loses the content of the dropzone block.
  • The inner image results in a block validation error which might explain the above lose of content appearing in the editor
  • It's probably better to consistently use hooks for block props and inner block props rather than mix-and-match between useInnerBlocksProps and InnerBlocks. It makes the blocks much harder to reason about and debug.
  • The Dropzone block itself should represent the container for its inner blocks rather than adding extra unnecessary markup. This would also provide more control e.g. the Group block offers positioning controls and block styles etc that don't make a lot of sense in the context of the dropzone block.
    • The dropzone block could contain the default styles applied to the group by adding them as a block attribute default e.g. attributes.style.default
    • The dropzone block can then also adopt the block supports that make sense for it via supports.
  • is-style-default shouldn't be manually added anywhere the default block style is really the absence of a selected block style. It's a bit of a Gutenberg quirk that is-style-default gets added when toggling block styles on and off.

It might be easier to implement the full inner blocks approach (using the proposed Label block) and follow the examples set in #42890. I suspect rendering extra markup around the inner blocks content while also making the block wrapper the sole container could be tricky.

@aaronrobertshaw

Copy link
Copy Markdown
Contributor

To help get the ball rolling on the alternate PR proposed, I've thrown up a quick exploration based off #42890. Hopefully, that might help inform or assist with creating the new PR.

Feel free to use or discard any of that as you see fit @edanzer

@edanzer
edanzer force-pushed the update/file-field-block branch from 2c3c0cf to bfc6467 Compare April 15, 2025 17:44
@github-actions

github-actions Bot commented Apr 15, 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 update/file-field-block branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack update/file-field-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

@jp-launch-control

jp-launch-control Bot commented Apr 15, 2025 •

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 2 files.

File Coverage Δ% Δ Uncovered
projects/packages/forms/src/blocks/contact-form/child-blocks.js 0/74 (0.00%) 0.00% 3 ❤️‍🩹
projects/packages/forms/src/blocks/contact-form/components/jetpack-field-file/index.js 0/9 (0.00%) 0.00% -1 💚

1 file is newly checked for coverage.

File Coverage
projects/packages/forms/src/blocks/contact-form/components/jetpack-dropzone/index.js 0/5 (0.00%) 💔

Full summary · PHP report · JS report

If appropriate, add one of these labels to override the failing coverage check: Covered by non-unit tests Use to ignore the Code coverage requirement check when E2Es or other non-unit tests cover the code Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage.

@edanzer
edanzer force-pushed the update/file-field-block branch from 61d0900 to 9c4a6ab Compare April 16, 2025 17:12
@simison simison added the DO NOT MERGE don't merge it! label May 15, 2025
@simison

simison commented May 23, 2025

Copy link
Copy Markdown
Member

Closing in favor of #43114

@simison simison closed this May 23, 2025
@simison
simison deleted the update/file-field-block branch May 23, 2025 12:35
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) DO NOT MERGE don't merge it! [Feature] Forms Blocks Blocks designed to streamline user input and engagement, such as contact, newsletter sign-ups, etc. [Feature] Forms [Package] Forms [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Pri] Normal Task

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants