Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Remove propTypes definitions from Reviews By Product #9692

Conversation

hritikchaudhary
Copy link
Contributor

Fixes #9522
Fixes woocommerce/woocommerce#42362

Changes in the PR:

Removed propTypes definitions from Reviews By Category.

Testing

Automated Tests

  • Changes in this PR are covered by Automated Tests.
    • Unit tests
    • E2E tests

User Facing Testing

  • Do not include in the Testing Notes

WooCommerce Visibility

  • WooCommerce Core
  • Feature plugin
  • Experimental

@hritikchaudhary
Copy link
Contributor Author

Hi @nielslange this PR following ts errors will be flagged:

  1. onChange - ProductControl in which this onChange is used is yet to be converted in ts will be converted in Convert index.js to index.tsx and replace propTypes with TypeScript definitions #9537 the error is: image

  2. noReviewsPlaceholder: image
    when i try to convert NoReviewsPlaceholder to a ReactElementLike or it asks me for mandatory properties, if i provide them then it stops showing This block lists reviews for a selected product. %s doesn't have any reviews yet, but they will show up here when it does. if product have no reviews.

If there are any other approach/method i can try please let me know I'll update the code.

I tried resolving them but no luck ended up in a rabbit hole and changed multiple files but this goes to other module as well so I reverted my changes

@nielslange nielslange mentioned this pull request Jun 2, 2023
@nielslange nielslange added type: refactor The issue/PR is related to refactoring. skip-changelog PRs that you don't want to appear in the changelog. block: reviews by product Issues related to the Reviews by Product block. labels Jun 2, 2023
@nielslange
Copy link
Member

onChange - ProductControl in which this onChange is used is yet to be converted in ts will be converted in #9537

Thanks for reaching out, @hritikchaudhary, and letting me know that you'll address that TS error in #9537.

If there are any other approach/method i can try please let me know I'll update the code.

I tried resolving them but no luck ended up in a rabbit hole and changed multiple files but this goes to other module as well so I reverted my changes

@gigitux Do you see how to address the second TS error @hritikchaudhary mentioned in #9692 (comment)? I looked into it, but could only came up with the following fix.

  • Changing noReviewsPlaceholder={ NoReviewsPlaceholder } to noReviewsPlaceholder={ <NoReviewsPlaceholder /> } in assets/js/blocks/reviews/reviews-by-product/block.tsx.
  • Changing getProduct: () => void; to getProduct?: () => void; in assets/js/blocks/reviews/reviews-by-product/types.ts.

However, this fix does not look elegant to me. I'm excited to hearing your thoughts on this.

Copy link
Member

@nielslange nielslange left a comment

Choose a reason for hiding this comment

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

Thanks for working on this, @hritikchaudhary. Below, I left some feedback regarding moving inline TS definitions into the corresponding component. I wonder what your thoughts are on that.

@hritikchaudhary
Copy link
Contributor Author

  • Changing noReviewsPlaceholder={ NoReviewsPlaceholder } to noReviewsPlaceholder={ <NoReviewsPlaceholder /> } in assets/js/blocks/reviews/reviews-by-product/block.tsx.
  • Changing getProduct: () => void; to getProduct?: () => void; in assets/js/blocks/reviews/reviews-by-product/types.ts.

I tried this yesterday, but it gives a different error in ErrorPlaceholder of no-reviews-placeholder, as it is expecting ErrorPlaceholderProps and gives the following error
Type '{ className: string; error: ErrorObject; isLoading: boolean; onRetry: (() => void) | undefined; }' is not assignable to type 'ErrorPlaceholderProps' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties. Types of property 'onRetry' are incompatible. Type '(() => void) | undefined' is not assignable to type '() => void'. Type 'undefined' is not assignable to type '() => void'.ts(2375)

@gigitux
Copy link
Contributor

gigitux commented Jun 6, 2023

onChange - ProductControl in which this onChange is used is yet to be converted in ts will be converted in #9537

Thanks for reaching out, @hritikchaudhary, and letting me know that you'll address that TS error in #9537.

If there are any other approach/method i can try please let me know I'll update the code.
I tried resolving them but no luck ended up in a rabbit hole and changed multiple files but this goes to other module as well so I reverted my changes

@gigitux Do you see how to address the second TS error @hritikchaudhary mentioned in #9692 (comment)? I looked into it, but could only came up with the following fix.

  • Changing noReviewsPlaceholder={ NoReviewsPlaceholder } to noReviewsPlaceholder={ <NoReviewsPlaceholder /> } in assets/js/blocks/reviews/reviews-by-product/block.tsx.
  • Changing getProduct: () => void; to getProduct?: () => void; in assets/js/blocks/reviews/reviews-by-product/types.ts.

However, this fix does not look elegant to me. I'm excited to hearing your thoughts on this.

For the noReviewsPlaceholder error, you can create a d.ts file for the withProduct HOC. I created a POC PR to show it hritikchaudhary#1. In general, I would say to keep this solution as just temporary since the best approach is to convert the HOC to Typescript as well.

@nielslange nielslange requested review from gigitux and removed request for nielslange June 6, 2023 10:11
@hritikchaudhary
Copy link
Contributor Author

For the noReviewsPlaceholder error, you can create a d.ts file for the withProduct HOC. I created a POC PR to show it hritikchaudhary#1. In general, I would say to keep this solution as just temporary since the best approach is to convert the HOC to Typescript as well.

Hi Luigi, thanks for the feedback, I'll look into it and push the improved changes soon..

@nielslange nielslange removed their request for review June 19, 2023 09:06
@hritikchaudhary
Copy link
Contributor Author

Closed this PR due to numerous merge conflicts and #9522 is already fixed in different PR raised #10249 to fix woocommerce/woocommerce#42362

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
block: reviews by product Issues related to the Reviews by Product block. skip-changelog PRs that you don't want to appear in the changelog. type: community contribution type: refactor The issue/PR is related to refactoring.
Projects
None yet
3 participants