Skip to content

Reduce duplicated preset utility implementations#80245

Open
scruffian wants to merge 16 commits into
trunkfrom
issue-80186-v2
Open

Reduce duplicated preset utility implementations#80245
scruffian wants to merge 16 commits into
trunkfrom
issue-80186-v2

Conversation

@scruffian

@scruffian scruffian commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

What?

Reduces duplicated preset utility implementations in the block editor spacing and border radius controls.

Why?

Spacing and border radius controls had overlapping helper logic for identifying preset values, extracting preset slugs, and resolving preset values. Keeping that logic centralized makes future preset behavior changes less likely to drift between controls.

How?

  • Updates spacing helpers to reuse the generic preset-input utilities for preset detection and slug extraction while preserving the public isValueSpacingPreset export for backwards compatibility.
  • Updates border radius preset conversion to reuse the generic preset-input utilities instead of maintaining border-radius-specific copies.
  • Removes now-redundant border radius utility tests that are covered by the generic preset-input utility tests.

Testing Instructions

Run npm run test:unit -- packages/block-editor/src/components/spacing-sizes-control/test/utils.js packages/block-editor/src/components/border-radius-control/test/utils.js packages/block-editor/src/components/preset-input-control/test/utils.js.

Testing Instructions for Keyboard

No keyboard-specific testing is needed because this refactors shared helper implementations without changing UI behavior.

Screenshots or screencast

Not applicable.

Use of AI Tools

This PR was authored with assistance from OpenAI Codex in Conductor; the generated changes were reviewed before submission.

@scruffian scruffian requested a review from ellatrix as a code owner July 14, 2026 10:42
@github-actions github-actions Bot added [Package] Block editor /packages/block-editor [Package] Edit Site /packages/edit-site labels Jul 14, 2026
@github-actions

github-actions Bot commented Jul 14, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: scruffian <scruffian@git.wordpress.org>
Co-authored-by: jeryj <jeryj@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

github-actions Bot commented Jul 14, 2026

Copy link
Copy Markdown

Size Change: +33 B (0%)

Total Size: 7.72 MB

📦 View Changed
Filename Size Change
build/modules/content-types/index.min.js 164 kB -11 B (-0.01%)
build/scripts/block-editor/index.min.js 421 kB +44 B (+0.01%)

compressed-size-action

@github-actions github-actions Bot added [Package] Block library /packages/block-library and removed [Package] Edit Site /packages/edit-site labels Jul 14, 2026
@scruffian scruffian added the [Type] Code Quality Issues or PRs that relate to code quality label Jul 14, 2026
@scruffian scruffian self-assigned this Jul 14, 2026
@github-actions github-actions Bot removed the [Package] Block library /packages/block-library label Jul 14, 2026
@github-actions

github-actions Bot commented Jul 14, 2026

Copy link
Copy Markdown

Flaky tests detected in 261d827.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/29420557510
📝 Reported issues:

@scruffian scruffian changed the title Reduce duplicated helper implementations Reduce duplicated preset utility implementations Jul 15, 2026
@scruffian scruffian requested a review from glendaviesnz July 15, 2026 13:58

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

Functionally looks good. Approving but I think we should remove the getPresetSlug test.

} );

describe( 'getSpacingPresetSlug', () => {
describe( 'getPresetSlug', () => {

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.

Haven't looked yet, but I assume these tests already exist within getPresetSlug from preset-input-control? I think we could just get rid of these tests if they are tested within preset-input-control.

@@ -64,10 +71,7 @@ export const VIEWS = {
* @return {boolean} Return true if value is string in format var:preset|spacing|.
*/
export function isValueSpacingPreset( value ) {

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.

If isValuePreset( value, SPACING_PRESET_TYPE ) handles it, maybe we use that instead? Or is isvalueSpacingPreset publicly exported?

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.

Ah, it is publicly exported. Nevermind.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Block editor /packages/block-editor [Type] Code Quality Issues or PRs that relate to code quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants