-
Notifications
You must be signed in to change notification settings - Fork 21
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
Use AppButton with extracted Button component #1834
Conversation
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.
Thanks for the fix. Tested locally and works well. Left a minor comment for another removable workaround.
For the
components-panel__body-toggle
'spadding-right
fix, it seems like it is not needed, so I have removed it.
💯
I believe the upstream should have fixed this problem. Thanks for improving this.
Ref: https://github.com/WordPress/gutenberg/blob/%40wordpress/components%4019.17.0/packages/components/src/panel/style.scss#L81
- Move all button-related CSS styles under the
.gla-admin-page
CSS class [...] for scoping the GLA required adjustments.
The reasons I suggested moving button-related styles under the .gla-admin-page
CSS class were:
Button
component is also used by@wordpress/components
and@woocommerce/components
, and theseButton
s are DEWPed by the libraries themselves. So, some buttons like the X on a modal won't have the.app-button
CSS class. In other words, the button fixes in GLA won't be applied to these buttons.
- Preserve the flexibility of using the
Button
of@wordpress/components
directly in the future. - The codes within the js/src/external-components directory would be a bit nicer to keep the same implementation with their copy as possible and only add needed fixes or features in GLA. Although adding
extracted/
would also make it inconsistent with the copy, at least it's clear that it's only becauseButton
is simply externalized. Changing it toAppButton
adds another extra mental burden of thinking about whetherAppButton
is a necessary change for these components.
For the first reason, since these button style fixes were moved under the .app-button
CSS class, it makes their application scope smaller than expected, which is to all Button
s in the entire GLA pages.
I guess it's probably not causing any problems at the moment, but I'd like to double check if any of the buttons mentioned in the first reason had the fixes applied to them but are now not applied to them?
Conflicts: js/src/dashboard/index.js
@eason9487 , thanks for the review! 😃
Related to my comment #1834 (comment) about WP L-2 version support policy, FYI I double checked and the same style is also in https://github.com/WordPress/gutenberg/blob/%40wordpress/components%4019.2.3/packages/components/src/panel/style.scss#L78, so I guess we are good.
For these components, I'd say it would be better to create wrapper component around them (e.g. we already have AppModal component that wraps Modal component), and put the CSS in the wrapper component (AppModal CSS would have the hacks for the close button in Modal component).
Personally, I start to think that "using the Having an AppButton wrapper around the Button component (and AppModal etc) gives us a level of control that is easier to reason about and maintain. This is not to say we must not use
Yeah, that was a dilemma that I had, I wasn't really sure whether it is wise to do that, that's why I made the changes as a separate commit in I chose to do the change because I was favoring consistency across the whole repo, to have only one line of
Yes, that is expected, and I think that is better. Previously, we have the style in _gutenberg-components.scss which is like a global site-wide style that affects everything. If we put it into
I think, the thing is, we wouldn't know for sure? I mean, for example, how do we know the rule |
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.
Thanks for the explanation in #1834 (comment).
Button
component is also used by@wordpress/components
and@woocommerce/components
, and theseButton
s are DEWPed by the libraries themselves. So, some buttons like the X on a modal won't have the.app-button
CSS class. In other words, the button fixes in GLA won't be applied to these buttons.
[screenshot of modal with close button]For these components, I'd say it would be better to create wrapper component around them (e.g. we already have AppModal component that wraps Modal component), and put the CSS in the wrapper component (AppModal CSS would have the hacks for the close button in Modal component).
Unfortunately, I'm not pretty sure creating wrapper component(s) would be better. For example, to broadly fix the support of hidden
attribute for Button
in GLA, all that needs to be done is to add the following style to the _gutenberg-components.scss file.
.gla-admin-page {
.components-button[hidden] {
display: none;
}
}
Instead, the way of creating wrapper component will need to:
- Search for all components in use that import
Button
across@wordpress/components
and@woocommerce/*
.- Not only the
@woocommerce/components
is the searching target because like@woocommerce/customer-effort-score
also usesButton
.
- Not only the
- If there are components using
Button
that are not currently wrapped in GLA,- Create wrapper components for them.
- Replace all direct uses with the wrapper components.
- For example,
Tag
,Pannel
,DropdownButton
,FilterPicker
,Chart
,Table
,CustomerEffortScore
and etc., will be the components that need to be wrapped.
- Duplicate this style fix or style import in all related wrapper components.
- Note down somewhere to remind devs to use the wrapper components rather than using them directly. Moreover, these rules must also be kept in reviewers' minds for future code reviews.
Maintainability is also significantly different:
- When adjusting, it will need to update all duplicates of the style fix.
- When removing, it will need to remove all duplicates of the style fix and further consider whether to revert the replacements of the wrapper component made when fixing.
Maybe I overlook some reasons that make it better?
- Preserve the flexibility of using the
Button
of@wordpress/components
directly in the future.Personally, I start to think that "using the
Button
of@wordpress/components
directly" may not be a good idea, mainly because of the L-2 version support policy. Imagine if we need to have different CSS hacks in.gla-admin-page
for Button component in version L-0, L-1 and L-1, and also hacks for Buttons in Modal, Panel etc.
Not sure what the exact case would be, but the following example should work.
.gla-admin-page {
.components-button {
// General fix goes here
}
.components-panel {
// General fix goes here
.components-button {
// Specific fix for Button in Panel goes here
}
}
}
Having an AppButton wrapper around the Button component (and AppModal etc) gives us a level of control that is easier to reason about and maintain.
Probably I missed some points of view. However, as in the first part of this reply, I don't quite sure that this will be easier to maintain. Instead, it would bring worse maintainability.
This is not to say we must not use
Button
of@wordpress/components
directly. We can, with this "rule": we want the Button that is exactly the same as the one provided by the WP environment. [...]
I'm not sure what situation would require using a AppButton
having a compatible fix and also using a Button
exactly the same as WP environment but without that fix at the same time, could you offer a practice example?
If we want to modify the component so that it is within our control, then we should do it with a wrapper.
Yes, using a wrapper for the needed things like adding the loading indicator and related styles would be good. But the concern here is about the style workarounds.
- The codes within the js/src/external-components directory would be a bit nicer to keep the same implementation with their copy as possible and only add needed fixes or features in GLA. Although adding
extracted/
would also make it inconsistent with the copy, at least it's clear that it's only becauseButton
is simply externalized. Changing it toAppButton
adds another extra mental burden of thinking about whetherAppButton
is a necessary change for these components.I chose to do the change because I was favoring consistency across the whole repo, to have only one line of
import { Button } from 'extracted/@wordpress/components';
inside AppButton in the whole repo.
When the entire @wordpress/components
can be externalized, it will need to remove the extracted/
for them in the codebase. Since this process is simple, IMO, having many lines of import { Button } from 'extracted/@wordpress/components';
is not a concern.
It is easier to inform future developers to "Always use AppButton, not Button".
I would say this would be more close to implying or inferring, not informing. Otherwise, this PR would not need to do so much with these replacements of Button
to AppButton
if the AppButton
had ever "informed" devs well in the past.
For the first reason, since these button style fixes were moved under the
.app-button
CSS class, it makes their application scope smaller than expected, which is to allButton
s in the entire GLA pages.Yes, that is expected, and I think that is better.
I couldn't understand why having compatible fixes in AppButton
only but not having them in Button
is an expected and better result. Could you clarify it?
Previously, we have the style in _gutenberg-components.scss which is like a global site-wide style that affects everything. If we put it into
.gla-admin-page
, it is like a global plugin-wide style within GLA.
Placing the plugin-wide style fixes under .gla-admin-page
in _gutenberg-components.scss is exactly one of the important and main purposes of creating that scoping CSS class.
IMO, these global styles make things a bit more difficult to reason about and maintain. If we put them into wrapper components, it is easier.
As in the first part of this reply, sorry, I can't agree with this point of view. In particular, this approach requires the creation of a dozen wrapped components, and these efforts don't look easy at all. And, wrapping non-basic-level components like FilterPicker
, Chart
, and Table
, just in order to fix a Button
style problem inside them, looks impractical and code smells.
I'd like to double check if any of the buttons mentioned in the first reason had the fixes applied to them but are now not applied to them?
I think, the thing is, we wouldn't know for sure? I mean, for example, how do we know the rule
&.is-tertiary.is-destructive
is originally written and meant to apply to the button in Modal, Panel... etc...?
Yes, we probably don't remember the original purpose. Considering that if these fixes were placed in _gutenberg-components.scss rather than AppButton
, doesn't this infer that they were expected to be applied to Button
on all GLA pages? The unexpected thing is they pollute other non-GLA pages.
And, the fixes applied to Button
on GLA pages have been there for almost a year to over two years (AppButton
was not even created yet two years ago), so it could be considered they've been tested over time at least.
Given a comparison table:
CSS selector \ Scope | AppButton on GLA pages | Button on GLA pages | Button on other pages |
---|---|---|---|
Global (before) | ✔️ ⭕ | ✔️ ⭕ * | ✔️ ❌ |
AppButton (this PR) | ✔️ ⭕ | ✖️ ❓ | ✖️ ⭕ |
.gla-admin-page | ✔️ ⭕ | ✔️ ⭕ * | ✖️ ⭕ |
✔️ Applied
✖️ Not applied
⭕ Expected
❌ Not expected
* At least it works well for 1 - 2 years
The unknown change marked as❓is the blocker for this PR, in addition, this change goes beyond the issue that this PR was probably intended to fix: the Button styles in GLA affect other non-GLA pages, which is the last column of the above table.
Therefore, if this approach is to be adopted in this PR, I would like to clarify whether this change has any extra impact. And yes, that probably means it needs to find and verify whether there are DEWPed Button
s that match these CSS selectors and still need those moved fixes. If not, the current implementation in this PR can proceed as well. But if there are, I'm still not quite keen on actually creating wrappers for those components, and then looping those components to the same verification processing recursively as there are fixes for other components in _gutenberg-components.scss.
And that is the problem of using global styles like this...?
That's why .gla-admin-page
is presented for limiting the scope to GLA pages only.
@eason9487 , thanks for the detailed explanation! 🙏 I'm gonna focus on the following one first, so that we can proceed and move this PR forward: 😄
Thanks so much for the table, I think I see your point now, and yeah I agree it does go beyond the issue, I was going far ahead of myself, sorry about that. 😅 I will look into moving those CSS from AppButton into the |
@eason9487 , I have made a few more commits in this PR. In In Three of the external-components files have eslint warnings that say "node_modules/@wordpress/components/build-module/index.js' imported multiple times. eslint import/no-duplicates", because we have imports from both In my VS Code editor, if I do an "autofix upon save", it will automatically change the line to I checked the GLA code base and these three external-components are the only places where we have both In With the above commits, I tested around in GLA and also in WooCommerce Core, it seems like things are working as expected and it fixes issue #1765. This is ready for another round of review. Let me know what you think on these. 🙂 🙏 |
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.
Thanks for the adjustment and consideration. LGTM.
Three of the external-components files have eslint warnings that say "node_modules/@wordpress/components/build-module/index.js' imported multiple times. eslint import/no-duplicates", [...]. Not sure if you are aware of the above eslint warning and autofix behavior, so just want to point it out.
Thanks for pointing out this. It's new and I opened #1844 to solve it.
Changes proposed in this Pull Request:
Closes #1765, and partly addresses #1391.
In this PR, we move from using bundled Button component to using extracted Button component from the
@wordpress/components
package, and remove the usage of@import "node_modules/@wordpress/components/src/button/style";
in_gutenberg-components.scss
.All
<Button>
usages are now changed to<AppButton>
, including the usages in theexternal-components
directory. AppButton is essentially a wrapper around Button. In the future, if there are breaking changes in Button, we just need to apply the fix in AppButton and it should work throughout the whole plugin.In
_gutenberg-components.scss
file, there were some hacks or fixes under.components-button
rule. I tested them and they are different from the default@wordpress/components
button style. The video recording below shows the difference of the button styles in WooCommerce Marketing page and in GLA page:Sample code for testing button styles used in the video below
demo-pr-button-styles.mov
To maintain UI appearance in GLA, I have moved the above button styles to AppButton CSS.
For the
components-panel__body-toggle
'spadding-right
fix, it seems like it is not needed, so I have removed it. It was introduced in2228fa5
(#1708) (heads up to the PR author @eason9487). Screenshot below shows the panel without thepadding-right
fix, and it appears to be working as expected without UI issue:With the button style no longer bundled and needed, this fixes the CSS issue in non-GLA pages mentioned in #1765.
Screenshots:
Screenshot of WooCommerce Marketing page, without button style conflict from GLA:
Detailed test instructions:
/wp-admin/admin.php?page=wc-settings&tab=advanced§ion=features
/wp-admin/admin.php?page=wc-admin&path=%2Fmarketing
Additional details:
Changelog entry