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

Palette Edit: Don't discards colors with default name and slug #54332

Merged
merged 7 commits into from Dec 22, 2023

Conversation

t-hamano
Copy link
Contributor

@t-hamano t-hamano commented Sep 10, 2023

Fixes: #37861
Related to #37496

What?

This PR will not discard colors with the default name (Color-{number}) and default color (#000) in the PaletteEdit component.

Why?

I have looked at the changes made in #37496 and this PR makes two main changes:

  • Apply the default slug when adding a new color.
  • If a color has a default slug and a default color, discard that color as temporary

However, my feeling is that the newly added color will have an appropriate name and slug so that the color no longer needs to be considered a "temporary" color.

In addition, you can never save a color that is considered a temporary color (i.e., one whose name is in the form color {number} and whose HEX color is #000). To me, this behavior feels more like a bug.

How?

I removed the code related to the isTemporaryElement() function that determines if a color is temporary or not, so that colors with default name are not deleted. I also adjusted variable names and comments.

Note: The PaletteEdit component generates a slug from the input string, but problems exist regarding non-Latin and multibyte characters. See #49711 and #39210 for details.

Testing Instructions

  • Access the Global Style panel.
  • Press the "Add" button on the Custom Color palette in succession.
  • Colors named Color 1, Color 2, and Color 3 should be created.
  • Click the "Done" button.
  • The color palette should be retained.

Screenshots or screencast

34561cfcc445476fa0c4bb874199df15.mp4

@t-hamano t-hamano added [Type] Bug An existing feature does not function as intended Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json labels Sep 10, 2023
@t-hamano t-hamano self-assigned this Sep 10, 2023
@t-hamano t-hamano marked this pull request as ready for review September 10, 2023 09:14
@github-actions
Copy link

github-actions bot commented Sep 10, 2023

Flaky tests detected in 676611a.
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/7296048303
📝 Reported issues:

@t-hamano t-hamano force-pushed the palette-edit/keep-default-palette branch from b2d4cb0 to 1547507 Compare October 10, 2023 12:07
@mirka mirka added the [Package] Components /packages/components label Dec 15, 2023
@mirka mirka requested a review from a team December 15, 2023 12:15
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.

The changes proposed in this PR make sense to me, although I'd like to hear thoughts from other folks too.


I also wanted to flag a related issue, which is going to be happening more often if this PR gets merged: entries with the same color name and/or value all appear as selected at the same time:

It would be great if we could look into fixing those issues as a follow-up

@t-hamano
Copy link
Contributor Author

When I merged the latest trunk into this PR and resolved the conflict, I discovered #56896 regarding the gradient custom palette.
This PR will also no longer discard gradients with the default color and the default color name.

The screencast below shows how to apply the default gradient color, but we discovered that a warning error is logged in the browser. However, this error also appears to occur on trunk, so I think it needs to be fixed separately.

922efb48fcabfe2594b7994698e47c2a.mp4

@ciampo
Copy link
Contributor

ciampo commented Dec 20, 2023

Adding @ramonjd @tellthemachines and @andrewserong as reviewers as they've been also working on PaletteEdit in the past weeks and are currently working on #56932

@ramonjd
Copy link
Member

ramonjd commented Dec 20, 2023

Oh wow, thanks for pointing out this PR to me @ciampo

I'll test it out tomorrow. Hopefully we can close #56932

Copy link
Member

@ramonjd ramonjd left a comment

Choose a reason for hiding this comment

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

I'm strangely attracted to this approach because:

  1. It removes a complexity
  2. It removes a lot of code anyway
  3. It returns us to a state from which we might try alternatives
  4. It hands more power and choice to the user

packages/components/CHANGELOG.md Outdated Show resolved Hide resolved
/**
* Checks if a color or gradient is a temporary element by testing against default values.
*/
export function isTemporaryElement(
Copy link
Member

Choose a reason for hiding this comment

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

I actually think this is a decent approach to removing the complexity. Why do we remove "default" values? To keep the list clean? We could rather trust the user to control how they want to create custom colors/gradients.

The following doesn't make much sense, but why not?

2023-12-21.11.02.16.mp4

The only thing we could probably address here is the lack of default value on the first item of the gradient:

Screenshot 2023-12-21 at 11 03 18 am

It has an empty value and can be saved.

Copy link
Contributor

Choose a reason for hiding this comment

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

The following doesn't make much sense, but why not?

That's a good point... maybe the user knows they're going to add a few custom colors and quickly goes to create them and then decides to go back later to update their colors? It might be nice to allow these sorts of interactions rather than try to predict too much, so I'm really liking the direction of this PR.

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.

I'm strangely attracted to this approach because:

+1, I really like the approach here! I think going for simplicity where we can is a good approach, and in practice, it feels quite good to me that you hit "+" and then new things are created and its up to the user to delete the ones they don't want.

The only issue I ran into is with a bit of inconsistency in creating gradients, not sure if it's related to what Ramon observed about an empty value being able to be saved, but when I go to add the first gradient, it has an empty value, but the second one isn't empty:

2023-12-21.13.49.22.mp4

Co-authored-by: Ramon <ramonjd@users.noreply.github.com>
@t-hamano
Copy link
Contributor Author

Thanks forthetesting, @ramonjd, @andrewserong!

The only issue I ran into is with a bit of inconsistency in creating gradients, not sure if it's related to what Ramon observed about an empty value being able to be saved, but when I go to add the first gradient, it has an empty value, but the second one isn't empty:

Thanks for finding that problem! This also occurs with trunk, so it should be a problem that needs to be fixed separately.

The cause is that if the custom gradient palette does not yet exist, this condition will be false, so the first palette added will be recognized as a solid color.

d7aca5dc537dcf27116c8e267dad9fe9.mp4

@t-hamano
Copy link
Contributor Author

The cause is that if the custom gradient palette does not yet exist, this condition will be false, so the first palette added will be recognized as a solid color.

I'm starting to think it might be better to resolve the above issues first before tackling this PR.

Whether the PaletteEdit component uses a solid color picker or a gradient color picker is determined solely by whether the gradients prop is falsy, so if no palette exists yet, there appears to be no way to make the PaletteEdit component act as a gradient color picker.

For example, add props like isGradient to specify the color type?

@ciampo Please let me know if you have any ideas 🙏

@andrewserong
Copy link
Contributor

I'm starting to think it might be better to resolve the above issues first before tackling this PR.

I'd be fine with either personally, since as you mention that's happening on trunk. Let's see what Marco thinks, but if it makes it easier to land this PR first before looking at that other issue, that would sound reasonable to me!

@ciampo
Copy link
Contributor

ciampo commented Dec 21, 2023

I agree with Andrew, let's resolve any feedback left and merge this PR, as it is an improvement over trunk anyway.

To recap, here are some follow-ups:

  1. Improve consistency when adding new gradients (issue described here)
    • While doing so, we should also investigate the console error described here, which seems related.
  2. Improve how we handle entries with the same name / color value — this is a pre-existing issue, but I think it's going to be amplified as a consequence of the changes in this PR
  3. Issues when handling non-latin characters (as mentioned in the PR description)

Unfortunately, I don't currently have time to work on this — @t-hamano / @andrewserong / @ramonjd , would any of you be able to look into it?

@t-hamano
Copy link
Contributor Author

Unfortunately, I don't currently have time to work on this — @t-hamano / @andrewserong / @ramonjd , would any of you be able to look into it?

OK, I have summarized the issues to be addressed in #57309.

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.

Sounds like we all agree, let's merge! ✨

(Looks like there's just a changelog conflict to resolve 🙂)

@ramonjd
Copy link
Member

ramonjd commented Dec 22, 2023

Great stuff! 🚢

@t-hamano t-hamano merged commit 6318db0 into trunk Dec 22, 2023
56 checks passed
@t-hamano t-hamano deleted the palette-edit/keep-default-palette branch December 22, 2023 05:19
@github-actions github-actions bot added this to the Gutenberg 17.4 milestone Dec 22, 2023
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.

Default custom color doesn't get saved
5 participants