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: dedupe palette element slugs #65772

Merged
merged 6 commits into from
Oct 4, 2024

Conversation

ramonjd
Copy link
Member

@ramonjd ramonjd commented Oct 1, 2024

What?

Part of #43197

First pass at deduping palette slugs

Why?

The color palette uses the palette item name to generate a slug. So, Test 1 will be custom-test-1.

If there are identical names, the slugs would normally be the same. Slugs should be unique identifiers so they can be correctly applied as CSS vars.

How?

When updating palette item names, check for duplicate slugs. If duplicates are found, update those slugs.

Testing Instructions

In Site Editor > Global Styles > Colors > Palette create multiple custom colors and gradients.

Give all or some of each the same name.

Save and try to apply your custom colors in the editor.

They should work in the front and backend.

Testing Instructions for Keyboard

Screenshots or screencast

Given a series of duplicate names:

Screenshot 2024-10-01 at 4 44 13 pm

The custom palette is still operable due to unique slugs:

Kapture.2024-10-01.at.16.45.27.mp4

Which are saved to global styles and output in the frontend

Screenshot 2024-10-01 at 4 45 59 pm

Copy link

github-actions bot commented Oct 2, 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: ramonjd <[email protected]>
Co-authored-by: aaronrobertshaw <[email protected]>
Co-authored-by: ciampo <[email protected]>

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

@ramonjd ramonjd added Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Type] Enhancement A suggestion for improvement. [Type] Bug An existing feature does not function as intended and removed [Type] Enhancement A suggestion for improvement. labels Oct 2, 2024
@ramonjd ramonjd changed the title ColorPalette: dedupe palette element slugs PaletteEdit: dedupe palette element slugs Oct 2, 2024
@ramonjd ramonjd changed the title PaletteEdit: dedupe palette element slugs PaletteEdit: dedupe palette element slugs Oct 2, 2024
@ramonjd ramonjd force-pushed the try/palette-edit-deduplicate-slugs branch from 5ee626b to 4c9b408 Compare October 2, 2024 02:48
Copy link
Contributor

@aaronrobertshaw aaronrobertshaw 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 fixing this one @ramonjd, I'm sure it was annoying for people maintaining color palettes 👍

This PR tests well for me. I didn't run into any issues and only left a couple of very minor nits as inline comments.

✅ Custom colors with various duplicate slugs now work
✅ Same for custom gradients
✅ Duplicate named colors work both frontend and in the editors (site/post)

LGTM 👍

Screen.Recording.2024-10-03.at.3.11.32.pm.mp4

@aaronrobertshaw
Copy link
Contributor

I believe I've addressed the remaining feedback.

@ramonjd should be back online later next week but if you're happy enough with this PR @ciampo, it might be a nice one to land and get included in the next 6.7 beta. What do you think?

ramonjd and others added 6 commits October 4, 2024 16:15
…a generic type parameter. The linter was complaining that I wasn't doing the same, even though I was using the same inherited types. Whatever. It could probably be optimized, but it's unrelated to the scope of this PR
@ciampo ciampo force-pushed the try/palette-edit-deduplicate-slugs branch from 526fc89 to f135898 Compare October 4, 2024 14:16
@ciampo
Copy link
Contributor

ciampo commented Oct 4, 2024

Sounds good! I rebased, fixed conflicts, and will merge as soon as CI is green

@ciampo ciampo added the Backport to WP 6.7 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Oct 4, 2024
@ciampo ciampo enabled auto-merge (squash) October 4, 2024 14:17
@ciampo ciampo merged commit 597c7d9 into trunk Oct 4, 2024
66 checks passed
@ciampo ciampo deleted the try/palette-edit-deduplicate-slugs branch October 4, 2024 14:52
@github-actions github-actions bot added this to the Gutenberg 19.5 milestone Oct 4, 2024
Copy link

github-actions bot commented Oct 4, 2024

There was a conflict while trying to cherry-pick the commit to the wp/6.7 branch. Please resolve the conflict manually and create a PR to the wp/6.7 branch.

PRs to wp/6.7 are similar to PRs to trunk, but you should base your PR on the wp/6.7 branch instead of trunk.

# Checkout the wp/6.7 branch instead of trunk.
git checkout wp/6.7
# Create a new branch for your PR.
git checkout -b my-branch
# Cherry-pick the commit.
git cherry-pick 597c7d97e5da343eaab9556a30c875cde0a0647f
# Check which files have conflicts.
git status
# Resolve the conflict...
# Add the resolved files to the staging area.
git status
git add .
git cherry-pick --continue
# Push the branch to the repository
git push origin my-branch
# Create a PR and set the base to the wp/6.7 branch.
# See https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/changing-the-base-branch-of-a-pull-request.

@ciampo ciampo removed the Backport to WP 6.7 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Oct 4, 2024
@ciampo
Copy link
Contributor

ciampo commented Oct 4, 2024

it might be a nice one to land and get included in the next 6.7 beta

@aaronrobertshaw I tried but there's a conflict when merging. I'm about to go offline for the week — would you be able to take care of manually backporting when you're back offline? Otherwise I'll do it myself when I come back online on Monday

ciampo added a commit that referenced this pull request Oct 7, 2024
* First pass at deduping palette element slugs.

* Addressing TypeScript errors where PaletteEditListViewProps is using a generic type parameter. The linter was complaining that I wasn't doing the same, even though I was using the same inherited types. Whatever. It could probably be optimized, but it's unrelated to the scope of this PR

* Add changelog

* Make use of PaletteElement type consistent

* Address feedback on deduplicate util

* Use count rather than index for new slugs

---------

Co-authored-by: ramonjd <[email protected]>
Co-authored-by: aaronrobertshaw <[email protected]>
Co-authored-by: ciampo <[email protected]>
@ciampo ciampo mentioned this pull request Oct 7, 2024
@ciampo
Copy link
Contributor

ciampo commented Oct 7, 2024

Manual backport #65905

ciampo added a commit that referenced this pull request Oct 8, 2024
* First pass at deduping palette element slugs.

* Addressing TypeScript errors where PaletteEditListViewProps is using a generic type parameter. The linter was complaining that I wasn't doing the same, even though I was using the same inherited types. Whatever. It could probably be optimized, but it's unrelated to the scope of this PR

* Add changelog

* Make use of PaletteElement type consistent

* Address feedback on deduplicate util

* Use count rather than index for new slugs

---------

Co-authored-by: ramonjd <[email protected]>
Co-authored-by: aaronrobertshaw <[email protected]>
Co-authored-by: ciampo <[email protected]>
ciampo added a commit that referenced this pull request Oct 8, 2024
* `PaletteEdit`: dedupe palette element slugs (#65772)

* First pass at deduping palette element slugs.

* Addressing TypeScript errors where PaletteEditListViewProps is using a generic type parameter. The linter was complaining that I wasn't doing the same, even though I was using the same inherited types. Whatever. It could probably be optimized, but it's unrelated to the scope of this PR

* Add changelog

* Make use of PaletteElement type consistent

* Address feedback on deduplicate util

* Use count rather than index for new slugs

---------

Co-authored-by: ramonjd <[email protected]>
Co-authored-by: aaronrobertshaw <[email protected]>
Co-authored-by: ciampo <[email protected]>

* Update CHANGELOG section

---------

Co-authored-by: ramonjd <[email protected]>
Co-authored-by: ciampo <[email protected]>
Co-authored-by: andrewserong <[email protected]>
Co-authored-by: aaronrobertshaw <[email protected]>
@ramonjd ramonjd removed the [Status] In Progress Tracking issues with work in progress label Oct 30, 2024
karthick-murugan pushed a commit to karthick-murugan/gutenberg that referenced this pull request Nov 13, 2024
* First pass at deduping palette element slugs.

* Addressing TypeScript errors where PaletteEditListViewProps is using a generic type parameter. The linter was complaining that I wasn't doing the same, even though I was using the same inherited types. Whatever. It could probably be optimized, but it's unrelated to the scope of this PR

* Add changelog

* Make use of PaletteElement type consistent

* Address feedback on deduplicate util

* Use count rather than index for new slugs

---------

Co-authored-by: ramonjd <[email protected]>
Co-authored-by: aaronrobertshaw <[email protected]>
Co-authored-by: ciampo <[email protected]>
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 [Type] Bug An existing feature does not function as intended
Projects
None yet
3 participants