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] Remove the getTripTransactions method #55077

Open
tgolen opened this issue Jan 10, 2025 · 19 comments
Open

[$250] Remove the getTripTransactions method #55077

tgolen opened this issue Jan 10, 2025 · 19 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

@tgolen
Copy link
Contributor

tgolen commented Jan 10, 2025

Coming from #54965 (comment)

Problem

When getTripTransactions() is called, it accesses data from Onyx that the view is not connected to. This breaks the reactivity of the component because when the transactions are updated in Onyx, the component won't receive the changes. This leads to stale data.

Solution

Remove getTripTransactions() and connect to the data using useOnyx() instead.

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021877740338376092500
  • Upwork Job ID: 1877740338376092500
  • Last Price Increase: 2025-01-10
  • Automatic offers:
    • shubham1206agra | Contributor | 105641744
Issue OwnerCurrent Issue Owner: @s77rt
@tgolen tgolen added 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 Jan 10, 2025
@tgolen tgolen self-assigned this Jan 10, 2025
Copy link

melvin-bot bot commented Jan 10, 2025

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.

@tgolen tgolen added the External Added to denote the issue can be worked on by a contributor label Jan 10, 2025
Copy link

melvin-bot bot commented Jan 10, 2025

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

@melvin-bot melvin-bot bot changed the title Remove the getTripTransactions method [$250] Remove the getTripTransactions method Jan 10, 2025
Copy link

melvin-bot bot commented Jan 10, 2025

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

@shubham1206agra
Copy link
Contributor

@tgolen You need to assign me for review as no one has trip rooms set up right now.

@mohit6789
Copy link
Contributor

mohit6789 commented Jan 10, 2025

Proposal

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

Make changes in getTripTransactions() so it will use reports using withOnyx() instead of Onyx.connect

What is the root cause of that problem?

Improvement remove getTripTransactions and use withOnyx()

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

  1. Make changes in ReportsUtlis so it can access reports data using withOnyx().

App/src/libs/ReportUtils.ts

Lines 8175 to 8183 in 3541c89

function getTripTransactions(tripRoomReportID: string | undefined, reportFieldToCompare: 'parentReportID' | 'reportID' = 'parentReportID'): Transaction[] {
const tripTransactionReportIDs = Object.values(allReports ?? {})
.filter((report) => report && report?.[reportFieldToCompare] === tripRoomReportID)
.map((report) => report?.reportID);
return tripTransactionReportIDs.flatMap((reportID) => getReportTransactions(reportID));
}
function getTripIDFromTransactionParentReportID(transactionParentReportID: string | undefined): string | undefined {
return getReportOrDraftReport(transactionParentReportID)?.tripData?.tripID;

function getTripTransactions(reports: OnyxCollection<Report>, tripRoomReportID: string | undefined, reportFieldToCompare: 'parentReportID' | 'reportID' = 'parentReportID'): Transaction[] {
    const tripTransactionReportIDs = Object.values(reports ?? {})
        .filter((report) => report && report?.[reportFieldToCompare] === tripRoomReportID)
        .map((report) => report?.reportID);
    return tripTransactionReportIDs.flatMap((reportID) => getReportTransactions(reportID));
}
  1. pass reports data from TripDetailsView.tsx

const tripTransactions = ReportUtils.getTripTransactions(tripRoomReportID);

const [reports] = useOnyx(ONYXKEYS.COLLECTION.REPORT);
const tripTransactions = ReportUtils.getTripTransactions(reports, tripRoomReportID);
  1. pass reports data from TripRoomPreview.tsx
    const tripTransactions = ReportUtils.getTripTransactions(chatReport?.reportID);

changes in both the components

const [reports] = useOnyx(ONYXKEYS.COLLECTION.REPORT);
const tripTransactions = ReportUtils.getTripTransactions(reports, chatReport?.reportID);

What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

What alternative solutions did you explore? (Optional)

Copy link
Contributor

github123 Your proposal will be dismissed because you did not follow the proposal template.

@Shahidullah-Muffakir
Copy link
Contributor

Shahidullah-Muffakir commented Jan 10, 2025

Proposal

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

When getTripTransactions() is called directly in the component, it accesses Onyx data that the component is not connected to. This breaks reactivity because the component won't re-render when the underlying transactions data changes in Onyx, leading to stale data being displayed to users.

What is the root cause of that problem?

The root cause is that we're accessing Onyx data through a utility function without establishing a proper subscription to that data.

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

Instead of calling getTripTransactions() directly, we should connect to the data using useOnyx with a selector that utilizes the existing utility function. Like this:
here:

const tripTransactions = ReportUtils.getTripTransactions(tripRoomReportID);

and here:
const tripTransactions = ReportUtils.getTripTransactions(chatReport?.reportID);

write it like this:

    const [tripTransactions] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {
        selector:(reports)=>  ReportUtils.getTripTransactions(reports, chatReport?.reportID),
    });

and accept reports as param in the getTripTransactions

What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

What alternative solutions did you explore? (Optional)

@tgolen tgolen assigned shubham1206agra and unassigned s77rt Jan 10, 2025
@melvin-bot melvin-bot bot removed the Help Wanted Apply this label when an issue is open to proposals by contributors label Jan 10, 2025
Copy link

melvin-bot bot commented Jan 10, 2025

📣 @shubham1206agra 🎉 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 📖

@shubham1206agra
Copy link
Contributor

I am sorry everyone. But this will be handled by @blazejkustra since you don't have access to trip rooms.

@shubham1206agra
Copy link
Contributor

@blazejkustra Please comment here so we can get you assigned.

@blazejkustra
Copy link
Contributor

Commenting for assigment.

@tgolen
Copy link
Contributor Author

tgolen commented Jan 10, 2025

Sorry, I didn't realize this was a locked-down feature!

@melvin-bot melvin-bot bot added the Overdue label Jan 13, 2025
@isabelastisser
Copy link
Contributor

@shubham1206agra @blazejkustra, can you please provide an update? What are the next steps? Thanks!

@melvin-bot melvin-bot bot removed the Overdue label Jan 13, 2025
@blazejkustra
Copy link
Contributor

blazejkustra commented Jan 14, 2025

Sorry, I had other tasks that required my attention. I'm starting to work on this one now!

Remove getTripTransactions() and connect to the data using withOnyx() instead.

@tgolen I assume you meant to use useOnyx, and not withOnyx (as it is deprecated)

@tgolen
Copy link
Contributor Author

tgolen commented Jan 14, 2025

Ah, haha, yes. useOnyx 😂

@blazejkustra
Copy link
Contributor

blazejkustra commented Jan 15, 2025

@tgolen Draft PR is up, please let me know if it’s in line with what you had in mind!

I found another issue though, and I'm not sure what is the best approach to fixing it and I'd be glad to hear your thoughts (also cc @rlinoz @shubham1206agra). Basically, whenever you make a reservation, a report action is added to the workspace chat with a trip preview (TripRoomPreview component). And while it looks well when the nested data is loaded:

Image

It doesn't work right after I sign in, this is because the nested trips aren't fetched from the backend:

Image

In order to see them I have to click on 'View trip', which as a side effect calls OpenReport for the trip:

Image

Any idea how to fix it? Maybe there is a similar flow in the app already.

@rlinoz
Copy link
Contributor

rlinoz commented Jan 15, 2025

This is the same as report previews right? I think the fix is to return the reports either on OpenApp or on OpenReport for the parent report, not sure which one we do for report previews

@tgolen
Copy link
Contributor Author

tgolen commented Jan 15, 2025

Sounds like a backend fix needs to be done for that, yeah. I'll cc @stitesExpensify about it so he is aware of the issue.

@melvin-bot melvin-bot bot added Reviewing Has a PR in review Weekly KSv2 and removed Daily KSv2 labels Jan 17, 2025
@blazejkustra
Copy link
Contributor

Update: PR is under review

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

8 participants