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

Adds optimistic data for transaction threads with violations #35449

Merged

Conversation

cdanwards
Copy link
Contributor

@cdanwards cdanwards commented Jan 31, 2024

Details

Fixed Issues

$ #31411

PROPOSAL:

This PR addresses the need to add the optimistic data necessary for transaction threads to display in the LHN even when offline. We do this by creating transaction threads and created actions for those threads and adding that data to the optimistic data within RequestMoney, CreateDistanceRequest, and SplitBill and subsequently passing that thread and created action data to the API Calls.

There were a few instances where logic needed to be altered in order for transaction threads with violations to correctly display in the LHN.

Some bug fixes that were discovered in the creation of this:

  • originalMessage needed to be added to the mapped version of reportActions in SidebarLinksData so that we correctly identify threads with violations
  • adding policy, policyTags, and policyCategories to the splitBill function to correctly create transactionViolations onyx collections for those transactions

Issue 34548 is also resolved within this PR by adding a check to ReportUtils for the status of the report and if it is reimbursed, we don't want to display a transaction thread with violations.

Tests

  • Verify that no errors appear in the JS console

Pre-testing Instructions

  • Verify you have a workspace with violations enabled and that have required Tags and Categories and that you have an account with that workspace.
  • Verify that you have the canUseViolations beta enabled

Testing Money Request

  • Select the Floating Action Button (FAB) within the Left Hand Navigation (LHN) and then select Request Money
  • Select Manual as the entry method and enter an amount.
  • Select the Next button.
  • Select your workspace from the possible options.
  • Verify you have been taken to the Money Request Confirmation Screen.
  • Select the Merchant row and enter a merchant name, then hit the Save button. (It can be anything and this is required to continue)
  • Select the Request button
  • Verify that the Money Request you just created appears in the LHN with an RBR indicator.
  • Select and verify the information.

Testing Distance Requests

  • Select the Floating Action Button (FAB) within the Left Hand Navigation (LHN) and then select Request Money
  • Select the Distance tab
  • Select the Start row and in the input screen type 100 5th Ave New York NY and select the address
  • Select the End row and in the input screen type 400 5th Ave New York NY and select the address
  • Select the Next button
  • Select your Workspace from the available options
  • Verify that the amount 1.41 miles and that the date is correct.
  • Select the Request button
  • Verify that the transaction thread correctly appears in the LHN with the correct information and an RBR indicator.

Splits are included in the functionality of this PR and so transaction threads are created optimistically however because violations aren't created for splits, they will not appear in the LHN. To test that they are created correctly, you can log the optimisticTransactionThread and optimisticCreatedActionForTransactionThread within the createSplitsAndOnyxData in the IOU.js file. Then within the OnyxDB in the Storage browser tab you can verify that those reports and report actions have been created.

Offline tests

Same as Tests

QA Steps

Same as Tests

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I verified the translation was requested/reviewed in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Android_480.mov
Android: mWeb Chrome
AndroidChrome_480.mov
iOS: Native
iOS_480.mov
iOS: mWeb Safari
iOS_Safari.mov
MacOS: Chrome / Safari
Web_480.mov
MacOS: Desktop
Desktop_480.mov

const reportIsSettled = report.statusNum === CONST.REPORT.STATUS_NUM.REIMBURSED;

// Always show IOU reports with violations unless they are reimbursed
if (isExpenseRequest(report) && doesReportHaveViolations && !reportIsSettled) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moving this check up to this location was discussed here: https://expensify.slack.com/archives/C01GTK53T8Q/p1706026331938069

@cdanwards cdanwards marked this pull request as ready for review February 2, 2024 16:52
@cdanwards cdanwards requested a review from a team as a code owner February 2, 2024 16:52
@cdanwards
Copy link
Contributor Author

@cead22 this is ready for review!

@melvin-bot melvin-bot bot requested review from grgia and removed request for a team February 2, 2024 16:53
Copy link

melvin-bot bot commented Feb 2, 2024

@grgia Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@cead22 cead22 requested review from cead22 and removed request for grgia February 5, 2024 21:56
@cead22
Copy link
Contributor

cead22 commented Feb 6, 2024

Thanks! There are conflicts on this branch, once they're resolved I'll bring a C+ to review

@cdanwards
Copy link
Contributor Author

@cead22 saw the conflicts at end of day today, will be fixing tomorrow morning!

@cead22
Copy link
Contributor

cead22 commented Feb 6, 2024

Sounds good, thank you!

@situchan

This comment was marked as off-topic.

@situchan
Copy link
Contributor

#33114 is not fixed yet. Bug still happening:

Screen.Recording.2024-02-20.at.7.12.37.PM.mov

@situchan
Copy link
Contributor

@cdanwards please at least test and upload one platform video which involves all test cases

@cead22
Copy link
Contributor

cead22 commented Feb 23, 2024

#33114 is not fixed yet. Bug still happening:

@situchan I believe this diff fixes it, can you give it a try?

diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts
index cda09f99c5..1e3ad06c46 100644
--- a/src/libs/actions/IOU.ts
+++ b/src/libs/actions/IOU.ts
@@ -883,7 +883,7 @@ function getMoneyRequestInformation(
     const currentTime = DateUtils.getDBTime();
     const optimisticCreatedActionForChat = ReportUtils.buildOptimisticCreatedReportAction(payeeEmail);
     const optimisticCreatedActionForIOU = ReportUtils.buildOptimisticCreatedReportAction(payeeEmail, DateUtils.subtractMillisecondsFromDateTime(currentTime, 1));
-    const iouAction = ReportUtils.buildOptimisticIOUReportAction(
+    let iouAction = ReportUtils.buildOptimisticIOUReportAction(
         CONST.IOU.REPORT_ACTION_TYPE.CREATE,
         amount,
         currency,
@@ -899,6 +899,7 @@ function getMoneyRequestInformation(
         currentTime,
     );
     const optimisticTransactionThread = ReportUtils.buildTransactionThread(iouAction, iouReport.reportID);
+    iouAction.childReportID = optimisticTransactionThread.reportID;
     const optimisticCreatedActionForTransactionThread = ReportUtils.buildOptimisticCreatedReportAction(payeeEmail);
 
     let reportPreviewAction = shouldCreateNewMoneyRequestReport ? null : ReportActionsUtils.getReportPreviewAction(chatReport.reportID, iouReport.reportID);

Also, I'm thinking we merge this PR as is even if it doesn't fix #33114, so long as it passes the other tests, and we can unlink that issue from this PR and work on the fix for that issue separately, since we can't update this PR anymore.

Alternatively, I can create a new PR with all the commits from this one, and the fix above -- assuming it works (the thing is that I'm having issue running the app on mweb on android).

What do you think?

@situchan
Copy link
Contributor

Above change works! Need to tackle more to make TS check happy

Screenshot 2024-02-23 at 6 33 34 AM

@situchan
Copy link
Contributor

Also, I'm thinking we merge this PR as is even if it doesn't fix #33114, so long as it passes the other tests, and we can unlink that issue from this PR and work on the fix for that issue separately, since we can't update this PR anymore.

👍

@cead22
Copy link
Contributor

cead22 commented Feb 23, 2024

Cool, I updated the description to remove the link and the tests for 33114. Can you complete the reviewer checklist when you get a chance.

If everything works fine for you (other than 33114), we can merge this PR, and I'll update #33114 with a better problem description, the diff above, and find a contributor to work on it

@situchan
Copy link
Contributor

situchan commented Feb 23, 2024

Just to remind again from https://expensify.slack.com/archives/C01GTK53T8Q/p1705432850640919?thread_ts=1705336943.293449&cid=C01GTK53T8Q

For a money request that has a violation:

  • The money request view show should violations for both payee and payer
  • The money request preview show should violations for both
  • The report preview should show a RBR for both
  • The LHN only for the payee should show the transaction thread with RBR -- clicking this chat takes you to the money request view

Am I missing something? #34548 isn't fixed yet.

RBR still shows in LHN for already paid request on payee side

Screenshot 2024-02-23 at 6 09 30 PM

@situchan
Copy link
Contributor

situchan commented Feb 23, 2024

@cead22 RBR doesn't show at all on payer side. As this PR isn't supposed to handle them and didn't touch this logic, I consider them out of scope.

(payer: dark mode, payee: light mode)

  • ReportPreview
Screenshot 2024-02-23 at 5 19 47 PM Screenshot 2024-02-23 at 5 19 53 PM
  • MoneyRequestPreview
Screenshot 2024-02-23 at 5 20 27 PM Screenshot 2024-02-23 at 5 20 32 PM
  • MoneyRequestView
Screenshot 2024-02-23 at 5 20 57 PM Screenshot 2024-02-23 at 5 21 00 PM

@situchan
Copy link
Contributor

Looks like there's bug in backend. After creating distance request without category, default category is auto-selected.
Reproducible on both this branch and main so not frontend bug.

Screen.Recording.2024-02-23.at.5.50.55.PM.mov

@situchan
Copy link
Contributor

situchan commented Feb 23, 2024

Checklist complete.
Reported a few concerns/bugs above (#35449 (comment) #35449 (comment) #35449 (comment)). Otherwise looks good.

@cead22
Copy link
Contributor

cead22 commented Feb 23, 2024

Thanks for the thorough review

Am I missing something? #34548 isn't fixed yet.

I don't think you're missing anything, and I see some code meant to handle this, but let's merge and fix this in a separate PR

@cead22 RBR doesn't show at all on payer side. As this PR isn't supposed to handle them and didn't touch this logic, I consider them out of scope.

Agreed

Looks like there's bug in backend. After creating distance request without category, default category is auto-selected.
Reproducible on both this branch and main so not frontend bug.

Agreed. This may be due to implicit categorization, which is a feature we have where we set the category automatically for a request with merchant X, if you've created requests before with merchant X and have added a category to it. You should be able to reproduce this by creating a manual request with a specific merchant, and add a category to it, and then create a second manual request with the same merchant

@situchan
Copy link
Contributor

situchan commented Feb 23, 2024

@cead22 mind assigning me (for C+ role) in follow-up issues since I have context?

@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.

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/cead22 in version: 1.4.44-0 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@kavimuru
Copy link

@cead22 Should the QA team test?

Splits are included in the functionality of this PR and so transaction threads are created optimistically however because violations aren't created for splits, they will not appear in the LHN. To test that they are created correctly, you can log the optimisticTransactionThread and optimisticCreatedActionForTransactionThread within the createSplitsAndOnyxData in the IOU.js file. Then within the OnyxDB in the Storage browser tab you can verify that those reports and report actions have been created.

@kavimuru
Copy link

@cdanwards or @situchan could you please help with the above? Seems we can't test.

Splits are included in the functionality of this PR and so transaction threads are created optimistically however because violations aren't created for splits, they will not appear in the LHN. To test that they are created correctly, you can log the optimisticTransactionThread and optimisticCreatedActionForTransactionThread within the createSplitsAndOnyxData in the IOU.js file. Then within the OnyxDB in the Storage browser tab you can verify that those reports and report actions have been created.

@situchan
Copy link
Contributor

@cdanwards or @situchan could you please help with the above? Seems we can't test.

Splits are included in the functionality of this PR and so transaction threads are created optimistically however because violations aren't created for splits, they will not appear in the LHN. To test that they are created correctly, you can log the optimisticTransactionThread and optimisticCreatedActionForTransactionThread within the createSplitsAndOnyxData in the IOU.js file. Then within the OnyxDB in the Storage browser tab you can verify that those reports and report actions have been created.

yes, it's dev only tests. You can skip that.

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/puneetlath in version: 1.4.44-13 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@danieldoglas
Copy link
Contributor

@cead22 can you confirm if #37296 is an intended result of these changes?

@cead22
Copy link
Contributor

cead22 commented Mar 5, 2024

Can you be more specific? transaction threads that have violations should show RBR on the LHN for the person that made the request, and only for them

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

Successfully merging this pull request may close these issues.

7 participants