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

Use BoundsObserver to keep tooltip over the wrapper #18782

Merged
merged 17 commits into from
May 19, 2023

Conversation

cubuspl42
Copy link
Contributor

@cubuspl42 cubuspl42 commented May 11, 2023

Details

Use BoundsObserver to keep tooltip over the wrapper

Fixed Issues

$ #15229
$ #15757
PROPOSAL: #15229 (comment)

Tests

  • Test whether the tooltip doesn't show in an incorrect position for animated elements
    • Go to the "Settings" -> "Profile" page
    • Go back to "Settings" and hover the mouse over the profile image quickly
      • Verify that the tooltip behaves as expected, staying over the profile image
  • Test whether the tooltip doesn't stay in an incorrect position in case of scrolling
    • Go to a scrollable page, for example, a workspace chat with multiple messages
    • Hover over an element with a tooltip (for example, an avatar) and start scrolling
      • Verify that the tooltip stays over that element

Offline tests

QA Steps

See Tests

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
tooltip-avatar.mp4
Mobile Web - Chrome
Mobile Web - Safari
Desktop
iOS
Android

@cubuspl42 cubuspl42 requested a review from a team as a code owner May 11, 2023 17:13
@melvin-bot melvin-bot bot requested review from 0xmiros and removed request for a team May 11, 2023 17:13
@melvin-bot
Copy link

melvin-bot bot commented May 11, 2023

@yuwenmemon @0xmiroslav One of you needs to 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]

@melvin-bot melvin-bot bot requested a review from yuwenmemon May 11, 2023 17:13
@cubuspl42
Copy link
Contributor Author

@flodnv @parasharrajat @0xmiroslav @yuwenmemon

As the template says...

Fixed Issues (plural)

[...] you can link multiple issues using the same formatting, just add a new line): [...]

...I linked both issues my PR solves by my intention. But I might've confused some bots, so maybe it wasn't a good idea?

@parasharrajat
Copy link
Member

This is fine. I will be reviewing this PR @0xmiroslav

package.json Outdated Show resolved Hide resolved
src/components/Tooltip/index.js Show resolved Hide resolved
@0xmiros
Copy link
Contributor

0xmiros commented May 11, 2023

@cubuspl42 if this PR solves #15757 as well, that's great. But won't this conflict with #16052 which put #15757 on hold?

@cubuspl42
Copy link
Contributor Author

@cubuspl42 if this PR solves #15757 as well, that's great. But won't this conflict with #16052 which put #15757 on hold?

It does conflict, although not very seriously. I tested a variant of this branch that's rebased on top of #16052.

@parasharrajat When do you think we could expect #16052 to be merged?

@parasharrajat
Copy link
Member

Probably tomorrow.

...which could occur when scrolling down.
@flodnv
Copy link
Contributor

flodnv commented May 11, 2023

I think it's ok if it conflicts, no...?


// We may need this check due to the reason that the animation start will fire async
// and hideTooltip could fire before it thus keeping the Tooltip visible
if (this.shouldStartShowAnimation) {
Copy link
Contributor Author

@cubuspl42 cubuspl42 May 11, 2023

Choose a reason for hiding this comment

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

@parasharrajat

Continuing this thread.

Please note that this check is nearly directly below the this.shouldStartShowAnimation = true assignment. The only barrier between is the awaiting for this.getWrapperPositionPromise.promise. That promise is gone, so the shouldStartShowAnimation flag doesn't have any use anymore, as I see it.

@cubuspl42
Copy link
Contributor Author

@parasharrajat I think we're ready for your next round!

@parasharrajat
Copy link
Member

parasharrajat commented May 12, 2023

We are running a discussion internally as it seems the lib is overengineered. Do we really need https://github.com/html-ng/bounding-client-rect-observer/blob/04a7cbbafe6a3fbafe93cbf4be2bf6e79165757c/src/handle.ts#L8?

@cubuspl42
Copy link
Contributor Author

cubuspl42 commented May 12, 2023

@parasharrajat I'd be happy to take part in that discussion if you find this appropriate.

It seems the lib is overengineered.

Let me know which parts you would remove or implement differently.

Do we really need HandleUtils?

Probably not, it's just a util. It could be inlined, it's a matter of opinion whether that would be less or more readable code. It's analogical to things like Listenable.merge in Flutter or other APIs I've seen over the years.

Is the presence of HandleUtils the biggest flaw you find in this library?

@parasharrajat
Copy link
Member

There is no flaw as such.

@cubuspl42
Copy link
Contributor Author

cubuspl42 commented May 15, 2023

@parasharrajat Let me know when we can take a next step with this PR. What's the state of the internal discussion? What are the blockers for merging this PR?

What do you think about starting the PR reviewer's checklist? I think it could be done independently from the internal discussion.

@parasharrajat
Copy link
Member

@cubuspl42 I will review this asap.

@cubuspl42
Copy link
Contributor Author

@parasharrajat

@cubuspl42 I will review this asap.

Thank you.

@parasharrajat
Copy link
Member

This PR is still held on the internal discussion. Sorry for the delay here. We will get back with an update as soon as possible.

@parasharrajat
Copy link
Member

This is back in motion.

@flodnv
Copy link
Contributor

flodnv commented May 16, 2023

Yes, please proceed 👍

@cubuspl42
Copy link
Contributor Author

@parasharrajat @flodnv Thanks for the update!

From my perspective, the PR has been essentially ready since the beginning, so I'm waiting for your turn guys 🙃

Comment on lines 109 to 114
targetWrapperWidth,
targetWrapperHeight,
maxWidth,
tooltipWidth,
tooltipHeight,
tooltipContentWidth,
wrapperMeasuredWidth,
wrapperMeasuredHeight,
contentMeasuredWidth,
Copy link
Member

Choose a reason for hiding this comment

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

These are confusing. They were making more sense earlier.

component means the toolip target. It can be changed to target. That is fine.

but wrapperMeasuredWidth is confusing. Earlier name tooltipWidth ws correct as it is width of tooltip itself. Now it is confusing to see two wrapper names.

I would say you revert

wrapperMeasuredWidth,
    wrapperMeasuredHeight,
    contentMeasuredWidth,

back to old names.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I aimed at consistency. Maybe then I'll change targetWrapperWidth/Height to targetWidth/Height?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And wrapper to tooltip?

Copy link
Member

Choose a reason for hiding this comment

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

yeah, you can do this. Let's not increase the scope of the PR.

Actually, I don't approve extra unrelated changes to any PR. Even though these are good refactors but completely unnecessary.

As you have already applied these, let's not remove them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I pushed a second suggestion. I tried to take your perspective into consideration, while also trying to stay consistent.

}, []);

const {animationStyle, tooltipWrapperStyle, tooltipTextStyle, pointerWrapperStyle, pointerStyle} = useMemo(
const {animationStyle, wrapperStyle, textStyle, pointerWrapperStyle, pointerStyle} = useMemo(
Copy link
Member

Choose a reason for hiding this comment

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

We named wrapperStyle to tooltipwrapperStyle to distinguish it from pointerWrapperStyle. IMO, that was fine too.

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 the reference is named wrapper 🙁 I renamed wrapper to rootWrapper and wrapperStyle to rootWrapperStyle, trying to address both concerns

@parasharrajat
Copy link
Member

parasharrajat commented May 18, 2023

Screenshots

🔲 iOS / native

Screenshot 2023-05-19 at 2 51 50 AM

🔲 iOS / Safari

Screenshot 2023-05-19 at 2 53 48 AM

🔲 MacOS / Desktop

Screen.Recording.2023-05-19.at.2.49.26.AM.mov

🔲 MacOS / Chrome

Screen.Recording.2023-05-19.at.2.48.03.AM.mov

🔲 Android / Chrome

Screenshot 2023-05-19 at 2 59 56 AM

🔲 Android / native

Screenshot 2023-05-19 at 3 12 26 AM

Copy link
Member

@parasharrajat parasharrajat left a comment

Choose a reason for hiding this comment

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

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible 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 checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified tests pass on all platforms & I tested again on:
    • Android / native
    • Android / Chrome
    • iOS / native
    • iOS / Safari
    • MacOS / Chrome / Safari
    • MacOS / Desktop
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (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 verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • 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
  • 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 reviewer checklist, including those that don't apply to this PR.

cc: @flodnv

🎀 👀 🎀 C+ reviewed

@yuwenmemon yuwenmemon requested a review from flodnv May 18, 2023 23:20
Copy link
Contributor

@flodnv flodnv left a comment

Choose a reason for hiding this comment

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

Nice PR, thanks!

import * as DeviceCapabilities from '../../libs/DeviceCapabilities';

// A "target" for the tooltip, i.e. an element that, when hovered over, triggers the tooltip to appear. The tooltip will
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment confuses me a bit. Is it meant to describe what class Tooltip is? If so, I am confused that class Tooltip is the target for the tooltip 😕

Copy link
Member

Choose a reason for hiding this comment

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

No, it is defining the term Target in the tooltip context.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok so why is this comment here? It feels out of context, no?

Copy link
Member

Choose a reason for hiding this comment

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

Actually, the target term is used a lot of places in the tooltip context across multiple components and files so there wasn't any good place to put it. Do you have something in mind? We can move it there.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we put it where we define the target for example?

Copy link
Contributor

Choose a reason for hiding this comment

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

I personally agree that the comment is a bit confusing and that the name is fine. For all intents and purposes it is a... tooltip. The "target" feels like it would refer to the wrapped element. If this comment is attempting to explain how the tooltip works at a high level it could probably be better.

Copy link
Member

Choose a reason for hiding this comment

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

This comment is only defining the term target in reference to the code in the Tooltip component so that it is clear what are we referring to when we encounter variables like targetWidth targetHeight etc.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok so how about this for a better comment:

We use this Tooltip component to wrap an element on which we want to show a tooltip. The "target" for the tooltip is the wrapped element which when hovered over, triggers the tooltip to appear.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@flodnv You're right, this is much better and what I actually had in mind. I'll create a follow-up PR tomorrow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@parasharrajat
Copy link
Member

Let's get this merged in the next 30 mins which will be under 3 days ❤️

@flodnv flodnv merged commit 2182d0c into Expensify:main May 19, 2023
@melvin-bot
Copy link

melvin-bot bot commented May 19, 2023

Congrats, that’s your 5th PR merged! 🎉 Do you know about the ContributorPlus role? It’s an opportunity to earn more in the Expensify Open Source community. Keep up the great work - thanks!

@OSBotify
Copy link
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@parasharrajat
Copy link
Member

Thank you for merging this. Please let me know if you want me to move the comment somewhere else. I can spin a PR for that.

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/flodnv in version: 1.3.17-0 🚀

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

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/chiragsalian in version: 1.3.17-5 🚀

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

@sobitneupane
Copy link
Contributor

This issue was created by the change introduced in this PR. The issue is: "tooltip appears at top left corner on pressing back icon"

Steps to reproduce:

  1. Go to "Settings."
  2. Click on " Share code."
  3. Click on Chevron left symbol to go back.
  4. Observe that for a fraction of seconds tooltip naming Back” appears at top left corner of the page.

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.

10 participants