Skip to content

[PAID] [$500] Update getIOUReportActionDisplayMessage() to accept the transaction as a parameter #38355

Closed

Description

@tgolen

This is coming from #27262. You can read the issue description there to get context behind the problem being solved and the mess being cleaned up.

Problem

ReportUtils.getIOUReportActionDisplayMessage() is called from a view component. It contains logic which calls const transaction = TransactionUtils.getTransaction(originalMessage.IOUTransactionID ?? ''); (a deprecated method).

Why this is important to fix

It maintains more pure and exact flow of data through the react application. If the view is using transaction data, then it needs to subscribe to the transaction in Onyx so that it's assured that the transaction object will never be stale or out-of-date.

Solution

  • Pass transaction as a parameter to getIOUReportActionDisplayMessage() and get the parameter from withOnyx() in the view component.
  • Remove the deprecated method completely
Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01cae110240999840b
  • Upwork Job ID: 1768370164615811072
  • Last Price Increase: 2024-03-14
  • Automatic offers:
    • hoangzinh | Reviewer | 0
    • FitseTLT | Contributor | 0
Issue OwnerCurrent Issue Owner: @strepanier03

Activity

  1. added
    ExternalAdded to denote the issue can be worked on by a contributor
    BugSomething is broken. Auto assigns a BugZero manager.
    on Mar 14, 2024
  2. self-assigned this
    on Mar 14, 2024
  3. changed the title [-]Update getIOUReportActionDisplayMessage() to accept the transaction as a parameter[/-] [+][$500] Update getIOUReportActionDisplayMessage() to accept the transaction as a parameter[/+] on Mar 14, 2024
  4. melvin-bot commented on Mar 14, 2024

    @melvin-bot
  5. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Mar 14, 2024
  6. melvin-bot commented on Mar 14, 2024

    @melvin-bot

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

  7. melvin-bot commented on Mar 14, 2024

    @melvin-bot

    Triggered auto assignment to @strepanier03 (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.

  8. FitseTLT commented on Mar 14, 2024

    @FitseTLT
    Contributor

    Proposal

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

    Update getIOUReportActionDisplayMessage() to accept the transaction as a parameter

    What is the root cause of that problem?

    Enhancement

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

    Update getIOUReportActionDisplayMessage to accept transaction as a parameter instead of this

    App/src/libs/ReportUtils.ts

    Lines 4958 to 4959 in 02e8025

    const transaction = TransactionUtils.getTransaction(originalMessage.IOUTransactionID ?? '');
    const transactionDetails = getTransactionDetails(!isEmptyObject(transaction) ? transaction : null);

    and pass transaction from withOnyx (using transactionID action.originalMessage.IOUTransactionID) for REportactionItem here

    And for context menu action we will subscribe to transaction in here

    },
    reportActions: {
    key: ({originalReportID}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${originalReportID}`,
    canEvict: false,
    },

    we will pass reportActions and reportActionID to the key and we will subscribe to transaction with transactionID we get from the report action's originalMessage.IOUTransactionID and pass the transaction to onPress in the payload when the context menu item is copy to clipboard ( textTranslateKey=='reportActionContextMenu.copyToClipboard') here
    onPress={(event) => interceptAnonymousUser(() => contextAction.onPress?.(closePopup, {...payload, event}), contextAction.isAnonymousAction)}
    description={contextAction.getDescription?.(selection) ?? ''}

    and we will pass the transaction when we call getIOUReportActionDisplayMessage
    const displayMessage = ReportUtils.getIOUReportActionDisplayMessage(reportAction);
    Clipboard.setString(displayMessage);

    What alternative solutions did you explore? (Optional)

    for the context menu ,of course we can omit the transaction parameter and continue the current method of fetching transaction as we are currently doing because we don't have stale data worry for it as the function will be executed when the user presses copy to clipboard not when context menu component is first rendered 👍

  9. allgandalf commented on Mar 14, 2024

    @allgandalf
    Contributor

    Proposal

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

    Update getIOUReportActionDisplayMessage() to accept the transaction as a parameter

    What is the root cause of that problem?

    We want to update getIOUReportActionDisplayMessage as getTransaction is depricated

    function getIOUReportActionDisplayMessage(reportAction: OnyxEntry<ReportAction>): string {

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

    First we need to update getIOUReportActionDisplayMessage to accept one additional prop :

    function getIOUReportActionDisplayMessage( transaction OnyxEntry<Transaction>): string {

    Then remove the reportAction references as we get it from component:

    App/src/libs/ReportUtils.ts

    Lines 4958 to 4959 in aca0f8c

    const transaction = TransactionUtils.getTransaction(originalMessage.IOUTransactionID ?? '');
    const transactionDetails = getTransactionDetails(!isEmptyObject(transaction) ? transaction : null);

    Finally we need to get transaction parameter with withOnyx in each component and pass it, currently we use getIOUReportActionDisplayMessage in :

    iouMessage = ReportUtils.getIOUReportActionDisplayMessage(action);

    const displayMessage = ReportUtils.getIOUReportActionDisplayMessage(reportAction);

    What alternative solutions did you explore? (Optional)

    N/A

  10. Krishna2323 commented on Mar 14, 2024

    @Krishna2323
    Contributor

    Proposal

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

    Update getIOUReportActionDisplayMessage() to accept the transaction as a parameter

    What is the root cause of that problem?

    Enhancement

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

    We need to pass transaction from these two places, in ReportActionItemMessage we can use withOnyx & in ContextMenuActions we need to use Onyx.connect.
    We will use reportAction.originalMessage.IOUTransactionID to get the data fro Onyx.

    iouMessage = ReportUtils.getIOUReportActionDisplayMessage(action);

    const displayMessage = ReportUtils.getIOUReportActionDisplayMessage(reportAction);

    Here we need to accept transaction prop and remove the line.

    App/src/libs/ReportUtils.ts

    Lines 4925 to 4928 in 2737e44

    /**
    * Return iou report action display message
    */
    function getIOUReportActionDisplayMessage(reportAction: OnyxEntry<ReportAction>): string {

    const transaction = TransactionUtils.getTransaction(originalMessage.IOUTransactionID ?? '');

    Result

    Alternative

    Instead of adding additional prop, we can utilize the transactions we have in ReportUtils, we have already connected to Onyx for transactions. We can use it like

    allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${iouMessage?.IOUTransactionID}`] ?? ({} as Transaction)

    App/src/libs/ReportUtils.ts

    Lines 499 to 509 in 2737e44

    let allTransactions: OnyxCollection<Transaction> = {};
    Onyx.connect({
    key: ONYXKEYS.COLLECTION.TRANSACTION,
    waitForCollectionCallback: true,
    callback: (value) => {
    if (!value) {
    return;
    }
    allTransactions = Object.fromEntries(Object.entries(value).filter(([, transaction]) => transaction));
    },
    });

  11. allgandalf commented on Mar 14, 2024

    @allgandalf
    Contributor

    Updated Proposal

    Removed the reference of reportAction from the new function in my proposal

  12. 38 remaining items

  13. melvin-bot commented on Apr 8, 2024

    @melvin-bot

    The solution for this issue has been 🚀 deployed to production 🚀 in version 1.4.60-13 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-04-15. 🎊

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

  14. melvin-bot commented on Apr 8, 2024

    @melvin-bot
  15. strepanier03 commented on Apr 16, 2024

    @strepanier03
    Contributor

    @hoangzinh - Please complete the checklist as soon as you can and then I'll handle your payment.

    @FitseTLT - I've paid your contract and closed it in Upwork, thanks!

  16. hoangzinh commented on Apr 17, 2024

    @hoangzinh
    Contributor

    Hi @strepanier03 we don't have a checklist for this issue because it's not a bug fix but a technical improvement.

  17. hoangzinh commented on Apr 17, 2024

    @hoangzinh
    Contributor

    oh @tgolen @FitseTLT we still have another follow-up task here #38882 (comment)

  18. tgolen commented on Apr 17, 2024

    @tgolen
    ContributorAuthor
  19. strepanier03 commented on Apr 17, 2024

    @strepanier03
    Contributor

    Thanks @hoangzinh for clarification 🙌.

  20. changed the title [-][HOLD for payment 2024-04-15] [$500] Update getIOUReportActionDisplayMessage() to accept the transaction as a parameter[/-] [+][PAID] [$500] Update getIOUReportActionDisplayMessage() to accept the transaction as a parameter[/+] on Apr 17, 2024
  21. strepanier03 commented on Apr 17, 2024

    @strepanier03
    Contributor

    Okay, this is all paid out and contracts are closed. Thank you both, @hoangzinh and @FitseTLT, for your work on this.

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

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributor

Type

No type

Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions