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

PaletteEdit: temporary custom gradient not saving #56896

Merged
merged 3 commits into from Dec 12, 2023

Conversation

ramonjd
Copy link
Member

@ramonjd ramonjd commented Dec 8, 2023

Fixes #56865

What?

Refactors isTemporaryElement test in the PaletteEdit component.

Why?

Gradient elements contain both color and gradient properties, therefore they'll always return true for the isTemporaryElement test if the color property is default (#000).

How?

Ensuring we test for gradient values first.

Testing Instructions

  1. Kick on over to the site editor and open up the global styles panel.
  2. Create a new custom gradient in Colors > Palette > Gradient (ensuring to modify the color at least)
  3. Click "Done"
  4. The new custom gradient should persist

Testing Instructions for Keyboard

Screenshots or screencast

Before

2023-12-08.15.38.45.mp4

After

2023-12-08.16.07.29.mp4

@ramonjd ramonjd added [Type] Bug An existing feature does not function as intended [Package] Components /packages/components Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json labels Dec 8, 2023
@ramonjd ramonjd self-assigned this Dec 8, 2023
…re they'll always return true for this test if the color property is default (#000)
@ramonjd ramonjd force-pushed the update/palette-edit-temporary-test branch from e371581 to a847daa Compare December 8, 2023 05:17
@ramonjd ramonjd changed the title PaletteEdit: custom gradient not saving PaletteEdit: temporary custom gradient not saving Dec 8, 2023
Copy link

github-actions bot commented Dec 8, 2023

Flaky tests detected in fbd438c.
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/7160971758
📝 Reported issues:

Copy link
Contributor

@tellthemachines tellthemachines left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

It does fix the inability to save a custom gradient with the default colour, but now it's not possible to save the default gradient with a custom name. I wonder if we shouldn't be checking that both name and gradient are set to default, and if either one has changed assume the change is deliberate and save?

One thing I noticed while trying to reproduce the issue on trunk is that it's only impossible to save a gradient with the default name if there are no other gradients saved already. After successfully saving one, I'm able to save however many I want with the default name. Not sure why this happens though.

@ramonjd
Copy link
Member Author

ramonjd commented Dec 8, 2023

but now it's not possible to save the default gradient with a custom name.

Thanks for testing! Oh dang 😆 I didn't see that.

I wonder if we shouldn't be checking that both name and gradient are set to default, and if either one has changed assume the change is deliberate and save?

Good point on the default name. I'll take look.

@ramonjd
Copy link
Member Author

ramonjd commented Dec 10, 2023

now it's not possible to save the default gradient with a custom name.

I've fixed that I think, and added some tests. I was returning the wrong default value from isTemporaryElement.

Working on this PR highlighted another logical error in trunk: that the regex ^${ slugPrefix }color-([\\d]+)$ will catch all color-${ anyNumber }, so if a user edits the number on the default name and doesn't update the color value, it'll be treated as a "temporary" color, and wiped.

2023-12-11.10.30.47.mp4

Might require a bit of a refactor so I'd say unrelated to this bug, which fixes the bug in the color/gradient conditional test order.

@ramonjd
Copy link
Member Author

ramonjd commented Dec 10, 2023

Might require a bit of a refactor so I'd say unrelated to this bug, which fixes the bug in the color/gradient conditional test order.

Have WIP PR here as a follow up to this one:

Copy link
Contributor

@andrewserong andrewserong left a comment

Choose a reason for hiding this comment

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

Works nicely for me, and is a definite improvement over what we have on trunk. Thanks for adding the tests, too!

Saving custom gradients is working now, and saving single colors is still working:

2023-12-12.16.39.49.mp4

LGTM! ✨

@ramonjd
Copy link
Member Author

ramonjd commented Dec 12, 2023

Thanks @andrewserong!

@ramonjd ramonjd merged commit 839e553 into trunk Dec 12, 2023
52 checks passed
@ramonjd ramonjd deleted the update/palette-edit-temporary-test branch December 12, 2023 05:44
@github-actions github-actions bot added this to the Gutenberg 17.3 milestone Dec 12, 2023
Copy link
Contributor

@ciampo ciampo left a comment

Choose a reason for hiding this comment

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

Thank you for working on this (and for adding tests!!) I've left a small comment, but otherwise this looks great!

slugPrefix: string,
{ slug, color, gradient }: Color | Gradient
) {
): Boolean {
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh! Thanks. I'll fix in an upcoming, related PR 👍🏻

Copy link
Contributor

Choose a reason for hiding this comment

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

Great catch, thanks Marco!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Package] Components /packages/components [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Custom gradient only saves with new name
4 participants