Skip to content

Component cleanup: Icons, paths, links, code style (3928) #3319

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 1 commit into
base: trunk
Choose a base branch
from

Conversation

mmaymo
Copy link
Contributor

@mmaymo mmaymo commented Apr 14, 2025

This PR fixes js lint in the settings module. Some rules were suppressed to avoid changing implementation

some rules suppressed to avoid changing implementation
@mmaymo mmaymo requested a review from stracker-phil April 14, 2025 13:27
@@ -36,6 +36,7 @@ const PricingTitleBadge = ( { item } ) => {
);

const label = sprintf(
// Translators: %1$s is the percentage, %2$s is the fixed amount.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice 👍

@@ -57,7 +57,9 @@ const filterSteps = ( steps, conditions ) => {
};

export const getSteps = ( flags ) => {
// eslint-disable-next-line react-hooks/rules-of-hooks
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of ignoring the "rules-of-hooks" check:

  • My initial idea was to pass all conditions as arguments, like getSteps( flags, skipPaymentsScreen ), ie keep it a plain helper function without dependencies (would also make it more testable)
  • An alternative would be to change the helper method to become a real hook -- change getSteps(flags) to useSteps() or similar, then we can drop the flags argument and collect all details inside the hook

The current mix of receiving input arguments and collecting other details via hooks is a bit messy

? // eslint-disable-next-line react-hooks/rules-of-hooks
CommonHooks.useSandbox()
: // eslint-disable-next-line react-hooks/rules-of-hooks
CommonHooks.useProduction();
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of ignoring these warnings, I think it would be better to correct the code to call hooks unconditionally:

  const sandboxData = CommonHooks.useSandbox();
  const productionData = CommonHooks.useProduction();
  
  const { onboardingUrl } = isSandbox ? sandboxData : productionData;

const [ syncCompleted, setSyncCompleted ] = useState( false );
const [ syncError, setSyncError ] = useState( null );
const [ , setSyncCompleted ] = useState( false );
const [ , setSyncError ] = useState( null );
Copy link
Contributor

Choose a reason for hiding this comment

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

Hm... looks like we do not use those two states. There's no point in setting the state but not using the value anywhere.

To clean this up, the two states should be completely removed from the code.

Possibly, those states are a left over from a previous change

@stracker-phil
Copy link
Contributor

As we're working on this, can you also remove this utility file?

https://github.com/woocommerce/woocommerce-paypal-payments/blob/800bf1b7660d802b4358643e2d15f4b039abad2b/modules/ppcp-settings/resources/js/utils/data.js

This file contains a deprecated helper that's only used in a single component:

https://github.com/woocommerce/woocommerce-paypal-payments/blob/800bf1b7660d802b4358643e2d15f4b039abad2b/modules/ppcp-settings/resources/js/Components/ReusableComponents/PaymentMethodIcons.js

I would really like to delete data.js, as we should not use the getImage() helper anywhere, except inside the PaymentMethodIcon component - here's an idea for a much cleaner solution:

import { Icon } from '@wordpress/components';

const imageUrl( name ) {
  const filename = `icon-button-${ name }.svg`;
  
  // Move the logic into this file, as a private helper method.
}

const PaymentMethodIcon = ( { type } ) => (
  <Icon
    icon={ imageUrl( type ) }
    className="ppcp--method-icon"
  />
);

export default PaymentMethodIcon;

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