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

[HOLD for payment 2024-10-25] [$250] Migrate IOURequestStepDistanceRate to useOnyx #50334

Closed
neil-marcellini opened this issue Oct 7, 2024 · 20 comments
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Weekly KSv2

Comments

@neil-marcellini
Copy link
Contributor

neil-marcellini commented Oct 7, 2024

Problem

Coming from this PR, there's a warning that withOnyx is deprecated and we should migrate this component to useOnyx

/Users/NeilMarcellini/Expensidev/App/src/pages/iou/request/step/IOURequestStepDistanceRate.tsx
  138:44  error  'withOnyx' is deprecated. Use `useOnyx` instead of `withOnyx` whenever possible.

Solution

Do the migration

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021843307064145973750
  • Upwork Job ID: 1843307064145973750
  • Last Price Increase: 2024-10-07
Issue OwnerCurrent Issue Owner: @abekkala / @isabelastisser
@neil-marcellini neil-marcellini added External Added to denote the issue can be worked on by a contributor Daily KSv2 Help Wanted Apply this label when an issue is open to proposals by contributors Bug Something is broken. Auto assigns a BugZero manager. labels Oct 7, 2024
@neil-marcellini neil-marcellini self-assigned this Oct 7, 2024
@melvin-bot melvin-bot bot changed the title Migrate IOURequestStepDistanceRate to useOnyx [$250] Migrate IOURequestStepDistanceRate to useOnyx Oct 7, 2024
Copy link

melvin-bot bot commented Oct 7, 2024

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

Copy link

melvin-bot bot commented Oct 7, 2024

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

Copy link

melvin-bot bot commented Oct 7, 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.

@shahinyan11
Copy link
Contributor

Can I work on it ?

@mkzie2
Copy link
Contributor

mkzie2 commented Oct 7, 2024

I'd love to work on this issue.

@mkzie2
Copy link
Contributor

mkzie2 commented Oct 7, 2024

Proposal

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

Migrate IOURequestStepDistanceRate to useOnyx

What is the root cause of that problem?

This is a migration

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

Remove withOnyx HOC and replace it with useOnyx. We should use || to prevent crashing when using useOnyx with report?.policyID is changed from an empty string to an ID. We also need to update IOURequestStepDistanceRateProps with removing IOURequestStepDistanceRateOnyxProps

const [policyReal] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID || '-1'}`);
const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID || '-1'}`);
const [policyTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID || '-1'}`);

const IOURequestStepDistanceRateWithOnyx = withOnyx<IOURequestStepDistanceRateProps, IOURequestStepDistanceRateOnyxProps>({
policy: {
key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report ? report.policyID : '-1'}`,
},
policyCategories: {
key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${report ? report.policyID : '0'}`,
},
policyTags: {
key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${report ? report.policyID : '0'}`,
},
})(IOURequestStepDistanceRate);
// eslint-disable-next-line rulesdir/no-negated-variables
const IOURequestStepDistanceRateWithWritableReportOrNotFound = withWritableReportOrNotFound(IOURequestStepDistanceRateWithOnyx);
// eslint-disable-next-line rulesdir/no-negated-variables

What alternative solutions did you explore? (Optional)

@twilight2294
Copy link
Contributor

twilight2294 commented Oct 7, 2024

Proposal

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

Migrate IOURequestStepDistanceRate to use useOnyx instead of withOnyx.

What is the root cause of that problem?

N/A feature request

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

  • First remove the withOnyx and directly set:
const IOURequestStepDistanceRateWithWritableReportOrNotFound = withWritableReportOrNotFound(IOURequestStepDistanceRate);

Then remove the IOURequestStepDistanceRateOnyxProps completely.

And then finally get the values of policyCategories policyTags and policyReal using useOnyx:

--- a/src/pages/iou/request/step/IOURequestStepDistanceRate.tsx
+++ b/src/pages/iou/request/step/IOURequestStepDistanceRate.tsx
@@ -1,6 +1,6 @@
 import React from 'react';
 import type {OnyxEntry} from 'react-native-onyx';
-import {useOnyx, withOnyx} from 'react-native-onyx';
+import {useOnyx} from 'react-native-onyx';


@@ -23,38 +23,27 @@ import withFullTransactionOrNotFound from './withFullTransactionOrNotFound';
 import type {WithWritableReportOrNotFoundProps} from './withWritableReportOrNotFound';
 import withWritableReportOrNotFound from './withWritableReportOrNotFound';
 
-type IOURequestStepDistanceRateOnyxProps = {
-    /** Policy details */
-    policy: OnyxEntry<OnyxTypes.Policy>;
 
-    /** Collection of categories attached to the policy */
-    policyCategories: OnyxEntry<OnyxTypes.PolicyCategories>;
-
-    /** Collection of tags attached to the policy */
-    policyTags: OnyxEntry<OnyxTypes.PolicyTagLists>;
-};
-
-type IOURequestStepDistanceRateProps = IOURequestStepDistanceRateOnyxProps &
-    WithWritableReportOrNotFoundProps<typeof SCREENS.MONEY_REQUEST.STEP_DISTANCE_RATE> & {
+type IOURequestStepDistanceRateProps = WithWritableReportOrNotFoundProps<typeof SCREENS.MONEY_REQUEST.STEP_DISTANCE_RATE> & {

 
 function IOURequestStepDistanceRate({
-    policy: policyReal,
     report,
     reportDraft,
     route: {
         params: {action, reportID, backTo, transactionID},
     },
     transaction,
-    policyTags,
-    policyCategories,
 }: IOURequestStepDistanceRateProps) {
     const [policyDraft] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_DRAFTS}${IOU.getIOURequestPolicyID(transaction, reportDraft) ?? '-1'}`);
-
+    const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${report?.policyID ?? '0'}`)
+    const [policyTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${report?.policyID ?? '0'}`)
+    const [policyReal] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID ?? '-1'}`)
     const policy = policyReal ?? policyDraft;
 
+


@@ -133,20 +122,9 @@ function IOURequestStepDistanceRate({
 
 IOURequestStepDistanceRate.displayName = 'IOURequestStepDistanceRate';
 
-const IOURequestStepDistanceRateWithOnyx = withOnyx<IOURequestStepDistanceRateProps, IOURequestStepDistanceRateOnyxProps>({
-    policy: {
-        key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report ? report.policyID : '-1'}`,
-    },
-    policyCategories: {
-        key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${report ? report.policyID : '0'}`,
-    },
-    policyTags: {
-        key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${report ? report.policyID : '0'}`,
-    },
-})(IOURequestStepDistanceRate);
 
 // eslint-disable-next-line rulesdir/no-negated-variables
-const IOURequestStepDistanceRateWithWritableReportOrNotFound = withWritableReportOrNotFound(IOURequestStepDistanceRateWithOnyx);
+const IOURequestStepDistanceRateWithWritableReportOrNotFound = withWritableReportOrNotFound(IOURequestStepDistanceRate);

 

What alternative solutions did you explore? (Optional)

@neil-marcellini
Copy link
Contributor Author

Looks like @mkzie2 posted the first sufficient proposal, so I'm hiring him to get this moving. Thanks!

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

melvin-bot bot commented Oct 8, 2024

📣 @mkzie2 You have been assigned to this job!
Please apply to the Upwork job and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review 🧑‍💻
Once you apply to this job, your Upwork ID will be stored and you will be automatically hired for future jobs!
Keep in mind: Code of Conduct | Contributing 📖

@rushatgabhane
Copy link
Member

@mkzie2 feel free to raise a PR

@melvin-bot melvin-bot bot added Reviewing Has a PR in review Weekly KSv2 and removed Daily KSv2 labels Oct 10, 2024
@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 @isabelastisser (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.

@melvin-bot melvin-bot bot added Daily KSv2 and removed Weekly KSv2 labels Oct 11, 2024
@abekkala
Copy link
Contributor

@isabelastisser I'll be ooo until Mon Oct 21
Given that the PR has not deployed to prod starting the 7 day waiting period yet I don't expect this to come to payment before I return from ooo on Oct 21.

STATUS: PR created but not deployed to prod yet

Payment Summary [date, TBD]:

@abekkala abekkala self-assigned this Oct 11, 2024
Copy link

melvin-bot bot commented Oct 18, 2024

@abekkala, @neil-marcellini, @rushatgabhane, @isabelastisser, @mkzie2 Whoops! This issue is 2 days overdue. Let's get this updated quick!

@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Daily KSv2 labels Oct 18, 2024
@melvin-bot melvin-bot bot changed the title [$250] Migrate IOURequestStepDistanceRate to useOnyx [HOLD for payment 2024-10-25] [$250] Migrate IOURequestStepDistanceRate to useOnyx Oct 18, 2024
Copy link

melvin-bot bot commented Oct 18, 2024

Reviewing label has been removed, please complete the "BugZero Checklist".

@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Oct 18, 2024
Copy link

melvin-bot bot commented Oct 18, 2024

The solution for this issue has been 🚀 deployed to production 🚀 in version 9.0.50-8 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

If no regressions arise, payment will be issued on 2024-10-25. 🎊

For reference, here are some details about the assignees on this issue:

  • @rushatgabhane requires payment through NewDot Manual Requests
  • @mkzie2 requires payment (Needs manual offer from BZ)

Copy link

melvin-bot bot commented Oct 18, 2024

BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:

  • [@rushatgabhane] The PR that introduced the bug has been identified. Link to the PR:
  • [@rushatgabhane] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake. Link to comment:
  • [@rushatgabhane] A discussion in #expensify-bugs has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner. Link to discussion:
  • [@rushatgabhane] Determine if we should create a regression test for this bug.
  • [@rushatgabhane] If we decide to create a regression test for the bug, please propose the regression test steps to ensure the same bug will not reach production again.
  • [@abekkala / @isabelastisser] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:

@abekkala
Copy link
Contributor

I'm back from ooo - unassigning @isabelastisser

@abekkala
Copy link
Contributor

Payment Summary OCT 25

  • Fix: @mkzie2 [$250, if no regression] OFFER
  • PR Review: @rushatgabhane [$250, if no regression] payment via NewDot
    please complete checklist

@rushatgabhane
Copy link
Member

Not a bug. Checklist not needed.

Migration was planned as part of PR - #50001 (comment)

@abekkala
Copy link
Contributor

@mkzie2 payment sent and contract ended - thank you! 🎉

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

No branches or pull requests

7 participants