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

16098 — selecting chat message and pressing any key focus the message instead of switch the focus to the composer #21583

Conversation

robertKozik
Copy link
Contributor

@robertKozik robertKozik commented Jun 26, 2023

Details

This PR creates new document-scoped key listener which is connected with composer lifecycle. Listener will be mounted only when composer is rendered. It listens on any alphanumeric key event, and focuses the composer accordingly

Also there is added a fix for the ROUTES method parseReportRouteParams as it was not suited to the Navigation.getActiveRoute returend path - it don't have slash at the beggining.

the copy&paste listener is now document-scoped rather than connected to textInput and restricted in the same manner as new key listner

Fixed Issues

$ #16098
PROPOSAL: #16098 (comment)

Tests

  1. Go to any chats
  2. Click on any message
  3. Press any character keys like a,b,c,d (not non-character keys like Enter, Shift)
  4. Verify that the composer is focused again and the above character is entered in the composer
  5. Open emoji picker
  6. Press any character keys like a,b,c,d
  7. Verify that the emoji composer is focused again and the above character is entered in this composer. And the main composer is not affected

As the test steps also the regression tests pasted by @PauloGasparSv in previous PR can be used :

Typing should focus on the composer

  1. Open any chat
  2. Click on a message
  3. Start typing alpha-numeric characters (like a,b,c,d… but not Enter, Shift…)
  4. Verify that the composer is focused and the characters you type are inserted there

Typing in other inputs and modals

(Coming from here)

  1. Open any chat
  2. Open the Global Search and make sure the search is working
  3. Blur the global search input and start typing alpha-numeric characters (like a,b,c,d… but not Enter, Shift…)
  4. Make sure the characters you typed aren’t added to the search input or the Chat composer box
  5. Open your profile then display name and make sure the “First name” and “Last name” are not focused then start typing alpha-numeric characters (like a,b,c,d… but not Enter, Shift…)
  6. Go back to the chat and make sure those characters were not added to the composer box
  7. Go to Settings > Workspaces
  8. Open any workspace and go to the “Manage Members” page
  9. With no input focused, start typing alpha-numeric characters (like a,b,c,d… but not Enter, Shift…) and make sure they are not added to the Chat composer box
  10. Click on “Invite” and repeat the previous step

The composer Emoji Picker

(Coming from #17413)

  1. Open any chat
  2. Click on the Emoji Picker icon in the right side of the composer box
  3. Make sure you can search inside the Emoji Picker but what you type isn’t added to the composer box
  4. With the Emoji Picker opened, blur the search box and start typing alpha-numeric characters (like a,b,c,d… but not Enter, Shift…)
  5. Make sure the focus goes back to the Emoji Picker search box and all characters are added there instead of the Chat composer box
  6. Hover any message and click on the “Add reaction” icon
  7. Repeat steps 3 to 5

The FAB popover menu

  1. Open any chat
  2. Click on the Floating Action Button (+) in the bottom left of the screen
  3. Start typing alpha-numeric characters (like a,b,c,d… but not Enter, Shift…)
  4. Make sure that characters you typed aren't added to the Chat composer box
  5. Close popover of the Floating Action Button, blur the chat composer if it's in focus
  6. Start typing alpha-numeric characters (like a,b,c,d… but not Enter, Shift…)
  7. Make sure that characters you typed are added to the Chat composer box

"Meeting" popup

  1. Open any chat
  2. Click on the headphone icon on the right of chat header
  3. Start typing alpha-numeric characters (like a,b,c,d… but not Enter, Shift…)
  4. Make sure that characters you typed aren't added to the Chat composer box
  5. Close popover, blur the chat composer if it's in focus
  6. Start typing alpha-numeric characters (like a,b,c,d… but not Enter, Shift…)
  7. Make sure that characters you typed are added to the Chat composer box

three dot popup

  1. Open any task
  2. Click on the three dot icon on the right of chat header
  3. Start typing alpha-numeric characters (like a,b,c,d… but not Enter, Shift…)
  4. Make sure that characters you typed aren't added to the Chat composer box
  5. Close popover, blur the chat composer if it's in focus
  6. Start typing alpha-numeric characters (like a,b,c,d… but not Enter, Shift…)
  7. Make sure that characters you typed are added to the Chat composer box

Copying&Pasting - Web & Desktop only

(Coming from #17397 and #17411)

  1. Open any chat
  2. Select/Highlight the text from a message
  3. Copy the text using CMD + C or CTRL + C
  4. Click on the composer and paste the text using CMD + V or CTRL + V
  • Verify that no errors appear in the JS console

Offline tests

Same as test steps

QA Steps

Same as test 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 / Chrome
    • iOS / native
    • iOS / 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
    • 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 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

Web
web.mov
Mobile Web - Chrome
chrome.mov
Mobile Web - Safari
safari.mov
Desktop
desktop.mov
iOS
iOS.mov
Android
android.mov

@robertKozik robertKozik changed the title 16098 selecting chat message and pressing any key focus the message instead of switch the focus to the composer 16098 — selecting chat message and pressing any key focus the message instead of switch the focus to the composer Jun 26, 2023
@robertKozik robertKozik marked this pull request as ready for review June 26, 2023 16:27
@robertKozik robertKozik requested a review from a team as a code owner June 26, 2023 16:27
@melvin-bot melvin-bot bot removed the request for review from a team June 26, 2023 16:27
@melvin-bot
Copy link

melvin-bot bot commented Jun 26, 2023

@Santhosh-Sellavel 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]

@Santhosh-Sellavel
Copy link
Collaborator

Santhosh-Sellavel commented Jun 26, 2023

Moved here

@Santhosh-Sellavel
Copy link
Collaborator

@robertKozik Tests mentioned here work well, please include the linked #17649 (comment) steps here as well, it would be easy for everyone!

@robertKozik
Copy link
Contributor Author

@Santhosh-Sellavel Sure, pasted the testes 👌🏼

…y-key-focus-the-message-instead-of-switch-the-focus-to-the-composer
@Santhosh-Sellavel
Copy link
Collaborator

Bug: Pressing copy paste is broken

Steps:

  1. Select a text in the message
  2. Press CMD + C
  3. Manually focus the composer.
  4. Press CMD + V

Data is pasted multiple times

Comparision between staging & dev

Screen.Recording.2023-06-29.at.1.23.06.AM.mov

@Santhosh-Sellavel
Copy link
Collaborator

Resolve conflicts and look into the above bug I will continue testing tomorrow!

@robertKozik
Copy link
Contributor Author

@Santhosh-Sellavel @PauloGasparSv I want to clarify one thing about this issue/PR. From this issue: #17411 (linked in the repro steps) I assumed that copy&pasting function which will focus composer from anywhere should be implemented. But I missed that in this issue that was pointed out as New Feature. Thus should this behaviour be included in this PR?

@Santhosh-Sellavel
Copy link
Collaborator

I think yes, we should do it here. Actually, implementation works, but there is a breakage

@robertKozik
Copy link
Contributor Author

With new changes from last commit everything should be fine. Looks like after redirecting to the new page, the composer is not unmounting. Because of it, I bind the lifecycle of the listeners with the navigation focus/blur, so we wont register multiple ones - which was causing the breakage.

@Santhosh-Sellavel
Copy link
Collaborator

Santhosh-Sellavel commented Jun 29, 2023

@robertKozik
Can you re-test the PR now all tests are failing

Now the Typing does not focus on the composer

Screen.Recording.2023-06-30.at.4.42.11.AM.mov

@Santhosh-Sellavel
Copy link
Collaborator

@robertKozik Also fix the lint Screenshot 2023-06-30 at 4 44 46 AM

@robertKozik
Copy link
Contributor Author

@robertKozik Can re-test the PR now all tests are failing

Now the Typing does not focus on the composer

Screen.Recording.2023-06-30.at.4.42.11.AM.mov

@Santhosh-Sellavel Can you double check if you were using my branch? I checked it locally and It's working on my end

Screen.Recording.2023-06-30.at.01.24.02.mov

@Santhosh-Sellavel
Copy link
Collaborator

@robertKozik Try merging with the latest main, seems it fails after merging please check!

…t-message-and-pressing-any-key-focus-the-message-instead-of-switch-the-focus-to-the-composer
@robertKozik
Copy link
Contributor Author

@Santhosh-Sellavel @PauloGasparSv I've moved the ref for the FloatingActionButtonWithPopoverMenu to separate file in order to access it from ReportActionCompose. It's similar to the already existing implementation of EmojiPickerActions with which we are checking the emoji picker visibility status. New test case is also added to the original post - The FAB popover menu.

@robertKozik
Copy link
Contributor Author

Suggestion Resolved

@Santhosh-Sellavel
Copy link
Collaborator

Sorry @robertKozik I missed this component earlier, can we have some other hook to detect visible popups?

Screen.Recording.2023-07-10.at.1.33.39.AM.mov

@robertKozik
Copy link
Contributor Author

It for sure can be done in a similar manner. Do we know if there can be more such a popups? If so I'll opt for coming up with more generic approach to them, if all the popovers are using the same component. But as it's only the second one to check, it can be done in same way.

@robertKozik
Copy link
Contributor Author

@Santhosh-Sellavel I've switched the way of detecting such a modals to use onyx data (ONYXKEYS.MODAL), it should be sufficient. Also I've updated test steps with the headphone popover and three dots popover inside task screen

@Santhosh-Sellavel
Copy link
Collaborator

Can you please resolve conflicts?

…y-key-focus-the-message-instead-of-switch-the-focus-to-the-composer
@PauloGasparSv
Copy link
Contributor

I'm starting tests here and Web is looking fine : D

I'll resume and finish testing in ~2hours

@Santhosh-Sellavel
Copy link
Collaborator

LGTM Tests well!

Screen.Recording.2023-07-11.at.9.08.56.PM.mov

Copy link
Collaborator

@Santhosh-Sellavel Santhosh-Sellavel left a comment

Choose a reason for hiding this comment

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

LGTM tests well!

Copy link
Contributor

@PauloGasparSv PauloGasparSv left a comment

Choose a reason for hiding this comment

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

LGTM!

Web
Web.mov
Mobile Web - Chrome

Skipped, still having problems with chrome in the android emulator

Mobile Web - Safari
iosMweb.mov
Desktop
Deskto.mov
iOS
iOs.mov
Android
Android.mov

@PauloGasparSv PauloGasparSv merged commit e673d3f into Expensify:main Jul 12, 2023
11 checks passed
@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/PauloGasparSv in version: 1.3.40-0 🚀

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

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/Julesssss in version: 1.3.40-5 🚀

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

Comment on lines +715 to +718
// If the key pressed is non-character keys like Enter, Shift, ... do not focus
if (e.key.length > 1) {
return;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We forgot to consider the space as the key which also shouldn't focus the composer. This lead to issue #23508

}

this.focus();
this.replaceSelectionWithText(e.key, false);
Copy link
Contributor

Choose a reason for hiding this comment

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

This call was redundant. Later it caused #33710.
More details about the root cause: #33710 (comment)

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