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

[$500] Distance - Duplicate waypoint error message is not dimissed after closing distance editor #34999

Closed
6 tasks done
lanitochka17 opened this issue Jan 23, 2024 · 38 comments
Closed
6 tasks done
Assignees
Labels
Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Reviewing Has a PR in review Weekly KSv2

Comments

@lanitochka17
Copy link

lanitochka17 commented Jan 23, 2024

If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!


Version Number: 1.4.30-0
Reproducible in staging?: Y
Reproducible in production?: Y
If this was caught during regression testing, add the test name, ID and link from TestRail:
Email or phone of affected tester (no customers):
Logs: https://stackoverflow.com/c/expensify/questions/4856
Expensify/Expensify Issue URL:
Issue reported by: Applause - Internal Team
Slack conversation:

Action Performed:

Precondition: App location access is disabled

  1. Go to workspace chat
  2. Create a distance request with A-B-A address
  3. Navigate to request details page
  4. Click Distance
  5. Drag the waypoint so that it becomes A-A-B
  6. Save the request
  7. Exit the distance editor
  8. Refresh the page
  9. Click Distance

Expected Result:

The duplicate waypoint error message is dismissed

Actual Result:

The duplicate waypoint error message is not dismissed

Workaround:

Unknown

Platforms:

Which of our officially supported platforms is this issue occurring on?

  • Android: Native
  • Android: mWeb Chrome
  • iOS: Native
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Add any screenshot/video evidence

Bug6352460_1706039016934.20240123_235006.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~018929236a56deb238
  • Upwork Job ID: 1749887372530053120
  • Last Price Increase: 2024-01-30
  • Automatic offers:
    • alitoshmatov | Reviewer | 28142961
    • tienifr | Contributor | 28142962
Issue OwnerCurrent Issue Owner: @JmillsExpensify
@lanitochka17 lanitochka17 added External Added to denote the issue can be worked on by a contributor Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Jan 23, 2024
@melvin-bot melvin-bot bot changed the title Distance - Duplicate waypoint error message is not dimissed after closing distance editor [$500] Distance - Duplicate waypoint error message is not dimissed after closing distance editor Jan 23, 2024
Copy link

melvin-bot bot commented Jan 23, 2024

Job added to Upwork: https://www.upwork.com/jobs/~018929236a56deb238

Copy link

melvin-bot bot commented Jan 23, 2024

Triggered auto assignment to @JmillsExpensify (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Jan 23, 2024
Copy link

melvin-bot bot commented Jan 23, 2024

Triggered auto assignment to Contributor-plus team member for initial proposal review - @alitoshmatov (External)

@lanitochka17
Copy link
Author

We think that this bug might be related to #wave6.
CC @greg-schroeder

@paultsimura
Copy link
Contributor

Proposal

Please re-state the problem that we are trying to solve in this issue.

The "Duplicate waypoint" error remains between the "edit distance" page refreshes.

What is the root cause of that problem?

For the distance request, we use a hook that restores the transaction to the original one if it was not saved:

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
}, []);

However, in this issue's scenario, we save the transaction (transactionWasSaved.current becomes true), but the changes are not persisted due to the route error. However, we still return early because the condition of transactionWasSaved.current is met, and therefore do not fully restore the transaction to its original state.

What changes do you think we should make in order to solve the problem?

We should add an extra check – early return only if the transaction was saved without a route error:

        return () => {
            // If the user cancels out of the modal without saving changes, then the original transaction
            // needs to be restored from the backup so that all changes are removed.
            if (transactionWasSaved.current && !hasRouteError) {
                return;
            }
            TransactionEdit.restoreOriginalTransactionFromBackup(transaction.transactionID);
        };

What alternative solutions did you explore? (Optional)

@JordanLevy19
Copy link

Proposal

Please re-state the problem that we are trying to solve in this issue.
The error message regarding non-unique waypoints in a distance request feature persists even after a user refreshes the page. This indicates that the error state is not being reset as expected during a page reload.

What is the root cause of that problem?
The root cause of the error message persisting after a page refresh is perhaps due to the hasError state in the DistanceRequest component not being reset correctly. The state is initially set to false, but the code only explicitly resets it in a specific useEffect cleanup function tied to the transaction and transactionID dependencies. If this cleanup function doesn't trigger correctly on a page refresh - either because the component isn't unmounting/remounting properly, or the dependencies don't change as expected - then the hasError state remains true, causing the error message to persist. Additionally, the submitWaypoints function sets this error state under certain conditions, but without a corresponding reset mechanism that activates on page refresh, the error state is not cleared.

What changes do you think we should make in order to solve the problem?

Ensure hasError Resets on Page Refresh:
Modify the useEffect for transaction and transactionID to explicitly reset hasError not only when the component unmounts but also when it remounts, which typically happens on a page refresh. This can involve adding a condition to check if waypoints or relevant conditions have been reinitialized and reset hasError accordingly.

Review and Update submitWaypoints Logic:
Implement a mechanism in submitWaypoints to reset hasError when the conditions that initially set it to true no longer apply. This could involve adding a state update at the start of this function to reset the error state, or incorporating additional checks to ensure the state aligns with the current conditions.

Improve Waypoints Update Logic:
In updateWaypoints, add logic to reassess the error state whenever waypoints are successfully updated. This ensures that if the error condition related to waypoints is resolved, hasError is reset to false.

What alternative solutions did you explore? (Optional)

@samilabud
Copy link
Contributor

Proposal

Please re-state the problem that we are trying to solve in this issue.

Distance - waypoint error message is not dimissed after closing distance editor

What is the root cause of that problem?

We are using Onyx to store and persist errors inside the transaction object:

errorFields?: OnyxCommon.ErrorFields<'route'>;

Because of this when we got an error we going to keep it at least we save the waypoints again.

What changes do you think we should make in order to solve the problem?

We should clean the transaction errors when unmount the Distance request component inside the next line:

The code result should be:

.
.
.
  return () => {
            // If there are error cached in onyx
            if (hasRouteError) {
                TransactionEdit.cleanTransactionErrors(transaction);
            }
.
.
.

And the cleanTransactionErrors could be (inside of https://github.com/Expensify/App/blob/main/src/libs/actions/TransactionEdit.ts):

function cleanTransactionErrors(transaction: OnyxEntry<Transaction>) {
    if (!transaction) {
        return;
    }
    const newTransaction = {
        ...transaction,
        errorFields: {
            route: {},
        },
    };
    Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transaction.transactionID}`, newTransaction);
}

Result:

Distance.request.error.test.mp4

@Krishna2323
Copy link
Contributor

Krishna2323 commented Jan 24, 2024

Proposal

Please re-state the problem that we are trying to solve in this issue.

Distance - Duplicate waypoint error message is not dimissed after closing distance editor

What is the root cause of that problem?

We save the waypoints even if we have duplicates & thats why its been stored in ONYX and it persists after refresh.

What changes do you think we should make in order to solve the problem?

We should not save the waypoint if we have duplicates. We need to return from here:

if (_.size(validatedWaypoints) < 2 || hasRouteError || isLoadingRoute || (isLoading && !isOffline)) {

To validate we can add an extra check like, (_.keys(waypoints).length > 2 && _.size(validatedWaypoints) !== _.keys(waypoints).length) to check if the all waypoints are valid.

We already have done it inside IOURequestStepDistance:

if (_.size(validatedWaypoints) < 2 || (_.keys(waypoints).length > 2 && _.size(validatedWaypoints) !== _.keys(waypoints).length) || hasRouteError || isLoadingRoute || isLoading) {
setHasError(true);
return;

Result

@Krishna2323
Copy link
Contributor

Proposal Updated

Added permalink for reference.

@tienifr
Copy link
Contributor

tienifr commented Jan 24, 2024

Proposal

Please re-state the problem that we are trying to solve in this issue.

The duplicate waypoint error message is not dismissed

What is the root cause of that problem?

We're not validating duplicate waypoints when editing waypoints, so when we call the API to save it, it will return a back-end error which will not be cleared when we reload the page.

What changes do you think we should make in order to solve the problem?

Make sure to validate duplicate waypoints and show the duplicate waypoints error properly when editing waypoints

  1. Below here, add a condition to return an error if there's duplicate waypoints, we can check that the size of the validatedWaypoints is smaller than the size of waypoints because if there's duplicate waypoints, it will be removed in validatedWaypoints
if (_.size(validatedWaypoints) < _.keys(waypoints).length) {
    return {0: translate('iou.error.duplicateWaypointsErrorMessage')};
}
  1. In here, update so that it will show the DotIndicatorMessage (aka the error message UI) if there's error in getError()
{((hasError && !_.isEmpty(getError())) || hasRouteError) && (
  1. In here, update so that it will set hasError to true if there's an error when getError, the rest remains as currently logic
if (!_.isEmpty(getError()) || isLoadingRoute || (isLoading && !isOffline)) {

We can consider making the error returned from getError() a variable, using useMemo, it will look cleaner and can minimize rerendering. We can do the same inside IOURequestStepDistance as well.

What alternative solutions did you explore? (Optional)

NA

@melvin-bot melvin-bot bot added the Overdue label Jan 29, 2024
Copy link

melvin-bot bot commented Jan 29, 2024

@JmillsExpensify, @alitoshmatov Eep! 4 days overdue now. Issues have feelings too...

@alitoshmatov
Copy link
Contributor

Missed this one, reviewing today

@melvin-bot melvin-bot bot removed the Overdue label Jan 30, 2024
Copy link

melvin-bot bot commented Jan 30, 2024

📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸

@alitoshmatov
Copy link
Contributor

@paultsimura Thank you for your proposal. Even if transaction is restored when closing the page, error is still persisting.

@alitoshmatov
Copy link
Contributor

alitoshmatov commented Jan 30, 2024

@JordanLevy19 Don't get me wrong but your proposal looks like written by a chatbot, it is very vague and has no context awareness

@JordanLevy19
Copy link

Hey @alitoshmatov - not wrong at all - this was actually my first go at one of these bugs, and I have definitely learned to be more specific about the issues and to and identify as much as possible where the actual bugs reside in the code files and components!

Thank you for the feedback!

@alitoshmatov
Copy link
Contributor

@Krishna2323 Thank you for your proposal, you are suggesting how to prevent duplicate waypoints from being submitted. I think your solution is not complete because there is no error handling there. You are just preventing user from submitting duplicate waypoints

@alitoshmatov
Copy link
Contributor

@samilabud Thank you for your proposal. Your RCA is correct and your solution does solve this issue. But I am not sure if it is expected behavior to clean all transaction errors when distance page is closed

@alitoshmatov
Copy link
Contributor

@tienifr Thank you for your proposal. Your RCA is correct. I do agree we should validate waypoints and show duplicate error before user submits the edit just like creating distance request.

@tienifr
Copy link
Contributor

tienifr commented Feb 1, 2024

@tienifr Thank you for your proposal. Your RCA is correct. I do agree we should validate waypoints and show duplicate error before user submits the edit just like creating distance request.

@alitoshmatov Thanks! Do you think we can move forward with my proposal?

@kmbcook
Copy link
Contributor

kmbcook commented Feb 1, 2024

In #34441 we have proposed to use a draft transaction for editing waypoints, which would solve this issue.

@melvin-bot melvin-bot bot added the Overdue label Feb 2, 2024
@alitoshmatov
Copy link
Contributor

@kmbcook Can you elaborate how that issue will solve ours?

@melvin-bot melvin-bot bot removed the Overdue label Feb 2, 2024
@kmbcook
Copy link
Contributor

kmbcook commented Feb 2, 2024

@alitoshmatov sorry, I was wrong.

@melvin-bot melvin-bot bot added the Overdue label Feb 5, 2024
@alitoshmatov
Copy link
Contributor

We can go with @tienifr 's proposal

C+ reviewed 🎀 👀 🎀

@melvin-bot melvin-bot bot removed the Overdue label Feb 5, 2024
Copy link

melvin-bot bot commented Feb 5, 2024

Triggered auto assignment to @tgolen, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

@tgolen
Copy link
Contributor

tgolen commented Feb 5, 2024

LGTM 👍

@melvin-bot melvin-bot bot removed the Help Wanted Apply this label when an issue is open to proposals by contributors label Feb 5, 2024
Copy link

melvin-bot bot commented Feb 5, 2024

📣 @alitoshmatov 🎉 An offer has been automatically sent to your Upwork account for the Reviewer role 🎉 Thanks for contributing to the Expensify app!

Offer link
Upwork job

Copy link

melvin-bot bot commented Feb 5, 2024

📣 @tienifr 🎉 An offer has been automatically sent to your Upwork account for the Contributor role 🎉 Thanks for contributing to the Expensify app!

Offer link
Upwork job
Please accept the offer and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review 🧑‍💻
Keep in mind: Code of Conduct | Contributing 📖

Copy link

melvin-bot bot commented Feb 6, 2024

@JmillsExpensify @tgolen @alitoshmatov @tienifr this issue was created 2 weeks ago. Are we close to approving a proposal? If not, what's blocking us from getting this issue assigned? Don't hesitate to create a thread in #expensify-open-source to align faster in real time. Thanks!

@tienifr
Copy link
Contributor

tienifr commented Mar 1, 2024

@JmillsExpensify PR hit production. Melvin is malfunctioning. Please add HOLD for payment label.

@tienifr
Copy link
Contributor

tienifr commented Mar 18, 2024

@JmillsExpensify PR hit production. Melvin is malfunctioning. Please add HOLD for payment label.

@JmillsExpensify Would you mind helping with payment here? Thanks

@alitoshmatov
Copy link
Contributor

@JmillsExpensify Bump

@JmillsExpensify
Copy link

If you need something urgent please please reach out to me in Slack in our open source community or directly 1:1. Sorry for the delay!

@JmillsExpensify
Copy link

Payment summary:

Also @alitoshmatov I don't believe I've seen a BZ checklist. Can you please complete one? Thank you.

@JmillsExpensify
Copy link

All contributors have been paid out though please @alitoshmatov help with the BZ checklist before we can close this on out!

@JmillsExpensify
Copy link

@alitoshmatov bump on the BZ checklist.

@alitoshmatov
Copy link
Contributor

  • The PR that introduced the bug has been identified. Link to the PR: feat: enable next button #29125
  • The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake. Link to comment: https://github.com/Expensify/App/pull/29125/files#r1546740052
  • A discussion in #expensify-bugs has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner. Link to discussion: No need
  • Determine if we should create a regression test for this bug. No need

cc: @JmillsExpensify

@JmillsExpensify
Copy link

Great thanks so much! Given no regression test is required, I'll close the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Reviewing Has a PR in review Weekly KSv2
Projects
None yet
Development

No branches or pull requests

10 participants