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

Followup #23961: update IOU report total in optimistic data on edit money request #25498

Conversation

BeeMargarida
Copy link
Contributor

@BeeMargarida BeeMargarida commented Aug 18, 2023

Details

Updates the optimistic data of the IOU report when a money request is edited. It only updates it if the currency matches and the amount was changed.

Fixed Issues

$ #23961

Tests

  1. Open a money request
  2. Go offline
  3. Edit the amount
  4. Check that the total amount updates
  • Verify that no errors appear in the JS console

Offline tests

  1. Open a money request
  2. Go offline
  3. Edit the amount
  4. Check that the total amount updates

QA Steps

  1. Open a money request
  2. Go offline
  3. Edit the amount
  4. Check that the total amount updates
  • Verify that no errors appear in the JS console

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 / Chrome
    • iOS / native
    • iOS / 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 a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • If we are not using the full Onyx data that we loaded, I've added the proper selector in order to ensure the component only re-renders when the data it is using changes
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • 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(themeColors.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 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.
  • I have checked off every checkbox in the PR author checklist, including those that don't apply to this PR.

Screenshots/Videos

Web
web_t.mp4
Mobile Web - Chrome
mchrome_t.mp4
Mobile Web - Safari
msafari_t.mp4
Desktop
desktop_t.mp4
iOS
ios_t.mp4
Android
android_t.mp4

@BeeMargarida BeeMargarida marked this pull request as ready for review August 21, 2023 10:56
@BeeMargarida BeeMargarida requested a review from a team as a code owner August 21, 2023 10:56
@melvin-bot melvin-bot bot requested review from allroundexperts and removed request for a team August 21, 2023 10:56
@melvin-bot
Copy link

melvin-bot bot commented Aug 21, 2023

@allroundexperts 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]

@allroundexperts
Copy link
Contributor

allroundexperts commented Aug 21, 2023

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible 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 checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified tests pass on all platforms & I tested again on:
    • Android / native
    • Android / Chrome
    • iOS / native
    • iOS / Safari
    • MacOS / Chrome / Safari
    • MacOS / Desktop
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (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
    • 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 verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • 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
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • 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(themeColors.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 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.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Web
screen-recording-2023-08-28-at-24350-pm_Ci0fDSzK.mp4
screen-recording-2023-08-28-at-24600-pm_W0q2mj8b.mp4
Mobile Web - Chrome
Screen.Recording.2023-08-28.at.2.54.02.PM.mov
Mobile Web - Safari
Screen.Recording.2023-08-28.at.3.03.01.PM.mov
Desktop
Screen.Recording.2023-08-28.at.2.49.42.PM.mov
iOS
Screen.Recording.2023-08-28.at.3.01.21.PM.mov
Android
Screen.Recording.2023-08-28.at.3.20.27.PM.mov

@allroundexperts
Copy link
Contributor

Hi @BeeMargarida!
The amount on the LHN isn't changing.

Screen.Recording.2023-08-21.at.8.45.20.PM.mov

@BeeMargarida
Copy link
Contributor Author

BeeMargarida commented Aug 21, 2023

@allroundexperts Hum, it seems to be working on my side. Are you using the same currency as the one in the report, right?

(I merged with main, I was having some issues with logging in)

asd_t.mp4

@allroundexperts
Copy link
Contributor

I was using the same currency as in report. I will try again!

@allroundexperts
Copy link
Contributor

Still happening for me @BeeMargarida. @mountiny Can you maybe confirm this please?

Screen.Recording.2023-08-22.at.1.18.38.AM.mov

@mountiny
Copy link
Contributor

For me its partial. The IOU report updates, the report title of the request is still the old 30 instead of 40 and the report preview total is incorrect. Could we look into updating that too? @BeeMargarida
image

@allroundexperts
Copy link
Contributor

It's the same for me. The title in the LHN never updates.

@mountiny
Copy link
Contributor

@BeeMargarida Lets make sure to circle back to this one today 🙇

@BeeMargarida
Copy link
Contributor Author

Working on this still, it's more tricky than I though. Fixed the previews, just missing the update to the request title

@mountiny
Copy link
Contributor

thanks for the update

@BeeMargarida
Copy link
Contributor Author

@allroundexperts @mountiny Should be fixed now

change_t.mp4

@mountiny
Copy link
Contributor

@allroundexperts any chance you can get to this today?

@allroundexperts
Copy link
Contributor

@mountiny I'll look at all the outstanding PRs after 3 hours.

src/components/LHNOptionsList/OptionRowLHNData.js Outdated Show resolved Hide resolved
Comment on lines 90 to 91
const transactionID = lodashGet(parentReportAction, ['originalMessage', 'IOUTransactionID'], '');
const transaction = lodashGet(transactions, [`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`], '');
Copy link
Contributor

Choose a reason for hiding this comment

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

You can also just load this single transaction by composing multiple withOnyx.

Copy link
Contributor

Choose a reason for hiding this comment

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

This will cause a lot of re-renders since we're including all the transactions. Similar optimisation can also be done for the parentReportAction above

Copy link
Contributor Author

@BeeMargarida BeeMargarida Aug 24, 2023

Choose a reason for hiding this comment

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

You mean having several withOnyx that depend on one another? Won't those also be injected as props? Or we ignore the transactions prop and only use the one transaction?

Copy link
Contributor Author

@BeeMargarida BeeMargarida Aug 24, 2023

Choose a reason for hiding this comment

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

I don't think this is possible, because there's no way to access the parentReportAction by key. And this parentReportAction is necessary to access the transaction. So we can't do this in withOnyx.
Or am I missing something? 🤔

The only thing that I think would work is make a withReportActions where we could pass transformValue that selected the report action taking into account the fullreport.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can use selector function from onyx. No?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think so, because in the selector we don't have access to the props, so we couldn't use the fullReport to access the correct report action

Copy link
Contributor

Choose a reason for hiding this comment

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

Hm...
Can't you add the following here:

withOnyx({
            transaction: {
                key: ({parentReportActions, fullReport}) => `${ONYXKEYS.COLLECTION.TRANSACTION}${lodashGet(parentReportActions[fullReport.parentReportActionID], ['originalMessage', 'IOUTransactionID'], '')}`,
                canEvict: false,
            },
        }),

Copy link
Contributor Author

@BeeMargarida BeeMargarida Aug 24, 2023

Choose a reason for hiding this comment

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

Yap, I think I can do that, but I can't make the same refactor to parentReportActions.
Well, I can, but I need to make a withReportActions HOC (allows to use the props in transformValue so we can only get the report action that we want). I've developed this and it seems to work fine. Do you think this optimization is worth it?
Note: the optimization could also be applied to the policies prop.

Copy link
Contributor

@allroundexperts allroundexperts Aug 24, 2023

Choose a reason for hiding this comment

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

If you're the owner of this code, and you think its not worth it, then I'm totally fine with this as well!

@mountiny Do you agree?

src/libs/actions/IOU.js Outdated Show resolved Hide resolved
src/libs/actions/IOU.js Outdated Show resolved Hide resolved
src/libs/actions/IOU.js Show resolved Hide resolved
src/libs/actions/IOU.js Outdated Show resolved Hide resolved
src/libs/actions/IOU.js Show resolved Hide resolved
src/libs/actions/IOU.js Outdated Show resolved Hide resolved
src/libs/actions/IOU.js Outdated Show resolved Hide resolved
src/libs/actions/IOU.js Outdated Show resolved Hide resolved
@BeeMargarida
Copy link
Contributor Author

BeeMargarida commented Aug 24, 2023

@allroundexperts @mountiny Updated! As mentioned above, I've not optimized the parentReportActions, but I have the HOC code, in case we end up going that way. For now, only the transaction and policy were optimized in OptionRowLHNData

@mountiny mountiny changed the title [hold merge freeze] Followup #23961: update IOU report total in optimistic data on edit money request Followup #23961: update IOU report total in optimistic data on edit money request Sep 11, 2023
Copy link
Contributor

@allroundexperts allroundexperts left a comment

Choose a reason for hiding this comment

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

This is working well. However, @mountiny the description is not getting updated optimistically. Do we have an issue to keep track of this?

Also, editing a request which resulted from a split bill request originally, does not reflect in the actual split bill report. Not sure if we are tracking this either.

@mountiny
Copy link
Contributor

Also, editing a request which resulted from a split bill request originally, does not reflect in the actual split bill report. Not sure if we are tracking this either.

This is out of scope

This is working well. However, @mountiny the description is not getting updated optimistically. Do we have an issue to keep track of this?

What do you mean exactly?

@allroundexperts
Copy link
Contributor

What do you mean exactly?

When you update the description (while offline), the updated description does not show up in the top bar until you refresh the page.

@mountiny
Copy link
Contributor

Oh I get waht you mean now and I am not sure if there is an issue for that. I think we could actually just fix it in this PR? @BeeMargarida would you be available to address this. Update the description in the header optimistically too when its changed. In the screenshot its the for test

image

@BeeMargarida
Copy link
Contributor Author

BeeMargarida commented Sep 12, 2023

@mountiny @allroundexperts Hum, weird, I'm positive this was working before 🤔 I'll check it out

@BeeMargarida
Copy link
Contributor Author

@mountiny @allroundexperts Should be working now 👍

vid_t.mp4

@allroundexperts
Copy link
Contributor

Getting this console error @BeeMargarida.

Screenshot 2023-09-13 at 4 08 28 AM

Otherwise, this is working well.

Screen.Recording.2023-09-13.at.4.04.12.AM.mov

@BeeMargarida
Copy link
Contributor Author

@allroundexperts Should be fixed now

@mountiny
Copy link
Contributor

@allroundexperts can you please double check?

@allroundexperts
Copy link
Contributor

Working well now!

Screen.Recording.2023-09-14.at.6.12.31.AM.mov

mountiny
mountiny previously approved these changes Sep 14, 2023
Copy link
Contributor

@mountiny mountiny left a comment

Choose a reason for hiding this comment

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

One question

src/components/MoneyRequestHeader.js Outdated Show resolved Hide resolved
@BeeMargarida
Copy link
Contributor Author

@mountiny Updated!

Copy link
Contributor

@mountiny mountiny left a comment

Choose a reason for hiding this comment

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

Thanks for the patience here!

@mountiny mountiny merged commit 1a49026 into Expensify:main Sep 14, 2023
12 checks passed
@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/mountiny in version: 1.3.70-0 🚀

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

// from the server with the currency conversion
let updatedMoneyRequestReport = {...iouReport};
const updatedChatReport = {...chatReport};
if (updatedTransaction.currency === iouReport.currency && updatedTransaction.modifiedAmount) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@BeeMargarida @rezkiy37 run into an issue because the modifiedAmount is true after oneamount update, the modified amount is always there, I think we have to look at the amount diff here, are you able to make a follow up PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I'll make a PR with that fix

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The regression fix PR: #27451 (comment)

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/thienlnam in version: 1.3.70-8 🚀

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

onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport.chatReportID}`,
value: updatedChatReport,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

We should have set lastReadTime and lastVisibleActionCreated of transaction thread report in optimistic data.
Without this, unread indicator didn't show even after marking report action as unread after changing date offline.
Issue: #27159


// Update the last message of the chat report
const messageText = Localize.translateLocal('iou.payerOwesAmount', {
payer: updatedMoneyRequestReport.managerEmail,
Copy link
Contributor

Choose a reason for hiding this comment

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

How hard would it be to update this to use updatedMoneyRequestReport.managerID instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

We're trying to get rid of all uses of managerEmail 🙏

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess not that hard just time consuming as we need to make prs across stack from back to front end and back, do you have an issue specifically for these flows?

Copy link
Contributor

Choose a reason for hiding this comment

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

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.

9 participants