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: unify TBD-related logic for Distance requests #34135

Merged
merged 41 commits into from
Feb 7, 2024

Conversation

paultsimura
Copy link
Contributor

@paultsimura paultsimura commented Jan 9, 2024

Details

  • Change places where "TBD" was used to use "Route pending..." instead;
  • Unify some pending-route-related logic to minimize potential discrepancies among different screens of the same transaction.
  • Update the Merchant to "Route pending..." when editing waypoints

Fixed Issues

$ #33362
PROPOSAL: #33362 (comment)

Large Slack discussion: https://expensify.slack.com/archives/C01GTK53T8Q/p1705425683928599

Tests

Same as QA

Offline tests

Same as QA

QA Steps

  1. Go offline
  2. Click FAB -> Distance
  3. Proceed to the confirmation page
  • Verify the amount is blank
  • Verify the distance shows "Route pending..."
  1. Complete the distance request
  2. Navigate (if not already) to the chat that contains the recently created Distance request
  • Verify that the amount is displayed as Route pending...
  • Verify that in the LHN, the preview shows Route pending...
  • Verify the total Expense shows $0
  1. Go Online (and wait a little)
  • Verify that the amount and distance are updated with the data from the BE
  1. Navigate to this Distance request
  2. Go offline again
  3. Click "Distance"
  4. Add a waypoint and click "Save"
  • Verify that the amount is blank
  • Verify that the distance field says Route pending
  • Verify the report title says Route pending
  1. Click on the receipt thumbnail
  • Verify that the distance on the e-Receipt shows Route pending and the amount is not shown
  1. Without going back online, modify the amount manually (available only if you're the admin or manager of the workspace)
  • Verify the amount field shows the manual amount
  • Verify the distance still shows "Route pending..."
  1. Go to the parent Expense report
  • Verify the money request preview shows the manual amount and "Route pending..." in the subtitle
  • Verify in LHN, the report preview shows the manually requested amount.

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
    • 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-compressed.mp4
Android: mWeb Chrome
chrome-compressed.mp4
iOS: Native
Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-01-09.at.15.02.49-compressed.mp4
iOS: mWeb Safari
Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-01-09.at.14.54.34-compressed.mp4
MacOS: Chrome / Safari
Screen.Recording.2024-01-20.at.20.28.56-compressed.mp4
MacOS: Desktop
Screen.Recording.2024-01-09.at.15.05.45-compressed.mp4

@paultsimura paultsimura changed the title Fix/33362 is loading tbd fix: unify TBD-related logic for Distance requests Jan 9, 2024
@paultsimura paultsimura marked this pull request as ready for review January 9, 2024 14:17
@paultsimura paultsimura requested a review from a team as a code owner January 9, 2024 14:17
@melvin-bot melvin-bot bot requested review from parasharrajat and removed request for a team January 9, 2024 14:17
Copy link

melvin-bot bot commented Jan 9, 2024

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

# Conflicts:
#	src/components/ReportActionItem/MoneyRequestPreview.js
src/libs/ReportUtils.ts Outdated Show resolved Hide resolved
src/libs/TransactionUtils.ts Outdated Show resolved Hide resolved
src/components/ReportActionItem/ReportPreview.js Outdated Show resolved Hide resolved
src/libs/TransactionUtils.ts Outdated Show resolved Hide resolved
src/libs/TransactionUtils.ts Outdated Show resolved Hide resolved
@neil-marcellini neil-marcellini self-requested a review January 16, 2024 19:46
@neil-marcellini
Copy link
Contributor

@paultsimura I'm going to convert this to a draft so we can tell when it's ready.

@neil-marcellini neil-marcellini marked this pull request as draft January 19, 2024 18:14
@paultsimura paultsimura marked this pull request as ready for review January 20, 2024 20:12
@@ -266,8 +266,8 @@ function getDescription(transaction: OnyxEntry<Transaction>): string {
/**
* Return the amount field from the transaction, return the modifiedAmount if present.
*/
function getAmount(transaction: OnyxEntry<Transaction>, isFromExpenseReport: boolean): number {
// IOU requests cannot have negative values but they can be stored as negative values, let's return absolute value
function getAmount(transaction: OnyxEntry<Transaction>, isFromExpenseReport = false): number {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are a bunch of places where this second parameter is not provided. So I've set it to default false to avoid "Wrong params count" errors.

@amyevans
Copy link
Contributor

amyevans commented Feb 6, 2024

@paultsimura In case you didn't see, there's more conflicts 🥲

# Conflicts:
#	src/libs/ReportUtils.ts
#	src/libs/actions/IOU.ts
@paultsimura
Copy link
Contributor Author

There's more conflicts 🥲

Thank you for the ping, resolved again ✔️

amyevans
amyevans previously approved these changes Feb 6, 2024
src/components/ReportActionItem/ReportPreview.tsx Outdated Show resolved Hide resolved
src/components/ReportActionItem/MoneyRequestPreview.tsx Outdated Show resolved Hide resolved
const isDistanceRequestWithoutRoute = isDistanceRequest && !hasRoute;
const formattedAmount = isDistanceRequestWithoutRoute
? translate('common.tbd')
const isDistanceRequestWithPendingRoute = isDistanceRequest && (!hasRoute || !rate);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why isn't this using isFetchingWaypointsFromServer()?

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 isFetchingWaypointsFromServer depends on this variable, not vice versa:

if (isDistanceRequestWithPendingRoute) {
IOU.setMoneyRequestPendingFields(transaction.transactionID, {waypoints: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD});
}

Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like that's kind of an anti pattern. I think we should only call actions based directly on user action, not based on data changing. Do you agree Tim?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But we already do call these actions in multiple places when landing on different steps of the IOU creation. Since in all these places we update the draft transaction, it looks more like a way to transfer the state between the IOU creation steps, and not an actual data modification.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I think you're both right. @paultsimura you're correct that this is more akin to storing the form state between steps. @neil-marcellini I think you might be onto something about this looking like an anti-pattern.

What do you think about this?

  • Instead of calling IOU.setMoneyRequestPendingFields(transaction.transactionID, {waypoints: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD}); on this page, set that data on the previous page when the user submits the form. I think it could be part of the data that gets set here:
    Transaction.updateWaypoints(transactionID, newWaypoints, true).then(() => {

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 issue here is the following scenario:

The user completes the first steps up until the confirmation step while being offline. Then, on the confirmation step, they come back online. Here, the map should get fetched, and we no longer should have the waypoints pending (even though when we landed on this page, the map was still pending).

Copy link
Contributor

@tgolen tgolen Feb 6, 2024

Choose a reason for hiding this comment

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

Oh, that darn offline flow gets confusing! Thanks for pointing that out. It's probably OK then, but I would ask that you also put that context into a code comment where it happens.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got you, thanks for taking your time on this. Updated ✔️

Copy link
Contributor

Choose a reason for hiding this comment

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

Then, on the confirmation step, they come back online. Here, the map should get fetched, and we no longer should have the waypoints pending

Thank you for explaining. I think that flow makes sense, but how does that relate to this condition? If we are offline and set the waypoints pending when they are updated (as Tim suggested), then when the user is navigated to this page the pending fields will show correctly. Once they go back online I would think that the GetRoute response should clear the pending fields for the waypoints (and or the route), and then all data on the confirmation page would no longer show as pending. Does that make sense?

I'm going to leave this as a NAB. We could fix it in a follow up if needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably yes, but I'm not sure where to attach the workspace rate being still loaded in this case. That being said, I would really appreciate it if we could merge this PR as-is if it's an NAB. It's my longest one so far 🙂

src/components/DistanceEReceipt.js Outdated Show resolved Hide resolved
Copy link
Contributor

@neil-marcellini neil-marcellini left a comment

Choose a reason for hiding this comment

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

I think it's pretty much good to go, but Tim did point out something a bit weird so I'll wait to approve until we get that settled.

const isDistanceRequestWithoutRoute = isDistanceRequest && !hasRoute;
const formattedAmount = isDistanceRequestWithoutRoute
? translate('common.tbd')
const isDistanceRequestWithPendingRoute = isDistanceRequest && (!hasRoute || !rate);
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like that's kind of an anti pattern. I think we should only call actions based directly on user action, not based on data changing. Do you agree Tim?

@paultsimura
Copy link
Contributor Author

@tgolen @neil-marcellini please re-review before we have new conflicts 🙂 🙏

@amyevans
Copy link
Contributor

amyevans commented Feb 7, 2024

Can you merge main to clear up the failing reassure performance tests?

@paultsimura
Copy link
Contributor Author

@amyevans done ✔️

@neil-marcellini neil-marcellini merged commit 60c7d92 into Expensify:main Feb 7, 2024
19 checks passed
@OSBotify
Copy link
Contributor

OSBotify commented Feb 7, 2024

✋ 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 Feb 8, 2024

🚀 Deployed to staging by https://github.com/neil-marcellini in version: 1.4.39-0 🚀

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

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/Beamanator in version: 1.4.39-8 🚀

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

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