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

Persist IOU data in Onyx #1785

Merged
merged 9 commits into from
Mar 19, 2021
Merged

Persist IOU data in Onyx #1785

merged 9 commits into from
Mar 19, 2021

Conversation

Jag96
Copy link
Contributor

@Jag96 Jag96 commented Mar 16, 2021

Details

This PR adds a new API command for GetIOUReport and starts persisting the IOUReport collection in Onyx.

Fixed Issues

Fixes https://github.com/Expensify/Expensify/issues/157104

Tests

  1. On web, log out of e.cash and open the console (cmd + option + j)
  2. Open the Application tab and select localhost:8080 under Local Storage
    image
  3. Log into an account without an IOU and check the LocalStorage keys, confirm there is nothing shown if you filter by reportIOU
    image
  4. Use the CreateIOUTransaction Curl request from https://github.com/Expensify/Expensify/issues/157104#issue-829068854 to create an IOU transaction. Ensure the debtorEmail is different from the email/accountID/authToken you set in the cookie field
  5. Log into cash as the account of the person who created the IOU. Confirm that you see a value in localStorage for reportIOU_ that contains the IOU reportID. For an example of the full data, see https://github.com/Expensify/Expensify/issues/157104#issuecomment-799886417

  1. Log out, and log into cash using the debtorEmail value you used in step 4, confirm you see a value in localStorage for reportIOU_ that contains the IOU reportID
  2. Create an IOUTransaction from an account A that has been the only one to comment on a chat report and User B is the debtor.
  3. Confirm that when logging in with UserA, the reportIOU collection contains that report.

Additionally, confirm that there are no regressions with sending messages to other accounts

Tested On

  • Web
  • Mobile Web
  • Desktop
  • iOS
  • Android

Screenshots

N/A

@Jag96 Jag96 requested a review from a team as a code owner March 16, 2021 02:02
@Jag96 Jag96 self-assigned this Mar 16, 2021
@Jag96 Jag96 removed the request for review from a team March 16, 2021 02:02
@botify botify requested a review from tgolen March 16, 2021 02:02
src/libs/actions/Report.js Outdated Show resolved Hide resolved
Julesssss
Julesssss previously approved these changes Mar 16, 2021
Copy link
Contributor

@Julesssss Julesssss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, approving for now in case no additional changes are pushed 👍

src/libs/API.js Show resolved Hide resolved
src/libs/actions/Report.js Outdated Show resolved Hide resolved
src/libs/actions/Report.js Outdated Show resolved Hide resolved
src/libs/actions/Report.js Outdated Show resolved Hide resolved
src/libs/actions/Report.js Outdated Show resolved Hide resolved
src/libs/actions/Report.js Outdated Show resolved Hide resolved
@Jag96 Jag96 changed the title [WIP] Persist IOU data in Onyx Persist IOU data in Onyx Mar 16, 2021
@Jag96
Copy link
Contributor Author

Jag96 commented Mar 16, 2021

Updated, #1785 (comment) is the only unresolved thread at the moment

@Jag96
Copy link
Contributor Author

Jag96 commented Mar 17, 2021

#1785 (comment) has been resolved, this is ready for review again!

@Julesssss
Copy link
Contributor

Julesssss commented Mar 18, 2021

I noticed two issues when running the test:

  1. I'm seeing an extra undefined 'actorEmail' in otherParticipants
    Screenshot 2021-03-18 at 13 07 44
    This makes the (otherParticipants.length > 1) condition true, preventing the getIOUReport request. Once I added .without(undefined), I was able to verify that the data was persisted to Onyx. Didn't look further into why this occurs or a better fix.

  2. I'm only seeing IOU data when logged into the account of the IOU creator
    I think this is because we're using actorEmail, which is the same value for both users. Perhaps we should use managerEmail or ownerEmail (whichever does not match the current user). These will swap depending on who owes who at the current point in time, but both emails should be available this way.

Copy link
Contributor

@Julesssss Julesssss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, but a couple of issues mentioned above need addressing

src/libs/actions/Report.js Outdated Show resolved Hide resolved
@Jag96
Copy link
Contributor Author

Jag96 commented Mar 18, 2021

I'm seeing an extra undefined 'actorEmail' in otherParticipants

I'm unable to reproduce this, what is the account setup you have for IOU testing?

I'm only seeing IOU data when logged into the account of the IOU creator

I'm also unable to reproduce this, I see the IOU data get populated when logged in as both the IOU creator and the debtor. I will try testing with some additional cases (no report_actions from the debtor, create a report with IOUs from both parties) to try to reproduce.

That testing brings up a good point however, since we're using the actorEmail to build the list of participants we may not be able to get the debtorEmail if the only person who has chatted on the report is the requestor. I'll have a look at that test case and if it is a problem, look into getting the debtorEmail another way.

@Jag96
Copy link
Contributor Author

Jag96 commented Mar 18, 2021

After some testing, I confirmed the issues above exist if the requestor is the only one with chats on a chat report. Therefore, using the actorEmail values in the reportHistory isn't enough to get the participants on a report.

Perhaps we should use managerEmail or ownerEmail (whichever does not match the current user)

The problem with this is that we don't have a managerEmail or ownerEmail in the response from getHistory. Additionally, fetching actions happens separately from where we fetch the rest of the report data, so we don't have access to the participants inside getActions where we're filtering by the "IOU" actionName.

I looked into creating a local object that keeps track of the participants of each report, similar to how we keep track of lastReadSequenceNumbers or reportMaxSequenceNumbers. Then, in handleReportChanged, I tried setting the value of chatReportParticipants[report.reportID] = report.participants. However, there is still a race condition here since the actions can fetch before the participants are updated.

Forcing the reportActions to wait until we are finished fetching the reportData is one way to fix this, but I'd rather not add that limitation unless we need to. Alternatively, we can make updates to the API to include participant data in one of the other API calls (GetHistory?). Bringing this to slack to chat about alternatives.

@Jag96
Copy link
Contributor Author

Jag96 commented Mar 19, 2021

I've created https://github.com/Expensify/Web-Expensify/pull/30506 and updated this PR so that GetIOUReport now takes reportID instead of debtorEmail. I've also updated the tests to account for the failing case as well as the Web branch required for testing.

In slack we agreed that the ideal solution would be to have Auth or the API handle figuring out the participants for a chat report, and to return all the necessary data, which will be handled in https://github.com/Expensify/Expensify/issues/157722.

This is ready for review, but now requires https://github.com/Expensify/Web-Expensify/pull/30506 to work properly

src/libs/actions/Report.js Outdated Show resolved Hide resolved
@Jag96
Copy link
Contributor Author

Jag96 commented Mar 19, 2021

Thanks for all the comments and discussion! Updated this based on the discussion in slack. Since we're already fetching reportActions as part of fetchChatReportsByIDs when we call GetReportStuff, we can grab the participants and reportActionList there, which is all that is required to call GetReportIOU.

I've also added some error handling for non-200 errors, empty reportList responses, and reportIDs of 0. I ran through the tests again and confirmed everything is working. This is ready for review again.

src/libs/actions/Report.js Show resolved Hide resolved
src/libs/actions/Report.js Outdated Show resolved Hide resolved
src/libs/actions/Report.js Outdated Show resolved Hide resolved
src/libs/actions/Report.js Show resolved Hide resolved
src/libs/actions/Report.js Outdated Show resolved Hide resolved
src/libs/actions/Report.js Show resolved Hide resolved
src/libs/actions/Report.js Outdated Show resolved Hide resolved
src/libs/actions/Report.js Outdated Show resolved Hide resolved
Julesssss
Julesssss previously approved these changes Mar 19, 2021
Copy link
Contributor

@Julesssss Julesssss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with a a few previously mentioned comments.

Ran through the tests with no issues this time, Great work!

@Jag96
Copy link
Contributor Author

Jag96 commented Mar 19, 2021

@iwiznia @tgolen Updated

src/CONST.js Outdated Show resolved Hide resolved
src/libs/actions/Report.js Show resolved Hide resolved
@Jag96
Copy link
Contributor Author

Jag96 commented Mar 19, 2021

Updated and re-tested

@Jag96 Jag96 merged commit 4bc3221 into master Mar 19, 2021
@Jag96 Jag96 deleted the joe-persist-iou-report branch March 19, 2021 20:47
@github-actions github-actions bot locked and limited conversation to collaborators Mar 19, 2021
@OSBotify
Copy link
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@tgolen
Copy link
Contributor

tgolen commented Mar 19, 2021

Sorry about not merging it! I was waiting for a test to finish... and apparently the GH page never updated when it was done.

@Jag96
Copy link
Contributor Author

Jag96 commented Mar 19, 2021

No worries! Those tests take a while!

@isagoico
Copy link

isagoico commented Mar 25, 2021

@Jag96 Hello! This one looks like it's internal QA. If so, can you go ahead with the testing? When done please let me know so I check the PR of the list. Thanks in advance!

@Expensify Expensify unlocked this conversation Mar 25, 2021
@Jag96
Copy link
Contributor Author

Jag96 commented Mar 25, 2021

Checked this off 👍

@Expensify Expensify locked as resolved and limited conversation to collaborators Mar 25, 2021
@Julesssss
Copy link
Contributor

This morning @trjExpensify and I noticed a potential regression with the Onyx changes:

The iou loading state values that we initialize here are returned null here when opening the IOUModal. The data is valid within local storage and this is only reproducible about 1 in 4 attempts.

While the simple solution would be to add a conditional check to confirm the iou object is valid, we need to confirm whether this requires a fix, or is now expected behavior.

CC @kidroca

IOURequestOnyxCrash.mov

@Julesssss
Copy link
Contributor

Moving this discussion to the PR, so that @kidroca can participate

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants