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: Fix order numbers #52212

Conversation

megane9988
Copy link
Contributor

@megane9988 megane9988 commented Jul 2, 2023

What?

For #51230

Why?

copilot:summary

How?

  • Change Site Language Setting English to 日本語
image
  • Go to Style Color setting
  • Push the Custom(カスタム) Plus icon
image
  • You can find Custom Color (the name is 色 1)
  • Add some custom colors
  • You can watch Color name (incremental)
image

Testing Instructions

Testing Instructions for Keyboard

Screenshots or screencast

@megane9988
Copy link
Contributor Author

megane9988 commented Jul 2, 2023

It is a draft now.

@megane9988 megane9988 marked this pull request as draft July 2, 2023 07:02
@megane9988 megane9988 marked this pull request as ready for review October 20, 2023 05:24
@miminari miminari added Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Package] Components /packages/components labels Oct 20, 2023
@ramonjd ramonjd added the [Type] Bug An existing feature does not function as intended label Mar 7, 2024
@ramonjd
Copy link
Member

ramonjd commented Mar 7, 2024

Thanks for the PR @megane9988

Could you rebase this PR? It would also help to have a description of how to test.

Thank you!

Copy link

github-actions bot commented Mar 7, 2024

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: megane9988 <megane9988@git.wordpress.org>
Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: mirka <0mirka00@git.wordpress.org>

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

@megane9988 megane9988 closed this Mar 7, 2024
@megane9988 megane9988 force-pushed the feature/fix-sequential-order-numbers-for-color-palette branch from 47aac7f to 9888332 Compare March 7, 2024 05:49
@megane9988 megane9988 reopened this Mar 7, 2024
@ramonjd ramonjd requested a review from t-hamano March 7, 2024 06:39
@ramonjd
Copy link
Member

ramonjd commented Mar 7, 2024

Thanks for the update to this PR @megane9988 and for the tests 🙇🏻

Screenshot 2024-03-07 at 3 14 37 pm

So to summarize: Gutenberg was trying to create slugs for colors using translated strings, e.g., 色 6 but that didn't pass the regex new RegExp( ^${ slugPrefix }color-([\d]+)$ )

This is working pretty well for me.

Copy link
Contributor

@t-hamano t-hamano 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!

This PR is working as expected and will also resolve two issues, #55185 and #51230.

7c6c80130e8a3a5ecbc25d0896d0aee6.mp4

As a follow-up, we should apply the same logic not only when a new color is "added" but also when a color label is "updated". As the screencast below shows, after an item with the correct slug is added, reapplying the same label will result in the incorrect slug being applied.

c408a0d4cd2bf3cbffb42f07b3925409.mp4

This means that we apply the getNameAndSlugForPosition() function here as well and completely stop the slug generation logic from relying on the color label:

onChange( {
...element,
name: nextName,
slug:
slugPrefix +
kebabCase( nextName ?? '' ),
} )

Comment on lines 5 to 16
### Bug Fix
- `PaletteEdit`: Fix order numbers for color palette ([#52212](https://github.com/WordPress/gutenberg/pull/52212)).
Copy link
Contributor

Choose a reason for hiding this comment

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

This part is causing a conflict, so could you rebase it again?

Copy link
Member

Choose a reason for hiding this comment

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

I think something like "PaletteEdit: Fix number incrementing of default names for new colors added in non-en-US locales" would be more helpful here, given the specific scope of the fix.

packages/components/src/palette-edit/index.tsx Outdated Show resolved Hide resolved
packages/components/src/palette-edit/test/index.tsx Outdated Show resolved Hide resolved
packages/components/src/palette-edit/test/index.tsx Outdated Show resolved Hide resolved
packages/components/src/palette-edit/test/index.tsx Outdated Show resolved Hide resolved
@t-hamano t-hamano requested a review from a team March 11, 2024 08:25
@ramonjd
Copy link
Member

ramonjd commented Mar 13, 2024

As a follow-up, we should apply the same logic not only when a new color is "added" but also when a color label is "updated".

Is it much effort to include it in this PR? It would be good to fix the flow in one go. But also happy for it to be a quick follow up

@t-hamano
Copy link
Contributor

Is it much effort to include it in this PR? It would be good to fix the flow in one go. But also happy for it to be a quick follow up

Regarding that issue, I think it's okay to address it in a follow-up since we probably need to add more tests. I plan to address it as part of a tracking issue, #57309.

Copy link
Member

@mirka mirka left a comment

Choose a reason for hiding this comment

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

Looks ready to merge as an iterative improvement, once @t-hamano's feedback is addressed 👍

The renaming case may be a bit more complicated than the new color case, so I understand why we'd want to do that in a follow up. We also need to figure out which part of the chain is responsible for the name/slug validation (deduplication) logic — I kind of think it has to be provided by the consumer rather than the PaletteEdit component itself, but that's a separate discussion. Maybe it will turn out that the consumer needs to be responsible for the entire name/slug generation logic as well.

@mirka mirka changed the title fix order numbers for color palette Mar 18, 2024
@mirka mirka added the Internationalization (i18n) Issues or PRs related to internationalization efforts label Mar 18, 2024
@megane9988 megane9988 force-pushed the feature/fix-sequential-order-numbers-for-color-palette branch from 33fe907 to 6635428 Compare March 18, 2024 15:18
Co-authored-by: Aki Hamano <54422211+t-hamano@users.noreply.github.com>
@ramonjd
Copy link
Member

ramonjd commented Mar 18, 2024

Thanks for the teamwork here, folks.

@megane9988 are you okay to look at a follow up? Otherwise I can add it to my TODO list for later.

Thank you! 🍺

@ramonjd ramonjd merged commit b81d990 into WordPress:trunk Mar 18, 2024
55 checks passed
@github-actions github-actions bot added this to the Gutenberg 18.0 milestone Mar 18, 2024
carstingaxion pushed a commit to carstingaxion/gutenberg that referenced this pull request Mar 27, 2024
Using FSE to change styles on a page template. When using the English language in site and add new colors to Styles, the default name appear with numbers in order. However, when switching to Japanese language, the sequential order numbers did not work anymore in the default name.

Gutenberg was trying to create slugs for colors using translated strings, e.g., 色 6 but that didn't pass the regex new RegExp( ^${ slugPrefix }color-([\d]+)$ )

This commit hardcodes the English `color-` slug fragment to avoid this.

Updates unit tests.

---------

Co-authored-by: megane9988 <megane9988@git.wordpress.org>
Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: mirka <0mirka00@git.wordpress.org>
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 Internationalization (i18n) Issues or PRs related to internationalization efforts [Package] Components /packages/components [Type] Bug An existing feature does not function as intended
5 participants