Skip to content

[Due for payment 2025-02-18] [$250] Search - Different behavior when using app and device back button in selection mode #45896

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

Closed
2 of 6 tasks
lanitochka17 opened this issue Jul 22, 2024 · 40 comments
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production 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 Jul 22, 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: 9.0.10-2
Reproducible in staging?: Y
Reproducible in production?: Y
If this was caught during regression testing, add the test name, ID and link from TestRail: N/A
Issue reported by: Applause - Internal Team

Action Performed:

  1. Launch New Expensify app
  2. Submit an expense to any user
  3. Go to Search
  4. Long press on the expense
  5. Tap Select
  6. Tap Back button on the top left
  7. Note that only the selection mode is dismissed and app remains on the same page
  8. Tap Select
  9. Go back using device navigation

Expected Result:

App will dimiss the selection mode and remains on the same page

Actual Result:

App returns to the previous page

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

Bug6549153_1721637282851.Screen_Recording_20240722_161640_New_Expensify.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~0189e7d6f2ae38bc4a
  • Upwork Job ID: 1818838854171056546
  • Last Price Increase: 2024-08-01
  • Automatic offers:
    • nkdengineer | Contributor | 103414449
Issue OwnerCurrent Issue Owner: @trjExpensify
@lanitochka17 lanitochka17 added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Jul 22, 2024
Copy link

melvin-bot bot commented Jul 22, 2024

Triggered auto assignment to @adelekennedy (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

@lanitochka17
Copy link
Author

We think that this bug might be related to #wave-collect - Release 1

@Krishna2323
Copy link
Contributor

Proposal

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

Search - Different behavior when using app and device back button in selection mode

What is the root cause of that problem?

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

We should use BackHandler.addEventListener('hardwareBackPress' to handle device back button and stop the navigation if isMobileSelectionModeActive is true.

    useEffect(() => {
        const backAction = () => {
            if (isMobileSelectionModeActive) {
                setIsMobileSelectionModeActive(false);
                return true;
            }
            return false;
        };
        BackHandler.addEventListener('hardwareBackPress', backAction);
        return () => {
            BackHandler.removeEventListener('hardwareBackPress', backAction);
        };
    }, [isMobileSelectionModeActive]);

What alternative solutions did you explore? (Optional)

@melvin-bot melvin-bot bot added the Overdue label Jul 24, 2024
Copy link

melvin-bot bot commented Jul 25, 2024

@adelekennedy Whoops! This issue is 2 days overdue. Let's get this updated quick!

Copy link

melvin-bot bot commented Jul 29, 2024

@adelekennedy 6 days overdue. This is scarier than being forced to listen to Vogon poetry!

Copy link

melvin-bot bot commented Jul 31, 2024

@adelekennedy 8 days overdue is a lot. Should this be a Weekly issue? If so, feel free to change it!

@adelekennedy
Copy link

added to a project

@melvin-bot melvin-bot bot removed the Overdue label Aug 1, 2024
@adelekennedy adelekennedy added External Added to denote the issue can be worked on by a contributor Overdue labels Aug 1, 2024
@melvin-bot melvin-bot bot changed the title Search - Different behavior when using app and device back button in selection mode [$250] Search - Different behavior when using app and device back button in selection mode Aug 1, 2024
Copy link

melvin-bot bot commented Aug 1, 2024

Job added to Upwork: https://www.upwork.com/jobs/~0189e7d6f2ae38bc4a

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

melvin-bot bot commented Aug 1, 2024

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

@melvin-bot melvin-bot bot removed the Overdue label Aug 1, 2024
@nkdengineer
Copy link
Contributor

Proposal

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

App returns to the previous page

What is the root cause of that problem?

We already have a custom back handler for Android here but it doesn't cover the case when the selectionMode is enabled.

if (bottomTabRoutes[bottomTabRoutes.length - 1].name === SCREENS.SEARCH.BOTTOM_TAB && focusedRoute?.name === SCREENS.SEARCH.CENTRAL_PANE) {

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

We should handle the back button for the selection mode case in SearchPageBottomTab.

onBackButtonPress={() => {
clearSelectedTransactions();
turnOffMobileSelectionMode();

While testing I found a problem that is if we add a hardwareBackPress listener and call the function as we do for the back button in the header here, this doesn't work. The problem is the selectedTransactions is not cleared before the selection mode is turned off and then this useEffect is triggered to turn on the selection mode again. It may be related to the state and lifeCycle of React here.

if (selectedKeys.length > 0 && !selectionMode?.isEnabled) {
turnOnMobileSelectionMode();
}

The solution here is we should only turn off the selection mode after the selectedTransactions is cleared. The details step here:

  1. Add an extra field in SearchContext data like shouldTurnOffSelectionMode with the default value is false to detect whether we should turn off the selection mode if the selectedTransactions is empty.

const Context = React.createContext<SearchContext>(defaultSearchContext);

  1. Accept an extra param in clearSelectedTransactions that will update shouldTurnOffSelectionMode
const clearSelectedTransactions = useCallback(
    (searchHash?: number, shouldTurnOffSelectionMode = false) => {
        if (searchHash === searchContextData.currentSearchHash) {
            return;
        }
        setSearchContextData((prevState) => ({
            ...prevState,
            shouldTurnOffSelectionMode,
            selectedTransactions: {},
        }));
    },
    [searchContextData.currentSearchHash],
);

const clearSelectedTransactions = useCallback(

and update shouldTurnOffSelectionMode to false when we set the selected transaction here to avoid the selection mode being turned off when we deselect the last selected option.

const setSelectedTransactions = useCallback((selectedTransactions: SelectedTransactions) => {
    setSearchContextData((prevState) => ({
        ...prevState,
        selectedTransactions,
        shouldTurnOffSelectionMode: false,
    }));
}, []);

const setSelectedTransactions = useCallback((selectedTransactions: SelectedTransactions) => {

  1. Create a useEffect in here to turn off the selection mode if the seleactedTransactions is empty and shouldTurnOffSelectionMode is true
useEffect(() => {
    const selectedKeys = Object.keys(selectedTransactions).filter((key) => selectedTransactions[key]);
    if (selectedKeys.length === 0 && selectionMode?.isEnabled && shouldTurnOffSelectionMode) {
        turnOffMobileSelectionMode();
    }
}, [selectedTransactions, selectionMode?.isEnabled, shouldTurnOffSelectionMode]);

function Search({queryJSON, policyIDs, isCustomQuery}: SearchProps) {

OPTIONAL: We can also create a function in SearchContext to reset the shouldTurnOffSelectionMode and use this in the useEffect above after we turn off the selection mode

  1. In SearchPageBottomTab, add an event listener for the back button of device and we will call clearSelectedTransactions with shouldTurnOffSelectionMode as true
const handleBackButtonPress = useCallback(() => {
    if (!selectionMode?.isEnabled) {
        return false;
    }
    if (selectionMode?.isEnabled) {
        clearSelectedTransactions(undefined, true);
        return true;
    }
}, [selectionMode, clearSelectedTransactions]);

useEffect(() => {
    const backHandler = BackHandler.addEventListener('hardwareBackPress', handleBackButtonPress);

    return () => backHandler.remove();
}, [handleBackButtonPress]);

We can also call clearSelectedTransactions(undefined, true) here

onBackButtonPress={() => { 
     clearSelectedTransactions(undefined, true);
}

onBackButtonPress={() => {
clearSelectedTransactions();
turnOffMobileSelectionMode();

The test branch here for more details: https://github.com/nkdengineer/App/tree/fix/45896

What alternative solutions did you explore? (Optional)

Result

Screen.Recording.2024-08-01.at.12.57.08.mov

Copy link

melvin-bot bot commented Aug 5, 2024

@eVoloshchak @adelekennedy 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!

@melvin-bot melvin-bot bot added the Overdue label Aug 5, 2024
@eVoloshchak
Copy link
Contributor

I think we should proceed with @nkdengineer's proposal

🎀👀🎀 C+ reviewed!

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

melvin-bot bot commented Aug 5, 2024

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

@melvin-bot melvin-bot bot removed the Help Wanted Apply this label when an issue is open to proposals by contributors label Aug 6, 2024
@melvin-bot melvin-bot bot changed the title [$250] Search - Different behavior when using app and device back button in selection mode [Due for payment 2025-02-18] [$250] Search - Different behavior when using app and device back button in selection mode Feb 11, 2025
@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Feb 11, 2025
Copy link

melvin-bot bot commented Feb 11, 2025

Reviewing label has been removed, please complete the "BugZero Checklist".

Copy link

melvin-bot bot commented Feb 11, 2025

The solution for this issue has been 🚀 deployed to production 🚀 in version 9.0.95-6 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

If no regressions arise, payment will be issued on 2025-02-18. 🎊

For reference, here are some details about the assignees on this issue:

Copy link

melvin-bot bot commented Feb 11, 2025

@eVoloshchak @adelekennedy @eVoloshchak The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the BugZero Checklist from here into a new comment on this GH and complete it. If you have the K2 extension, you can simply click: [this button]

@adelekennedy adelekennedy removed the Bug Something is broken. Auto assigns a BugZero manager. label Feb 14, 2025
@adelekennedy adelekennedy removed their assignment Feb 14, 2025
@adelekennedy adelekennedy added the Bug Something is broken. Auto assigns a BugZero manager. label Feb 14, 2025
Copy link

melvin-bot bot commented Feb 14, 2025

Triggered auto assignment to @trjExpensify (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

@melvin-bot melvin-bot bot added Daily KSv2 and removed Weekly KSv2 labels Feb 14, 2025
@adelekennedy
Copy link

@trjExpensify I will be ooo for payment on the 18th - adding you here!

@adelekennedy adelekennedy self-assigned this Feb 14, 2025
@melvin-bot melvin-bot bot added Daily KSv2 Overdue and removed Daily KSv2 labels Feb 17, 2025
@trjExpensify
Copy link
Contributor

Sure thing! Let's get the checklist here, @eVoloshchak.

@melvin-bot melvin-bot bot removed the Overdue label Feb 17, 2025
@trjExpensify
Copy link
Contributor

Bump on the checklist @eVoloshchak to pay this out.

@eVoloshchak
Copy link
Contributor

  • The PR that introduced the bug has been identified. Link to the PR: there isn't a PR that has introduced this, this is a default behavior we're changing to make it consistent across platforms (at least the ones we can)
  • 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: N/A
  • 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: this is a simple bug, I don't think an additional discussion is needed

Regression Test Proposal

iOS/Android native only

  1. Submit an expense to any user
  2. Go to Search
  3. Long press on the expense
  4. Tap Select
  5. Tap Back button on the top left
  6. Note that only the selection mode is dismissed and the app remains on the same page
  7. Tap Select
  8. Go back using device navigation
  9. Verify that the App will dismiss the selection mode and remain on the same page

Do we agree 👍 or 👎

@Julesssss
Copy link
Contributor

The test is valid, but I don't think we need a unique test for this case.

@trjExpensify
Copy link
Contributor

Fair enough. Payment summary as follows:

Closing, thanks!

@JmillsExpensify
Copy link

$250 approved for @eVoloshchak

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Payment Auto-added when associated PR is deployed to production 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
No open projects
Status: Polish
Development

No branches or pull requests

10 participants