Skip to content

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

Closed

Description

@neil-marcellini

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

Activity

  1. added
    External
    Daily
    Help Wanted
    Bug
    on Oct 7, 2024
  2. changed the title [-]Migrate IOURequestStepDistanceRate to useOnyx[/-] [+][$250] Migrate IOURequestStepDistanceRate to useOnyx[/+] on Oct 7, 2024
  3. melvin-bot commented on Oct 7, 2024

    @melvin-bot
  4. melvin-bot commented on Oct 7, 2024

    @melvin-bot

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

  5. melvin-bot commented on Oct 7, 2024

    @melvin-bot

    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.

  6. shahinyan11 commented on Oct 7, 2024

    @shahinyan11
    Contributor

    Can I work on it ?

  7. mkzie2 commented on Oct 7, 2024

    @mkzie2
    Contributor

    I'd love to work on this issue.

  8. mkzie2 commented on Oct 7, 2024

    @mkzie2
    Contributor

    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)

  9. twilight2294 commented on Oct 7, 2024

    @twilight2294
    Contributor

    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)

  10. 18 remaining items

  11. added
    Weekly
    Awaiting Payment
    and removed
    Daily
    on Oct 18, 2024
  12. changed the title [-][$250] Migrate IOURequestStepDistanceRate to useOnyx[/-] [+][HOLD for payment 2024-10-25] [$250] Migrate IOURequestStepDistanceRate to useOnyx[/+] on Oct 18, 2024
  13. melvin-bot commented on Oct 18, 2024

    @melvin-bot

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

  14. removed
    Reviewing
    on Oct 18, 2024
  15. melvin-bot commented on Oct 18, 2024

    @melvin-bot

    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)
  16. melvin-bot commented on Oct 18, 2024

    @melvin-bot

    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:
  17. abekkala commented on Oct 21, 2024

    @abekkala
    Contributor

    I'm back from ooo - unassigning @isabelastisser

  18. abekkala commented on Oct 21, 2024

    @abekkala
    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
  19. rushatgabhane commented on Oct 23, 2024

    @rushatgabhane
    Member

    Not a bug. Checklist not needed.

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

  20. abekkala commented on Oct 25, 2024

    @abekkala
    Contributor

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

  21. garrettmknight commented on Oct 29, 2024

    @garrettmknight
    Contributor

    $250 approved for @rushatgabhane

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Awaiting PaymentBugExternalWeekly

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions