Skip to content

[HOLD for payment 2024-03-25] [$500] Message action menu - Last option is not selected when pressing up key #36245

Closed

Description

@kbecciv

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: v1.4.39-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: https://expensify.testrail.io/index.php?/tests/view/4294106
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:

  1. Right click on owned message
  2. Press on up key till you rich the 'reply in thread' option
  3. Press up key once more

Expected Result:

Focus should be applied on 'Delete comment' option

Actual Result:

Focus is not applied on 'Delete comment' option

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

Bug6373696_1707490365897.Screen_Recording_2024-02-09_at_2.50.43_at_night.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~017003c89d832c6ad8
  • Upwork Job ID: 1755970808587268096
  • Last Price Increase: 2024-02-23
  • Automatic offers:
    • Ollyws | Reviewer | 0
    • FitseTLT | Contributor | 0

Activity

  1. added
    ExternalAdded to denote the issue can be worked on by a contributor
    BugSomething is broken. Auto assigns a BugZero manager.
    on Feb 9, 2024
  2. changed the title [-]Message action menu - Last option is not selected when pressing up key[/-] [+][$500] Message action menu - Last option is not selected when pressing up key[/+] on Feb 9, 2024
  3. melvin-bot commented on Feb 9, 2024

    @melvin-bot
  4. melvin-bot commented on Feb 9, 2024

    @melvin-bot

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

  5. kbecciv commented on Feb 9, 2024

    @kbecciv
    Author

    We think that this bug might be related to #vip-vsb
    CC @quinthar

  6. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Feb 9, 2024
  7. melvin-bot commented on Feb 9, 2024

    @melvin-bot

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

  8. FitseTLT commented on Feb 9, 2024

    @FitseTLT
    Contributor

    Proposal

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

    Last option is not selected when pressing up key

    What is the root cause of that problem?

    Because index '0' is disabled it breaks early here

    if (newFocusedIndex < 0) {
    break;

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

    Change this

    if (newFocusedIndex < 0) {
    break;
    }

    to

    if (newFocusedIndex < 0) {
                        if (disableCyclicTraversal) {
                            break;
                        }
                        newFocusedIndex = maxIndex;
                    }
    

    And there is a similar problem with arrow key down too as there is no check if it is greater than maxIndex so we can add the below here

    if (newFocusedIndex > maxIndex) {
                        if (disableCyclicTraversal) {
                            break;
                        }
                        newFocusedIndex = 0;
                    }
    

    What alternative solutions did you explore? (Optional)

  9. allgandalf commented on Feb 9, 2024

    @allgandalf
    Contributor

    Proposal

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

    What is the root cause of that problem?

    We reduce the value of newFocusedIndex everytime in the loop and when it hits beyond 0, we break the loop, thereby we lose the highlight from the list

    newFocusedIndex -= allowHorizontalArrowKeys ? itemsPerRow : 1;
    if (newFocusedIndex < 0) {
    break;

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

    Instead of checking for the values < 0 (This case is only where the value can be -1 as when we go to the top of the list the last index value is always 0 and nothing below it!)

    Update the while loop to check if the newFocusedIndex is at the top of the list, and if so then return the maxIndex, if we enable the property to not traverse cyclic in the list then we stay at the top index itself

    while (disabledIndexes.includes(newFocusedIndex)) {
        newFocusedIndex -= allowHorizontalArrowKeys ? itemsPerRow : 1;
        
        if (newFocusedIndex === -1) {
              return disableCyclicTraversal ? actualIndex : maxIndex
                    .
                    .
                 

    What alternative solutions did you explore? (Optional)

    N/A

  10. Krishna2323 commented on Feb 12, 2024

    @Krishna2323
    Contributor

    Proposal

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

    Message action menu - Last option is not selected when pressing up key

    What is the root cause of that problem?

    In the code below the while loop will be executed when the newFocusedIndex is 0 because disabledIndexes.includes(newFocusedIndex) will become true as we have the emojis container at the index 0 and we don't allow focus on it, and due to that the focusedIndex is set to -1 for once.

    while (disabledIndexes.includes(newFocusedIndex)) {
    newFocusedIndex -= allowHorizontalArrowKeys ? itemsPerRow : 1;
    if (newFocusedIndex < 0) {
    break;
    }

    We also have similar bug in arrowDownCallback, there also we don't handle the case when the newFocusedIndex becomes greater than the maxIndex. This can be reproduced easily by passing last index number to disabledIndexes array inside BaseReportActionContextMenu or in any component we use useArrowKeyFocusManager. there also if we have the last index as disabled, the newFocusedIndex will be greater than the maxIndex which will cause focus lost.

    arrow_down_issue.mp4

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

    For Up arrow key:

    Instead of exiting the loop, we need to find the next focusable option from last, we can't directly return maxIndex because the maxIndex can also be disabled. For that we need to use the another while loop. Also, instead of using 0 as the minIndex we need to introduce a new parameter minIndex in useArrowKeyFocusManager and the default value will be zero. We need that for special cases like the emoji picker because there we need to get negative index because we want to focus on the input. We will pass headerIndices.length * -1 + 1 as the minIndex from EmojiPickerMenuWithRef.

    We need to update the code below:

    if (newFocusedIndex < 0) {
    break;
    }

    To:

                    if (newFocusedIndex < minIndex) {
                        if (disableCyclicTraversal) {
                            return actualIndex;
                        }
                        let newIndexFromLast = maxIndex;
                        while (disabledIndexes.includes(newIndexFromLast)) {
                            newIndexFromLast -= allowHorizontalArrowKeys ? itemsPerRow : 1;
                            if (newIndexFromLast < minIndex) {
                                return actualIndex;
                            }
                        }
                        return newIndexFromLast;
                    }

    For Down arrow key:

    We need to add the code below in the while loop of arrowDownCallback:

        if (newFocusedIndex >= maxIndex) {
            if (disableCyclicTraversal) {
                return actualIndex;
            }
            let newIndexStart = 0;
            while (disabledIndexes.includes(newIndexStart)) {
                newIndexStart += allowHorizontalArrowKeys ? itemsPerRow : 1;
                if (nextIndex >= maxIndex) {
                    return actualIndex;
                }
            }
            return newIndexStart;
        }

    PS: Minor code changes or refactoring can be done during the PR, the general idea will be the same.

    Result

    fix_demo_arrow_keys.mp4
  11. 57 remaining items

  12. puneetlath commented on Mar 12, 2024

    @puneetlath
    Contributor

    @FitseTLT @Ollyws How's this going?

  13. Ollyws commented on Mar 12, 2024

    @Ollyws
    Contributor

    Just reviewing some details, should be good to go in a day or two.

  14. added
    Awaiting PaymentAuto-added when associated PR is deployed to production
    and removed on Mar 18, 2024
  15. changed the title [-][$500] Message action menu - Last option is not selected when pressing up key[/-] [+][HOLD for payment 2024-03-25] [$500] Message action menu - Last option is not selected when pressing up key[/+] on Mar 18, 2024
  16. melvin-bot commented on Mar 18, 2024

    @melvin-bot

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

  17. melvin-bot commented on Mar 18, 2024

    @melvin-bot

    The solution for this issue has been 🚀 deployed to production 🚀 in version 1.4.53-2 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 2024-03-25. 🎊

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

  18. melvin-bot commented on Mar 18, 2024

    @melvin-bot

    BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:

    • [@Ollyws] The PR that introduced the bug has been identified. Link to the PR:
    • [@Ollyws] 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:
    • [@Ollyws] 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:
    • [@Ollyws] Determine if we should create a regression test for this bug.
    • [@Ollyws] If we decide to create a regression test for the bug, please propose the regression test steps to ensure the same bug will not reach production again.
    • [@puneetlath] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:
  19. puneetlath commented on Mar 22, 2024

    @puneetlath
    Contributor

    @Ollyws friendly reminder about the checklist so that we can pay on Monday.

  20. Ollyws commented on Mar 23, 2024

    @Ollyws
    Contributor

    BugZero Checklist:

    • The PR that introduced the bug has been identified. Link to the PR:

    #34581

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

    #34581 (comment)

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

    N/A

    • Determine if we should create a regression test for this bug.

    Yes.

    • If we decide to create a regression test for the bug, please propose the regression test steps to ensure the same bug will not reach production again.

    Regression Test Proposal

    1. Open any chat
    2. Right click on any report action
    3. Press on up key till you rich the top selectable option
    4. Press up key once more
    5. Verify that the last menu item is now highlighted
    

    Do we agree 👍 or 👎

  21. puneetlath commented on Mar 25, 2024

    @puneetlath
    Contributor

    All paid. Thanks y'all!

    Regression test issue is here: https://github.com/Expensify/Expensify/issues/382048

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.EngineeringInternalRequires API changes or must be handled by Expensify staffWeeklyKSv2

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions