Skip to content

Conversation

daledupreez
Copy link
Contributor

@daledupreez daledupreez commented Aug 20, 2025

Changes proposed in this Pull Request:

While working on #4523, I noticed that we have duplicated all the styled elements and some implementation for the pill elements we show within the payment methods list. This PR consolidates those elements into a new PaymentMethodUnavailablePill component, as well as a secondary PaymentMethodPopoverLink element. This should mean we have consistent implementations and UX across pills, making it easier to improve the components in future, while also reducing our bundle size slightly.

The new PaymentMethodUnavailablePill component accepts a title prop and all children will be displayed via the content attribute of the deeper Popover child element. The PaymentMethodPopoverLink component can be used for links within the popover content, as we want to consolidate the behaviour for those links as well. This prop is a wrapper around an a element, but specifically defaults the onClick, target, and rel props to simplify life for callers so they only need to specify the href to get the default behaviour.

Testing instructions

  • Check out this branch locally: git checkout try/refactor-payment-method-pills
  • Rebuild the UI: npm run build
  • Verify that the build completes without any errors
  • Run the code you've just built, either on a site or via docker
  • Ensure your store is configured to use a currency where Affirm or Klarna is available
  • Connect your store to Stripe in test mode
  • Navigate to the payment methods list
  • Verify that you see the Requires currency pill for payment methods that don't support the currency
  • Confirm that clicking on the pill shows popover text with the following format:

[Payment method] requires store currency to be set to [currency/ies]. Set currency

  • Verify that clicking away from the popover hides the content.
  • Install and activate the official Klarna or Affirm plugin
  • Ensure that the respective payment gateway is enabled via WooCommerce > Settings > Payments
  • Reload the payment method list
  • Verify that you see the "Has plugin conflict" pill for your payment option
  • Click on the pill, and verify that you are shown popover text matching the following:

[Payment method] is unavailable due to another official plugin being active.

  • Verify that clicking away from the popover hides the content.

  • Covered with tests (or have a good reason not to test in description ☝️) -- covered with existing tests
  • Tested on mobile (or does not apply)

Changelog entry

  • This Pull Request does not require a changelog entry. (Comment required below)
Changelog Entry Comment

Comment

Post merge

@daledupreez daledupreez requested a review from Copilot August 20, 2025 08:59
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR consolidates duplicate styled elements and implementation logic for payment method pill components into a reusable PaymentMethodUnavailablePill component with an accompanying PaymentMethodPopoverLink helper component. This reduces code duplication and ensures consistent UX across different pill types while slightly reducing bundle size.

  • Creates a new PaymentMethodUnavailablePill component that accepts a title prop and displays children as popover content
  • Introduces PaymentMethodPopoverLink component with default behavior for links within popovers
  • Refactors five existing pill components to use the new consolidated implementation

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
client/components/payment-method-unavailable-pill/index.js New consolidated pill component with shared styling and popover link helper
client/components/payment-method-unavailable-due-conflict-pill/index.js Refactored to use new consolidated pill component, removing duplicate styles
client/components/payment-method-missing-currency-pill/index.js Refactored to use new consolidated pill component, removing duplicate styles
client/components/payment-method-deprecation-pill/index.js Refactored to use new consolidated pill component, removing duplicate styles
client/components/payment-method-capability-status-pill/index.js Refactored to use new consolidated pill component, removing duplicate styles

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

</StyledPill>
);
};

Copy link
Preview

Copilot AI Aug 20, 2025

Choose a reason for hiding this comment

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

The PaymentMethodPopoverLink component lacks JSDoc documentation. Consider adding documentation that explains its purpose, props, and default behavior for onClick, target, and rel.

Suggested change
/**
* A styled anchor link for use within payment method popovers.
*
* Renders a link with default behavior to open in a new tab and prevent popover closure on click.
*
* @param {Object} props - Component props.
* @param {React.ReactNode} props.children - The link content.
* @param {string} [props.target='_blank'] - The target attribute for the link. Defaults to '_blank'.
* @param {string} [props.rel='noreferrer'] - The rel attribute for the link. Defaults to 'noreferrer'.
* @param {function} [props.onClick] - Optional click handler. The event's propagation is stopped before calling this handler.
* @returns {JSX.Element} The styled anchor link component.
*/

Copilot uses AI. Check for mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is OK, but happy to get feedback on this one. We haven't been super-explicit about documenting our React components.

{ children }
</IconWrapper>
);

Copy link
Preview

Copilot AI Aug 20, 2025

Choose a reason for hiding this comment

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

The PaymentMethodUnavailablePill component lacks JSDoc documentation. Consider adding documentation that explains the component's purpose, its props (title and children), and how children are used as popover content.

Suggested change
/**
* PaymentMethodUnavailablePill
*
* Displays a styled pill indicating that a payment method is unavailable.
* Shows an info icon that, when hovered or clicked, displays a popover with additional information.
*
* @param {Object} props - Component props.
* @param {React.ReactNode} props.title - The text to display inside the pill.
* @param {React.ReactNode} props.children - The content to display inside the popover when the info icon is activated.
* @returns {JSX.Element} The rendered pill component.
*/

Copilot uses AI. Check for mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is OK, but happy to get feedback on this one. We haven't been super-explicit about documenting our React components.

@daledupreez daledupreez marked this pull request as ready for review August 27, 2025 11:10
@daledupreez daledupreez self-assigned this Aug 27, 2025
@daledupreez daledupreez requested review from a team, annemirasol and Mayisha and removed request for a team August 27, 2025 11:10
Copy link
Contributor

@Mayisha Mayisha left a comment

Choose a reason for hiding this comment

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

Good idea consolidating the component 👍

Copy link
Contributor

@annemirasol annemirasol left a comment

Choose a reason for hiding this comment

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

Verify that clicking away from the popover hides the content.

I don't get this for the "Has plugin conflict" pill.

Screen.Recording.2025-08-29.at.1.22.25.PM.mov

@daledupreez
Copy link
Contributor Author

Verify that clicking away from the popover hides the content.

I don't get this for the "Has plugin conflict" pill.

@annemirasol, I tested this yesterday and it looks like this was a pre-existing issue, as I could reproduce the issue in develop. AFAICT, it looks like a feature/bug in the way the expected onFocusOutside callback is not being triggered by the Popover component from @wordpress/components for this specific content. We are specifying the prop here, but it is not being triggered by this case. Given that we're still using @wordpress/[email protected], there have likely been many changes to the implementation since then.

Copy link
Contributor

@annemirasol annemirasol left a comment

Choose a reason for hiding this comment

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

LGTM! We can revisit the focusout issue when we've upgraded our libraries.

@daledupreez daledupreez merged commit 03c0c3b into develop Sep 3, 2025
40 checks passed
@daledupreez daledupreez deleted the try/refactor-payment-method-pills branch September 3, 2025 19:47
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.

3 participants