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

[$250] Migrate MoneyRequestConfirmationList to useOnyx #50532

Open
neil-marcellini opened this issue Oct 9, 2024 · 14 comments
Open

[$250] Migrate MoneyRequestConfirmationList to useOnyx #50532

neil-marcellini opened this issue Oct 9, 2024 · 14 comments
Assignees
Labels
Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Reviewing Has a PR in review Weekly KSv2

Comments

@neil-marcellini
Copy link
Contributor

neil-marcellini commented Oct 9, 2024

Problem

In this PR I made some changes to MoneyRequestConfirmationList, which trigged the ESLint changed files check to error saying that we need to migrate withOnyx to useOnyx

Solution migrate to useOnyx

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021844152421070937252
  • Upwork Job ID: 1844152421070937252
  • Last Price Increase: 2024-10-09
  • Automatic offers:
    • shubham1206agra | Reviewer | 104434485
    • NJ-2020 | Contributor | 104434486
Issue OwnerCurrent Issue Owner: @shubham1206agra
@neil-marcellini neil-marcellini added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Oct 9, 2024
@neil-marcellini neil-marcellini self-assigned this Oct 9, 2024
Copy link

melvin-bot bot commented Oct 9, 2024

Triggered auto assignment to @abekkala (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

@neil-marcellini neil-marcellini added the External Added to denote the issue can be worked on by a contributor label Oct 9, 2024
@melvin-bot melvin-bot bot changed the title Migrate MoneyRequestConfirmationList to useOnyx [$250] Migrate MoneyRequestConfirmationList to useOnyx Oct 9, 2024
Copy link

melvin-bot bot commented Oct 9, 2024

Job added to Upwork: https://www.upwork.com/jobs/~021844152421070937252

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Oct 9, 2024
Copy link

melvin-bot bot commented Oct 9, 2024

Triggered auto assignment to Contributor-plus team member for initial proposal review - @shubham1206agra (External)

@Shahidullah-Muffakir
Copy link
Contributor

Proposal

Please re-state the problem that we are trying to solve in this issue.

We are trying to migrate the MoneyRequestConfirmationList component from using the withOnyx HOC to the useOnyx hook.

What is the root cause of that problem?

The current implementation uses withOnyx, which is an older pattern for connecting components to Onyx data.

What changes do you think we should make in order to solve the problem?

In this file:

type MoneyRequestConfirmationListProps = MoneyRequestConfirmationListOnyxProps & {

  1. Remove the withOnyx HOC from the MoneyRequestConfirmationList component.
  2. Add the useOnyx hook inside the MoneyRequestConfirmationList component to fetch these data:

export default withOnyx<MoneyRequestConfirmationListProps, MoneyRequestConfirmationListOnyxProps>({
policyCategories: {
key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`,
},
policyCategoriesDraft: {
key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES_DRAFT}${policyID}`,

@NJ-2020
Copy link
Contributor

NJ-2020 commented Oct 9, 2024

Proposal

Please re-state the problem that we are trying to solve in this issue.

Migrate MoneyRequestConfirmationList to useOnyx

What is the root cause of that problem?

N/A

What changes do you think we should make in order to solve the problem?

Change from withOnyx here:

export default withOnyx<MoneyRequestConfirmationListProps, MoneyRequestConfirmationListOnyxProps>({
policyCategories: {
key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`,
},
policyCategoriesDraft: {
key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES_DRAFT}${policyID}`,
},
policyTags: {
key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`,
},
defaultMileageRate: {
key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
selector: DistanceRequestUtils.getDefaultMileageRate,
},
mileageRates: {
key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
selector: (policy: OnyxEntry<OnyxTypes.Policy>) => DistanceRequestUtils.getMileageRates(policy),
},
policy: {
key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
},
policyDraft: {
key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY_DRAFTS}${policyID}`,
},
lastSelectedDistanceRates: {
key: ONYXKEYS.NVP_LAST_SELECTED_DISTANCE_RATES,
},
currencyList: {
key: ONYXKEYS.CURRENCY_LIST,
},
})(

to useOnyx:

const [policyCategoriesReal] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID || '-1'}`);
const [policyCategoriesDraft] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES_DRAFT}${policyID || '-1'}`);
const [policyTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID || '-1'}`);
const [defaultMileageRate] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID || '-1'}`, {
    selector: DistanceRequestUtils.getDefaultMileageRate,
});
const [mileageRatesReal] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID || '-1'}`, {
    selector: (policy: OnyxEntry<OnyxTypes.Policy>) => DistanceRequestUtils.getMileageRates(policy),
});
const [policyReal] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID || '-1'}`);
const [policyDraft] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_DRAFTS}${policyID || '-1'}`);
const [lastSelectedDistanceRates] = useOnyx(ONYXKEYS.NVP_LAST_SELECTED_DISTANCE_RATES);
const [currencyList] = useOnyx(ONYXKEYS.CURRENCY_LIST);

And remove the MoneyRequestConfirmationListOnyxProps type

type MoneyRequestConfirmationListProps = MoneyRequestConfirmationListOnyxProps & {

type MoneyRequestConfirmationListOnyxProps = {
/** Collection of categories attached to a policy */
policyCategories: OnyxEntry<OnyxTypes.PolicyCategories>;
/** Collection of draft categories attached to a policy */

And the parameters from the function
And also remove this

lodashIsEqual(prevProps.defaultMileageRate, nextProps.defaultMileageRate) &&
lodashIsEqual(prevProps.lastSelectedDistanceRates, nextProps.lastSelectedDistanceRates) &&

lodashIsEqual(prevProps.currencyList, nextProps.currencyList) &&

What alternative solutions did you explore? (Optional)

@abekkala abekkala removed their assignment Oct 11, 2024
@abekkala abekkala added Bug Something is broken. Auto assigns a BugZero manager. and removed Bug Something is broken. Auto assigns a BugZero manager. labels Oct 11, 2024
Copy link

melvin-bot bot commented Oct 11, 2024

Triggered auto assignment to @anmurali (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

@abekkala
Copy link
Contributor

@anmurali I'll be ooo until Mon Oct 21; then I can take this back.

STATUS: proposals have been posted, waiting on one to be chosen

Copy link

melvin-bot bot commented Oct 14, 2024

@abekkala, @anmurali, @neil-marcellini, @shubham1206agra Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

@melvin-bot melvin-bot bot added the Overdue label Oct 14, 2024
@neil-marcellini
Copy link
Contributor Author

I like @NJ-2020's proposal best so far since it's sufficiently detailed while the one before it was not quite detailed enough. Hiring! @shubham1206agra please try to review proposals more promptly next time or re-assign.

@melvin-bot melvin-bot bot removed the Help Wanted Apply this label when an issue is open to proposals by contributors label Oct 15, 2024
Copy link

melvin-bot bot commented Oct 15, 2024

📣 @shubham1206agra 🎉 An offer has been automatically sent to your Upwork account for the Reviewer role 🎉 Thanks for contributing to the Expensify app!

Offer link
Upwork job

Copy link

melvin-bot bot commented Oct 15, 2024

📣 @NJ-2020 🎉 An offer has been automatically sent to your Upwork account for the Contributor role 🎉 Thanks for contributing to the Expensify app!

Offer link
Upwork job
Please accept the offer and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review 🧑‍💻
Keep in mind: Code of Conduct | Contributing 📖

@melvin-bot melvin-bot bot removed the Overdue label Oct 15, 2024
@melvin-bot melvin-bot bot added Reviewing Has a PR in review Weekly KSv2 and removed Daily KSv2 labels Oct 16, 2024
@NJ-2020
Copy link
Contributor

NJ-2020 commented Oct 16, 2024

PR ready

cc: @shubham1206agra

@abekkala
Copy link
Contributor

I'm back from ooo - unassinging @anmurali

@abekkala
Copy link
Contributor

PR not yet deployed

Fix: @NJ-2020
PR Review: @shubham1206agra

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Reviewing Has a PR in review Weekly KSv2
Projects
None yet
Development

No branches or pull requests

6 participants