8000 Refactor Button component. by ankitrox · Pull Request #10824 · google/site-kit-wp · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Refactor Button component. #10824

8000
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

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

ankitrox
Copy link
Collaborator

Summary

Addresses issue:

Relevant technical choices

PR Author Checklist

  • My code is tested and passes existing unit tests.
  • My code has an appropriate set of unit tests which all pass.
  • My code is backward-compatible with WordPress 5.2 and PHP 7.4.
  • My code follows the WordPress coding standards.
  • My code has proper inline documentation.
  • I have added a QA Brief on the issue linked above.
  • I have signed the Contributor License Agreement (see https://cla.developers.google.com/).

Do not alter or remove anything below. The following sections will be managed by moderators only.

Code Reviewer Checklist

  • Run the code.
  • Ensure the acceptance criteria are satisfied.
  • Reassess the implementation with the IB.
  • Ensure no unrelated changes are included.
  • Ensure CI checks pass.
  • Check Storybook where applicable.
  • Ensure there is a QA Brief.
  • Ensure there are no unexpected significant changes to file sizes.

Merge Reviewer Checklist

  • Ensure the PR has the correct target branch.
  • Double-check that the PR is okay to be merged.
  • Ensure the corresponding issue has a ZenHub release assigned.
  • Add a changelog message to the issue.

Copy link
github-actions bot commented May 26, 2025

Build files for 93cfaef are ready:

Copy link
github-actions bot commented May 26, 2025

Size Change: +2.97 kB (+0.14%)

Total Size: 2.13 MB

ℹ️ View Unchanged
Filename Size Change
./dist/assets/css/googlesitekit-admin-css-********************.min.css 63.2 kB 0 B
./dist/assets/css/googlesitekit-adminbar-css-********************.min.css 11.8 kB 0 B
./dist/assets/css/googlesitekit-authorize-application-css-********************.min.css 846 B 0 B
./dist/assets/css/googlesitekit-wp-dashboard-css-********************.min.css 8.47 kB 0 B
./dist/assets/js/32-********************.js 2.76 kB 0 B
./dist/assets/js/33-********************.js 2.25 kB 0 B
./dist/assets/js/34-********************.js 3.64 kB 0 B
./dist/assets/js/35-********************.js 936 B 0 B
./dist/assets/js/36-********************.js 893 B +1 B (+0.11%)
./dist/assets/js/37-********************.js 1.83 kB 0 B
./dist/assets/js/38-********************.js 3.12 kB 0 B
./dist/assets/js/analytics-advanced-tracking-********************.js 903 B 0 8000 B
./dist/assets/js/blocks/reader-revenue-manager/block-editor-plugin/editor-styles.css 124 B 0 B
./dist/assets/js/blocks/reader-revenue-manager/block-editor-plugin/editor-styles.js 492 B 0 B
./dist/assets/js/blocks/reader-revenue-manager/block-editor-plugin/index.js 8.42 kB 0 B
./dist/assets/js/blocks/reader-revenue-manager/common/editor-styles.css 307 B 0 B
./dist/assets/js/blocks/reader-revenue-manager/common/editor-styles.js 492 B 0 B
./dist/assets/js/blocks/reader-revenue-manager/contribute-with-google/index.js 9.47 kB 0 B
./dist/assets/js/blocks/reader-revenue-manager/contribute-with-google/non-site-kit-user.js 8.95 kB 0 B
./dist/assets/js/blocks/reader-revenue-manager/subscribe-with-google/index.js 9.47 kB 0 B
./dist/assets/js/blocks/reader-revenue-manager/subscribe-with-google/non-site-kit-user.js 8.96 kB 0 B
./dist/assets/js/blocks/sign-in-with-google/editor-styles.css 84 B 0 B
./dist/assets/js/blocks/sign-in-with-google/editor-styles.js 492 B 0 B
./dist/assets/js/blocks/sign-in-with-google/index.js 18.1 kB 0 B
./dist/assets/js/googlesitekit-activation-********************.js 24.3 kB +4 B (+0.02%)
./dist/assets/js/googlesitekit-ad-blocking-recovery-********************.js 57.8 kB -6 B (-0.01%)
./dist/assets/js/googlesitekit-adminbar-********************.js 37.1 kB +9 B (+0.02%)
./dist/assets/js/googlesitekit-api-********************.js 10.4 kB +1 B (+0.01%)
./dist/assets/js/googlesitekit-components-********************.js 6.8 kB +343 B (+5.31%) 🔍
./dist/assets/js/googlesitekit-consent-mode-********************.js 25.6 kB 0 B
./dist/assets/js/googlesitekit-data-********************.js 2.38 kB +1 B (+0.04%)
./dist/assets/js/googlesitekit-datastore-forms-********************.js 9.13 kB +1 B (+0.01%)
./dist/assets/js/googlesitekit-datastore-location-********************.js 2.08 kB +1 B (+0.05%)
./dist/assets/js/googlesitekit-datastore-site-********************.js 20.9 kB +6 B (+0.03%)
./dist/assets/js/googlesitekit-datastore-ui-********************.js 10.2 kB 0 B
./dist/assets/js/googlesitekit-datastore-user-********************.js 27.2 kB +5 B (+0.02%)
./dist/assets/js/googlesitekit-entity-dashboard-********************.js 68.6 kB +7 B (+0.01%)
./dist/assets/js/googlesitekit-events-provider-contact-form-7-********************.js 646 B 0 B
./dist/assets/js/googlesitekit-events-provider-easy-digital-downloads-********************.js 977 B 0 B
./dist/assets/js/googlesitekit-events-provider-mailchimp-********************.js 630 B 0 B
./dist/assets/js/googlesitekit-events-provider-ninja-forms-********************.js 717 B 0 B
./dist/assets/js/googlesitekit-events-provider-optin-monster-********************.js 675 B 0 B
./dist/assets/js/googlesitekit-events-provider-popup-maker-********************.js 634 B 0 B
./dist/assets/js/googlesitekit-events-provider-woocommerce-********************.js 1.36 kB 0 B
./dist/assets/js/googlesitekit-events-provider-wpforms-********************.js 633 B 0 B
./dist/assets/js/googlesitekit-i18n-********************.js 4.16 kB 0 B
./dist/assets/js/googlesitekit-main-dashboard-********************.js 150 kB +587 B (+0.39%)
./dist/assets/js/googlesitekit-metric-selection-********************.js 56 kB +1 B (0%)
./dist/assets/js/googlesitekit-modules-********************.js 24.1 kB -1 B (0%)
./dist/assets/js/googlesitekit-modules-ads-********************.js 51 kB +7 B (+0.01%)
./dist/assets/js/googlesitekit-modules-adsense-********************.js 134 kB +5 B (0%)
./dist/assets/js/googlesitekit-modules-analytics-4-********************.js 210 kB +525 B (+0.25%)
./dist/assets/js/googlesitekit-modules-pagespeed-insights-********************.js 26.6 kB +14 B (+0.05%)
./dist/assets/js/googlesitekit-modules-reader-revenue-manager-********************.js 45.6 kB +10 B (+0.02%)
./dist/assets/js/googlesitekit-modules-search-console-********************.js 75.3 kB +22 B (+0.03%)
./dist/assets/js/googlesitekit-modules-sign-in-with-google-********************.js 36.5 kB +15 B (+0.04%)
./dist/assets/js/googlesitekit-modules-tagmanager-********************.js 33.1 kB -11 B (-0.03%)
./dist/assets/js/googlesitekit-notifications-********************.js 54.9 kB -173 B (-0.31%)
./dist/assets/js/googlesitekit-polyfills-********************.js 377 B 0 B
./dist/assets/js/googlesitekit-settings-********************.js 137 kB +520 B (+0.38%)
./dist/assets/js/googlesitekit-splash-********************.js 75 kB +14 B (+0.02%)
./dist/assets/js/googlesitekit-user-input-********************.js 48.9 kB +453 B (+0.93%)
./dist/assets/js/googlesitekit-vendor-********************.js 313 kB +5 B (0%)
./dist/assets/js/googlesitekit-widgets-********************.js 113 kB +500 B (+0.44%)
./dist/assets/js/googlesitekit-wp-dashboard-********************.js 65.4 kB +109 B (+0.17%)
./dist/assets/js/runtime-********************.js 1.32 kB -2 B (-0.15%)

compressed-size-action

Copy link
Collaborator
@nfmohit nfmohit left a comment
8000

Choose a reason for hiding this comment

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

Brilliant work here, thank you @ankitrox!

I've left a few minor comments for your consideration. Please let me if you have any questions or concerns, thank you!

? title || customizedTooltip || ariaLabel
: null;

const buttonComponent = (
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since this variable is not reused anymore, we should get rid of it and render the component inline. What do you think?

*/
import Tooltip from '../Tooltip';

const MaybeTooltip = ( {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Our convention is to define components using the function keyword. Let's do that here.

Example:

export default function MaybeTooltip

*/
import Tooltip from '../Tooltip';

const MaybeTooltip = ( {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's define prop types for this component.

*/
import { forwardRef } from '@wordpress/element';

const SemanticButton = forwardRef(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's define prop types for this component, or somehow reuse from the parent component. While we're at it, it would be nice to update any outdated prop types.

Comment on lines 19 to 35
/**
* MaybeTooltip tests.
*
* Site Kit by Google, Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like this was duplicated.

Suggested change
/**
* MaybeTooltip tests.
*
* Site Kit by Google, Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

Copy link
Collaborator

Choose a reason for hiding this comment

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

Solid tests here, thank you!

A very nitpicky observation: We seem to be capitalising "Tooltip" in the test case names, which I think we shouldn't. Please let me know what you think, thanks!

/**
* SemanticButton tests.
*
* Site Kit by Google, Copyright 2021 Google LLC
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* Site Kit by Google, Copyright 2021 Google LLC
* Site Kit by Google, Copyright 2025 Google LLC

Comment on lines 57 to 88
it( 'should apply danger class when danger prop is true', () => {
const { container } = render(
<SemanticButton danger>Test</SemanticButton>
);
expect( container.firstChild ).toHaveClass( 'mdc-button--danger' );
} );

it( 'should apply inverse class when 8000 inverse prop is true', () => {
const { container } = render(
<SemanticButton inverse>Test</SemanticButton>
);
expect( container.firstChild ).toHaveClass( 'mdc-button--inverse' );
} );

it( 'should apply tertiary class when tertiary prop is true', () => {
const { container } = render(
<SemanticButton tertiary>Test</SemanticButton>
);
expect( container.firstChild ).toHaveClass( 'mdc-button--tertiary' );
} );

it( 'should apply callout classes when callout props are set', () => {
const { container } = render(
<SemanticButton callout calloutStyle="warning">
Test
</SemanticButton>
);
expect( container.firstChild ).toHaveClass( 'mdc-button--callout' );
expect( container.firstChild ).toHaveClass(
'mdc-button--callout-warning'
);
} );
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not very important, but this could be a nice spot to use it.each.

@ankitrox
Copy link
Collaborator Author

Thank you @nfmohit for reviewing the PR and adding your valuable suggestions.

I've addressed the feedback and sending it your way to review those.

Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0