Skip to content
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

UIPFU-91 - React v19: refactor away from default props for functional components #285

Merged
merged 19 commits into from
Jan 15, 2025

Conversation

Terala-Priyanka
Copy link
Contributor

@Terala-Priyanka Terala-Priyanka commented Dec 27, 2024

Purpose

UIPFU-91 - React v19: refactor away from default props for functional components

Approach

refactor 4 components from class based to functional based components and refactor away from default props.

NOTE: There is no test file for UserSearchView.js
Coverage would be enhanced in the scope of an existing tech debt ticket - https://folio-org.atlassian.net/browse/UIPFU-85

Learning

Pre-Merge Checklist

Before merging this PR, please go through the following list and take appropriate actions.

  • I've added appropriate record to the CHANGELOG.md
  • Does this PR meet or exceed the expected quality standards?
    • Code coverage on new code is 80% or greater
    • Duplications on new code is 3% or less
    • There are no major code smells or security issues
  • Does this introduce breaking changes?
    • If any API-related changes - okapi interfaces and permissions are reviewed/changed correspondingly
    • There are no breaking changes in this PR.

If there are breaking changes, please STOP and consider the following:

  • What other modules will these changes impact?
  • Do JIRAs exist to update the impacted modules?
    • If not, please create them
    • Do they contain the appropriate level of detail? Which endpoints/schemas changed, etc.
    • Do they have all they appropriate links to blocked/related issues?
  • Are the JIRAs under active development?
    • If not, contact the project's PO and make sure they're aware of the urgency.
  • Do PRs exist for these changes?
    • If so, have they been approved?

Ideally all of the PRs involved in breaking changes would be merged in the same day to avoid breaking the folio-testing environment. Communication is paramount if that is to be achieved, especially as the number of intermodule and inter-team dependencies increase.

While it's helpful for reviewers to help identify potential problems, ensuring that it's safe to merge is ultimately the responsibility of the PR assignee.

Copy link

github-actions bot commented Dec 27, 2024

Jest Unit Test Statistics

19 tests  +19   19 ✔️ +19   39s ⏱️ +39s
  4 suites +  4     0 💤 ±  0 
  1 files   +  1     0 ±  0 

Results for commit 5ce77ef. ± Comparison against base commit d98e258.

♻️ This comment has been updated with latest results.

This comment has been minimized.

Copy link

github-actions bot commented Dec 27, 2024

BigTest Unit Test Statistics

0 tests  ±0   0 ✔️ ±0   0s ⏱️ ±0s
0 suites ±0   0 💤 ±0 
0 files   ±0   0 ±0 

Results for commit 5ce77ef. ± Comparison against base commit d98e258.

♻️ This comment has been updated with latest results.

@Terala-Priyanka Terala-Priyanka marked this pull request as draft December 27, 2024 09:58
@Terala-Priyanka Terala-Priyanka marked this pull request as ready for review December 30, 2024 08:30
@Terala-Priyanka Terala-Priyanka requested a review from a team December 30, 2024 08:30
Comment on lines +22 to +28
// eslint-disable-next-line no-unused-vars
onModalClose,
renderTrigger,
// eslint-disable-next-line no-unused-vars
dataKey = 'find_patron',
// eslint-disable-next-line no-unused-vars
initialSelectedUsers,

Choose a reason for hiding this comment

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

Why are unused variables specified?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They are being passed to child components. Also they need default props to be mentioned.

// don't inadvertently pass in other resources which could result in resource confusion.
const isolatedProps = _omit(this.props, ['parentResources', 'resources', 'mutator', 'parentMutator']);
}
}, [isModalOpen, afterClose]);

Choose a reason for hiding this comment

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

I think adding afterClose function to deps is unsafe, as it now always needs to be memorized using useCallback to avoid triggering useEffect multiple times. The previous implementation didn't require this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Earlier Class based approach had a provision to make callbacks after setting while setState. Functional components do not work this way, right?
Also afterClose is a prop and called only when the modal is closed and only based on some conditions, I think it is fine here.

Comment on lines +8 to +13
const Filters = ({
activeFilters,
onChangeHandlers,
config,
resultOffset,
}) => {

Choose a reason for hiding this comment

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

Class components will continue to support defaultProps since there is no ES6 alternative.

Moving class components to functional ones seems redundant doc.

React v19: refactor away from default props for functional components

Is there any reason to touch class components?

Copy link
Contributor Author

@Terala-Priyanka Terala-Priyanka Dec 30, 2024

Choose a reason for hiding this comment

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

no specific reason. As we have been following the standard of creating only functional components in new developments and also refactoring the components from class based to functional based as and when there is an opportunity, I have taken this opportunity for the refactor.

@Dmytro-Melnyshyn Dmytro-Melnyshyn requested a review from a team December 30, 2024 11:12
@s3fs s3fs requested a review from a team January 8, 2025 10:24
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
39.5% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@s3fs s3fs merged commit 0935663 into master Jan 15, 2025
5 of 6 checks passed
@s3fs s3fs deleted the UIPFU-91 branch January 15, 2025 09:23
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.

5 participants