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

Fix/issue 29899 #30232

Merged
merged 22 commits into from
Nov 7, 2023
Merged

Fix/issue 29899 #30232

merged 22 commits into from
Nov 7, 2023

Conversation

Tony-MK
Copy link
Contributor

@Tony-MK Tony-MK commented Oct 24, 2023

Details

#29899

Fixed Issues

$ #29899
PROPOSAL: #29899 (comment)

Tests

  1. Create a distance request, if none exists
  2. Go Offline
  3. Change the waypoints in the existing distance request
  4. Verify that the amount is replaced with TBD
  5. Verify that the distance in the merchant string is replaced with TBD
  • Verify that no errors appear in the JS console

Offline tests

QA Steps

  • 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: 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 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

Android: Native
Android.-.Native.webm
Android: mWeb Chrome
Android.-.Chrome.webm
iOS: Native
iOS.-.Native.webm
iOS: mWeb Safari
iOS.-.Safari.webm
MacOS: Chrome / Safari
macOS.-.Chrome.mp4
macOS.-.Safari.webm
MacOS: Desktop
macOS.-.Desktop.webm

…nly distance request and the waypoints were modified and not yet updated to the server.
@Tony-MK Tony-MK requested a review from a team as a code owner October 24, 2023 04:11
@melvin-bot melvin-bot bot removed the request for review from a team October 24, 2023 04:11
@melvin-bot
Copy link

melvin-bot bot commented Oct 24, 2023

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

@melvin-bot melvin-bot bot requested a review from ArekChr October 24, 2023 04:11
Tony-MK and others added 2 commits October 25, 2023 12:04
Co-authored-by: Arkadiusz Chrabąszczewski <[email protected]>
@ArekChr
Copy link
Contributor

ArekChr commented Oct 26, 2023

@Tony-MK TypeScript check fails, please fix the issues and update branch with main

@Tony-MK
Copy link
Contributor Author

Tony-MK commented Oct 26, 2023

Hey @ArekChr, Sorry for the delays. If you don't mind, there are two things I'm a bit curious about.

  1. There are some components that are not consistent with distance requests that have recently been created offline and are TBD. Such as the money request header and total sum are supposed to show TBD. Also, the opacity of the amount and date fields are dimmed. Should I make it consistent with distance requests made offline?

  2. I believe there is a bug with the ReportPreview component. When a user changes the waypoints offline, two or more map images will be displayed. One will show the pending map due to the changes we have made, and the rest will show the original map or another map. It seems to have two or more transactions when the waypoints change for a singular distance request. This bug currently occurs in staging and production. I can't seem to figure out which appropriate logic to use so that the ReportPreview component shows TBD and the correct number of maps when every request in the report is a distance request and all are TBD. What should we do about it?

@Tony-MK Tony-MK requested a review from ArekChr October 26, 2023 13:15
@ArekChr
Copy link
Contributor

ArekChr commented Oct 27, 2023

Should I make it consistent with distance requests made offline?

I think we should stick to one topic in this PR and talk about other adjustments in a different issue to keep things clear and organized.

@ArekChr
Copy link
Contributor

ArekChr commented Oct 27, 2023

I believe there is a bug with the ReportPreview component. When a user changes the waypoints offline, two or more map images will be displayed. One will show the pending map due to the changes we have made, and the rest will show the original map or another map. It seems to have two or more transactions when the waypoints change for a singular distance request. This bug currently occurs in staging and production. I can't seem to figure out which appropriate logic to use so that the ReportPreview component shows TBD and the correct number of maps when every request in the report is a distance request and all are TBD. What should we do about it?

I think this also seems a separate issue.

src/CONST.ts Outdated Show resolved Hide resolved
@ArekChr
Copy link
Contributor

ArekChr commented Oct 27, 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: mWeb Chrome
    • iOS: Native
    • iOS: mWeb 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

Android: Native
android.mov
Android: mWeb Chrome
mweb.chrome.mov
iOS: Native
ios.mov
iOS: mWeb Safari
mweb.safari.mov
MacOS: Chrome / Safari
web.mov
MacOS: Desktop
desktop.mov

@Tony-MK
Copy link
Contributor Author

Tony-MK commented Nov 1, 2023

@ArekChr, Can you check again if the regression is still occurring? It seems to have been fixed when I updated the branch with main.

@Tony-MK
Copy link
Contributor Author

Tony-MK commented Nov 2, 2023

Hey @ArekChr and @arosiclair, I have an important proposal to share with you about debugging the ReportPreview component. Accordin‌g to this comment I posted earlier, there are duplicate transactions, with the same transactionId, retrieved from the ReportUtils.getTransactionsWithReceipts function.

const transactionsWithReceipts = ReportUtils.getTransactionsWithReceipts(props.iouReportID);

When a request's waypoints gets updated, another transaction with the same transaction ID is stored in allTransactions. This is the main reason why you will notice one or more extra images maps appear in the ReportPreview. When the user goes back online, the older transaction(s) will get deleted and number of image maps will change and becomes the exact number of distance requests.

Therefore, I kindly ask if it is possible of me to solve this bug. It's also affecting the code's accuracy on determining whether to show 'TBD' in the ReportPreview component when the hasOnlyDistanceRequests variable is true and all of the distance requests are waiting for their waypoints to be updated. Hence, my solution is after calling ReportUtils.getTransactionsWithReceipts function, we filter the latest transactions for every transaction ID and store the transactions in transactionsWithReceipts.

I believe this is an appropriate method of insuring the we display the exact number of maps and TBD appropriately. In turn, improving the offline user experience. I would greatly appreciate your thoughts on my proposal. Thank you 😄

@arosiclair
Copy link
Contributor

When a request's waypoints gets updated, another transaction with the same transaction ID is stored in allTransactions.

Can you find out why that's happening? This does not sound like correct behavior and it sounds like if we fix this, then your TBD problem should also be fixed.

@Tony-MK
Copy link
Contributor Author

Tony-MK commented Nov 4, 2023

Hey @arosiclair and @ArekChr, I have been investigating the root cause of the second problem I mentioned in #30232 (comment) and elaborated in #30232 (comment).

When a distance request is edited, a backup copy of the original transaction. If the user doesn't save the changes to the transaction, the transaction data is restored from the backup copy. Read the code snippet below on the useEffect hook used in EditRequestDistancePage to further understand the significance of creating a backup copy of a transaction.

useEffect(() => {
// This effect runs when the component is mounted and unmounted. It's purpose is to be able to properly
// discard changes if the user cancels out of making any changes. This is accomplished by backing up the
// original transaction, letting the user modify the current transaction, and then if the user ever
// cancels out of the modal without saving changes, the original transaction is restored from the backup.
// On mount, create the backup transaction.
TransactionEdit.createBackupTransaction(transaction);
return () => {
// If the user cancels out of the modal without without saving changes, then the original transaction
// needs to be restored from the backup so that all changes are removed.
if (transactionWasSaved.current) {
return;
}
TransactionEdit.restoreOriginalTransactionFromBackup(transaction.transactionID);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

The moment the server responds successfully, the backup transaction is deleted and is handled in the code snippet below.

App/src/libs/actions/IOU.js

Lines 785 to 792 in 7bd51eb

if (_.has(transactionChanges, 'waypoints')) {
// Delete the backup transaction when editing waypoints when the server responds successfully and there are no errors
successData.push({
onyxMethod: Onyx.METHOD.SET,
key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}-backup`,
value: null,
});
}

Therefore, the root cause of the problem is that the ReportUtils.getTransactionsWithReceipts function, which is used for fetching transactions to display in the ReportPreview component, does not filter out the backup copies of the original transactions fetched from the TransactionUtils.getAllReportTransactions function. The functions return both the edited transaction and, if present, the backup of the original transaction.

App/src/libs/ReportUtils.js

Lines 1710 to 1713 in 7bd51eb

function getTransactionsWithReceipts(iouReportID) {
const allTransactions = TransactionUtils.getAllReportTransactions(iouReportID);
return _.filter(allTransactions, (transaction) => TransactionUtils.hasReceipt(transaction));
}

function getAllReportTransactions(reportID?: string): Transaction[] {
// `reportID` from the `/CreateDistanceRequest` endpoint return's number instead of string for created `transaction`.
// For reference, https://github.com/Expensify/App/pull/26536#issuecomment-1703573277.
// We will update this in a follow-up Issue. According to this comment: https://github.com/Expensify/App/pull/26536#issuecomment-1703591019.
const transactions: Transaction[] = Object.values(allTransactions ?? {}).filter((transaction): transaction is Transaction => transaction !== null);
return transactions.filter((transaction) => `${transaction.reportID}` === `${reportID}`);
}

In conclusion, if we filter out the backup copies of the original transactions, it would solve the problem mentioned in the first paragraph.

@arosiclair
Copy link
Contributor

Very good breakdown @Tony-MK thanks!

In conclusion, if we filter out the backup copies of the original transactions, it would solve the problem mentioned in the first paragraph.

I agree with this. We can add an isBackup flag to the backup transaction when we create it and filter on that, though we would have to make sure we clear the flag before restoring the backup. What do you think?

I also do get the feeling that including the backup transaction in the normal transactions collection is probably going to cause more problems than it solves (like this one) so maybe we should consider moving backups to their own key. cc @tgolen since I think you designed this part

@tgolen
Copy link
Contributor

tgolen commented Nov 6, 2023

I really like the idea of moving it to a separate collection. I wish I would have thought of that in the first place. Can you make that change? It might be nice to create an onyx migration to clean out backup transactions from the main collection.

@Tony-MK
Copy link
Contributor Author

Tony-MK commented Nov 6, 2023

I also do get the feeling that including the backup transaction in the normal transactions collection is probably going to cause more problems than it solves (like this one) so maybe we should consider moving backups to their own key. cc @tgolen since I think you designed this part

Thank you, @arosiclair and @tgolen for your feedback. I believe we are moving forward with creating an onyx migration.

Can you make that change?

@tgolen, could you clarify to whom you were referring to make the change? Frankly, I wouldn't mind making the change.

@tgolen
Copy link
Contributor

tgolen commented Nov 6, 2023

Yeah, @Tony-MK I think you can go ahead and make that change. I actually took the lead with that on this PR I've been writing to refactor the request creation flow.

Can you make this same collection and use that for the backup transactions?

@Tony-MK
Copy link
Contributor Author

Tony-MK commented Nov 6, 2023

Can you make this same collection and use that for the backup transactions?

Sure, @tgolen, I can certainly do that.

But before we proceed, I have a final question. Since this PR was originally intended for a different purpose than our discussion, should I create a new PR to ensure everything remains organized?

@tgolen
Copy link
Contributor

tgolen commented Nov 7, 2023

I'd be fine with doing that in a different PR, sure.

@ArekChr
Copy link
Contributor

ArekChr commented Nov 7, 2023

@Tony-MK Please update PR with latest main

@ArekChr
Copy link
Contributor

ArekChr commented Nov 7, 2023

Should we display "TBD" in online mode optimistically, or is it better to keep it as is and update the amount only after the API returns successful data? @tgolen @arosiclair thoughts?

Nagranie.z.ekranu.2023-11-7.o.13.51.43.mov

@Tony-MK
Copy link
Contributor Author

Tony-MK commented Nov 7, 2023

@Tony-MK Please update PR with latest main

Definitely and welcome back, @ArekChr

@arosiclair
Copy link
Contributor

Should we display "TBD" in online mode optimistically, or is it better to keep it as is and update the amount only after the API returns successful data? @tgolen @arosiclair thoughts?

Yeah I think this is correct since there are pending changes on the waypoints even while online. UpdateDistanceRequest is one of our slower endpoints because of the distance calculations so this will be more noticeable here than in most other flows.

@arosiclair arosiclair merged commit cbfd424 into Expensify:main Nov 7, 2023
15 checks passed
@OSBotify
Copy link
Contributor

OSBotify commented Nov 7, 2023

✋ 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

OSBotify commented Nov 8, 2023

🚀 Deployed to staging by https://github.com/arosiclair in version: 1.3.96-6 🚀

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

@OSBotify
Copy link
Contributor

OSBotify commented Nov 9, 2023

🚀 Deployed to production by https://github.com/puneetlath in version: 1.3.96-15 🚀

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

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/arosiclair in version: 1.3.98-0 🚀

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

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/roryabraham in version: 1.3.98-5 🚀

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

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.

5 participants