-
Notifications
You must be signed in to change notification settings - Fork 62
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
Tooltip refactor #1168
base: master
Are you sure you want to change the base?
Tooltip refactor #1168
Conversation
20ed423
to
73c1356
Compare
@williamsyang-work thanks for this update. I see that it's still a draft PR. Let us know when it's ready for review. |
d9a90b9
to
e2bf86e
Compare
@bhufmann I just cleaned up the PR. It's ready for review! |
private getContent() { | ||
if (this.state.content) { | ||
return this.state.content; | ||
// Handle content and visibility changes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure where this happens or can be fixed, but when you hover over the tooltip and do a text range selection, some range selection remains when you close and reopen the tooltip, even when the text content changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know what you mean exactly... Can you post a GIF?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hover on a state on the kworker row, then mouse over the tooltip and select the End time value:
Then I move my mouse and hover over a state on the swapper row, and in the tooltip the End time value (a different string) is already selected:
This example is neat, but when the tooltip content is very different, then the persisted selection can be anything, starting and ending in the middle of words from different properties.
{Object.keys(tooltip).map(key => ( | ||
<tr key={key}> | ||
<td style={{ textAlign: 'left' }}> {key} </td> | ||
<td style={{ textAlign: 'left' }}> {tooltip[key]} </td> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems odd formatting to add spaces around the {...} ? Does it get stripped in the html?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spaces around the {...}
On lines 830-831? I usually don't put spaces around props prop={'content'}
but i will inside JS objects { object: 'value' }
At this point it's JSX and not actual HTML. Some react magic converts it to HTML and I'm not sure how that works! Haha.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean around {key} and {tooltip[key]} inside the html tag.
} | ||
|
||
export class TooltipComponent extends React.Component<unknown, TooltipComponentState> { | ||
private static readonly HOURGLASS_NOT_DONE = '⏳'; | ||
export const TooltipComponent = ({ content = '⏳', visible = false, fadeTransition = 500 }: TooltipProps) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get error/warning: Missing return type on function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added typing for the function.
@@ -751,7 +770,7 @@ export abstract class AbstractXYOutputComponent< | |||
rightPos = xLocation; | |||
} | |||
|
|||
const tooltipData = { | |||
const tooltipData: TooltipData = { | |||
title: timeLabel, | |||
dataPoints: points, | |||
top: topPos, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The four positioning fields are not used, so the position calculations above are also not needed, and the x,y function parameters are not needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I went ahead and removed the function inputs (x, y)
as well as the following keys from TooltipData
: top, bottom, right, left
and opacity, transition
.
Function calls of tooltip
have also been fixed in xy-output-component
and xy-output-overview-component
.
top?: number; | ||
bottom?: number; | ||
right?: number; | ||
left?: number; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The four position fields are not used.
right?: number; | ||
left?: number; | ||
opacity?: number; | ||
transition?: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The transition field is not used.
dependencies: | ||
prop-types "^15.7.2" | ||
uuid "^7.0.3" | ||
|
||
react-tooltip@^4.2.21: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just checking, is this one still needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a dependency of @theia/core
- Indeed, I do not see directly used in this repo here, but it might be used in the Theia examples in this repo.
$ yarn why react-tooltip
yarn why v1.22.22
[1/4] Why do we have the module "react-tooltip"...?
[2/4] Initialising dependency graph...
[3/4] Finding dependency...
[4/4] Calculating file sizes...
=> Found "react-tooltip@4.5.1"
info Reasons this module exists
- "_project_#browser-theia-trace-example-app#@theia#core" depends on it
- Hoisted from "_project_#browser-theia-trace-example-app#@theia#core#react-tooltip"
info Disk size without dependencies: "956KB"
info Disk size with unique dependencies: "1.48MB"
info Disk size with transitive dependencies: "1.6MB"
info Number of shared dependencies: 6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did check this out before submitting this PR. I made sure react-tooltip was removed from all of the codebase as well as all package.json
files. I came to the same conclusion as @marcdumais-work, that @theia
was using it somewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In any case, this dependency will not be part of the published npm packages (since they do not depend on it), so we should be good.
Removes 'react-tooltip' dependency and adds an in-house tooltip impl. Simplifies the rendering of tooltips inside of all available views. Fixes some UI bugs with tooltips. Fixes the bugged hourglass bug. Signed-off-by: Will Yang <william.yang@ericsson.com>
e2bf86e
to
1d50063
Compare
@PatrickTasse sorry for the delay. I addressed all of your comments except the first one, which I need some clarification on. Thank you! |
593e4b0
to
76a877d
Compare
After some thinking I decided to refactor this into a React Class Component. It will be easier to maintain. In |
76a877d
to
15d9a9f
Compare
15d9a9f
to
f5c6ba4
Compare
Refactor Tooltip Components
Overview
This PR modernizes our tooltip implementation by replacing the
react-tooltip
dependency with a custom tooltip component and introducing a more React-idiomatic state management approach.Key Changes
react-tooltip
in favor of a custom implementationTechnical Details
New Tooltip Implementation
The new tooltip component uses React's built-in state management and Portal API, providing better control over positioning and animations:
Compared to the old implementation which relied on external library and callbacks:
Abstract Component Pattern
Enhanced the existing
AbstractOutputComponent
with tooltip management capabilities:This replaces the old callback-based approach:
Removed Complexity
Migration Examples
Here are examples of how components are being updated to use the new tooltip pattern:
XY Chart Tooltip
Table Tooltip
Testing Instructions
vscode-trace-extension
Future Considerations