-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Global Styles: Simplify code to fetch color and typography variation #62827
Conversation
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Size Change: -71 B (0%) Total Size: 1.76 MB
ℹ️ View Unchanged
|
packages/edit-site/src/components/global-styles/variations/variations-typography.js
Outdated
Show resolved
Hide resolved
2c4bff8
to
c297a4d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Asked a lot of questions because I'm not very familiar with this code :) It's testing fine for me though!
@@ -31,7 +33,7 @@ export default function ColorVariations( { title, gap = 2 } ) { | |||
key={ index } | |||
variation={ variation } | |||
isPill | |||
property="color" | |||
property={ propertyToFilter } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will these changes work alongside the changes in this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, if that one is merged we'll get a conflict here. I think there's more we'll be able to simplify once the two PRs are combined.
@@ -38,7 +40,7 @@ export default function TypographyVariations( { title, gap = 2 } ) { | |||
<Variation | |||
key={ index } | |||
variation={ variation } | |||
property="typography" | |||
property={ propertyToFilter } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also here.
/* | ||
* Filter out variations with no settings or styles. | ||
*/ | ||
return variationsByProperty?.length | ||
? variationsByProperty.filter( ( variation ) => | ||
isEmptyStyleVariation( variation ) | ||
) | ||
: []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not put this within the useMemo
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, done in a68c2ce.
...ges/edit-site/src/hooks/use-theme-style-variations/use-theme-style-variations-by-property.js
Outdated
Show resolved
Hide resolved
Object.keys( settings ).length > 0 || | ||
Object.keys( styles ).length > 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not familiar with how theme.json
settings get applied. From looking at the structure, I'm wondering if this should be an AND:
( Object.keys( settings ).length > 0 && Object.keys( styles ).length > 0 )
It looks like it could be a valid theme style while having a setting or style? Or does it need both?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah the problem here is actually the name of the function. It is returning true if the variation is NOT empty!
a68c2ce
to
f7bb918
Compare
...ges/edit-site/src/hooks/use-theme-style-variations/use-theme-style-variations-by-property.js
Outdated
Show resolved
Hide resolved
...ges/edit-site/src/hooks/use-theme-style-variations/use-theme-style-variations-by-property.js
Outdated
Show resolved
Hide resolved
I think For me the browser crashes when visiting Site Editor > Styles |
…iations-typography.js
…eme-style-variations-by-property.js Co-authored-by: Jerry Jones <jones.jeremydavid@gmail.com>
…eme-style-variations-by-property.js Co-authored-by: Jerry Jones <jones.jeremydavid@gmail.com>
…eme-style-variations-by-property.js Co-authored-by: Jerry Jones <jones.jeremydavid@gmail.com>
3ac8dbc
to
002915c
Compare
Thanks @ramonjd. I have fixed this and also rebased it, so it should be working again... |
Flaky tests detected in 90d3084. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/9789769319
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
🚢
…ordPress#62827) * Simplify style variation code * Update packages/edit-site/src/components/global-styles/variations/variations-typography.js * Update packages/edit-site/src/hooks/use-theme-style-variations/use-theme-style-variations-by-property.js Co-authored-by: Jerry Jones <jones.jeremydavid@gmail.com> * Update the function to actually check if the variation is empty * move the filter inside the useMemo * Update packages/edit-site/src/hooks/use-theme-style-variations/use-theme-style-variations-by-property.js Co-authored-by: Jerry Jones <jones.jeremydavid@gmail.com> * Update packages/edit-site/src/hooks/use-theme-style-variations/use-theme-style-variations-by-property.js Co-authored-by: Jerry Jones <jones.jeremydavid@gmail.com> * updawte variable name * fix rebase issues * refactor dependecy to a const * use the new function in the sidebar --------- Co-authored-by: Jerry Jones <jones.jeremydavid@gmail.com> Co-authored-by: scruffian <scruffian@git.wordpress.org> Co-authored-by: jeryj <jeryj@git.wordpress.org> Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
What?
Small refactor to simplify this code and share more code between the two variations.
Why?
Less code means less maintenance and fewer bugs.
How?
Remove
useColorVariations
anduseTypographyVariations
and calluseCurrentMergeThemeStyleVariationsWithUserConfig
directly instead.Testing Instructions
Screenshots or screencast